Why does dismiss() have no impact inside a closure of NavigationDestination view?

In the code below, for the #else case, when I click Click to dismiss, the button remains. But for the #if DISMISS_SUCCESSFULLY case, clicking the button causes pops it of the navigation stack. Would you please help explain why the difference? Thank you.


            Button("Click to navigate") {
                myNavigate = true
            }
            .navigationDestination(isPresented: $myNavigate) {
                #if DISMISS_SUCCESSFULLY
                DismissButton()
                #else
                Button("Click it dismiss") {
                    print("Dismissing ...")
                    presentationMode.dismiss()
                    print("Done dismissing")
                }
                #endif
            }

struct DismissButton: View {
        //=== Local ===
        @Environment(\.presentationMode) @Binding private var presentationMode
        
        var body: some View {
            Button("Click it dismiss") {
                presentationMode.dismiss()
            }
        }
    }

@atluutran could you try using dismiss or isPresented property instead. PresentationMode has been deprecated.

Secondly, is this within the context of a NavigationSplitView ?

@DTS Engineer below is the new code based on your suggestion, and I run into a new weird problem where the Button("Closure: Click to dismiss") is not responding to a click. If I remove dismiss() call, it becomes clickable.

The issue is within the context of NavigationStack, not NavigationSplitView.

struct Debug_ID2_Dismiss: View {
    @Environment(\.dismiss) private var dismiss

    @State private var myNavigate = false
    
    var body: some View {
        Button("Click to navigate") {
            myNavigate = true
        }
        .navigationDestination(isPresented: $myNavigate) {
#if DISMISS_SUCCESSFULLY
            DismissButton()
#else
            Button("Closure: Click to dismiss") {
                print("Dismissing ...")
                dismiss()
                print("Done dismissing")
            }
#endif
        }
    } // body
    
    struct DismissButton: View {
        let SRC = "DismissButton"
        
        @Environment(\.dismiss) private var dismiss
        
        var body: some View {
            Button("\(SRC): Click to dismiss") {
                print("\(SRC): Dismissing")
                dismiss()
                print("\(SRC): Done dismissing")
            }
        }
    } // DismissButton
} //  Debug_ID2_Dismiss
Why does dismiss() have no impact inside a closure of NavigationDestination view?
 
 
Q