Unable to Dismiss A Particular Window from WindowGroup

Hello guys,
I'm working on a visionOS project and I defined a WindowGroup in the app structure file with an ID and accepting String as values because I'm not sure how many windows could be opened so couldn't hard code an ID for each window.
Now I can open multiple windows by using openWindow(id: value:). What I expect to happen is that by using the dismissWindow(id: value:) function I could close a single window individually while others remain active.
But when I click on the button to dismiss one particular window, nothing happens. I couldn't use the 0 opacity or hidden() method because that would still leave the bar below the bottom of the window visible. And I have to close the window programmatically, not manually tap on the close button.

Below is the simplified files of my code. Any workaround or way to solve this issue would be greatly appreciated! Thank you in advance!

// main structure file.
import SwiftUI
@main
struct testerApp: App {
    @StateObject private var linkModel = LinkModel()
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(linkModel)
        }
        .windowStyle(.plain)
        
        
        WindowGroup(id: "MyWindow", for: String.self) { $windowID in
            WindowView(windowID: windowID ?? "")
                .environmentObject(linkModel)
        }
        .windowStyle(.plain)
        
    }
}
// model to save unique window IDs.
import Foundation
import Observation

/// Using this observable to save for the IDs.
@Observable class LinkModel: ObservableObject {
    var windowIDs = [String]()
}
// ContentView to open new windows, works as expected.
import SwiftUI
import RealityKit
import RealityKitContent

struct ContentView: View {
    @Environment(\.openWindow) private var openWindow
    @Environment(LinkModel.self) private var linkModel
    
    
    var body: some View {
        NavigationStack {
            VStack {
                /// By clicking this btn, a new window will be opened with its own unique id.
                Button {
                    let id = UUID().uuidString
                    linkModel.windowIDs.append(id)
                    openWindow(id: "MyWindow", value: id)
                    print("WINDOW ID: \(id)")
                } label: {
                    Text("Open New Window")
                }
            }
        }
    }
}
// dismissWindow here DOESN'T WORK.
import Foundation
import SwiftUI


struct WindowView: View {
    @Environment(\.dismissWindow) private var dismissWindow
    
    /// Each newly opened window has a unique window ID, used as value for closing this window later.
    let windowID: String
    
    var body: some View {
        NavigationStack {
            Text("Window ID: \(windowID)")
            
            /// Expect the window to be closed by clicking here but not responsive at all.
            Button {
                print("DISMISSING \(windowID)")
                dismissWindow(id: "MyWindow", value: windowID)
            } label: {
                Text("Dismiss Window")
            }
            
            Text("\nPlease check connection to the transmitter.")
            
        }  
    }
}
Answered by ForumsContributor in
Accepted Answer

Hi @wayney1121 , you should be using dismiss() instead of dismissWindow in your Button. Change this as well as your environment variable to @Environment(\.dismiss) private var dismiss and it should start working! You don't need to provide an ID, it will dismiss the window that you are clicking the button on.

Unable to Dismiss A Particular Window from WindowGroup
 
 
Q