I'm running this on macOS. I looks like a bug to me. If I activate the menu item and confirm the alert, the alert pops up again. It only double-shows once; then it behaves correctly. In my real app, it double-shows every time.
If I uncomment that DispatchQueue.main.async, it "fixes" it.
macOS 11.2.3, Xcode 12.4.
If I uncomment that DispatchQueue.main.async, it "fixes" it.
macOS 11.2.3, Xcode 12.4.
Code Block swift @main struct DoubleAlertApp: App { @State var showAlert: Bool = false @StateObject var model: Model = .init() var body: some Scene { WindowGroup { ContentView().environmentObject(model) .background(EmptyView() .alert(isPresented: $showAlert) { Alert(title: Text("Test"), message: Text("This will do something"), primaryButton: .cancel(), secondaryButton: .destructive(Text("Do it"), action: confirmedAction)) }) }.commands { CommandGroup(replacing: CommandGroupPlacement.newItem) { Button(action: testAlert) { Text("Test Alert") }.keyboardShortcut("t") } } } private func testAlert() { showAlert = true } private func confirmedAction() { print("confirmedAction") // DispatchQueue.main.async { self.model.change() //} } } class Model: ObservableObject { init() {} @Published var foo: Int = 0 func change() { objectWillChange.send() foo += 1 } } struct ContentView: View { @EnvironmentObject var model: Model var body: some View { Text("Hello. \(model.foo)").padding() } }