List selection does not update model on MacOS. But same code works fine on iOS.

I have this code example that works perfectly on iOS. But on MacOS, the changes made in view presented by Navigation Stack gets reverted after I click on Back button.

import SwiftUI
import Observation

enum Route: Hashable {
    case selection
}

let allSelectables: [String] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]

@Observable
class Model {
    var items: Set<String> = [] // Use Set for unique selections
}

struct ContentView: View {
    @State var model = Model()

    var body: some View {
        NavigationStack {
            VStack {
                Text("Selected: \(model.items.joined(separator: ", "))")
                List {
                    NavigationLink(value: Route.selection) {
                        Text("Go to Selection (\(model.items.count))")
                    }
                }
                .navigationDestination(for: Route.self) { route in
                    switch route {
                    case .selection:

                        List(allSelectables, id: \.self, selection: $model.items) { item in
                            Text(item)
                        }
#if os(iOS)
                        .environment(\.editMode, .constant(.active)) // Enable multiple selection
#endif
                        .navigationTitle("Selected: \(model.items.joined(separator: ", "))")
                    }
                }
            }
        }
    }
}

Seems to be a bug or behavior quirk in NavigationStack, because if I change the code to use .sheet(), then it suddenly work fine on MacOs:

import SwiftUI
import Observation
 

let allSelectables: [String] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
 
@Observable
class Model {
    var items: Set<String> = [] // Use Set for unique selections
}
 
struct ContentView: View {
    @State var model = Model()
    @State private var showSheet = false
 
    var body: some View {
        NavigationStack {
            VStack {
                Text("Selected: \(model.items.joined(separator: ", "))")
                List {
                    Button("Go to Selection (\(model.items.count))") {
                        showSheet = true
                    }
                }
                .sheet(isPresented: $showSheet) {
                        List(allSelectables, id: \.self, selection: $model.items) { item in
                            Text(item)
                        }
#if os(iOS)
                        .environment(\.editMode, .constant(.active)) // Enable multiple selection
#endif
                }
            }
        }
    }
}
List selection does not update model on MacOS. But same code works fine on iOS.
 
 
Q