SwiftUI MenuBarExtra not updating when State changes

hi is there any way to UPDATE dropdown content Text or do anything when "@State" changes ? cuz in normal SwiftUI views everything rerenders when "@State" changes expect this new "MenuBarExtra"

code in "label:" part will update when "@State" change but where I added "ControlView()" it does not :/

example code:


@State var secounds = 0

     @State var timerRunning = false

    let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()


    var body: some Scene {

        MenuBarExtra {

            ControlView()

        } label: {

            Text("\(hours):\(minutes):\(secounds)")

                .onReceive(timer) { _ in

                    }

                }

        }

        .menuBarExtraStyle(.window)

    }

    

    @ViewBuilder
    func ControlView()->some View {

        Grid(horizontalSpacing: 12, verticalSpacing: 12) {

            GridRow {

                ZStack {

                    RoundedRectangle(cornerRadius: 12, style: .continuous)

                        .fill(.red)

                        .frame(height: 75)

                    

                    Text("\(timerRunning ? "Pause" : "Play")")

                        .padding()

                        .onTapGesture {

                            timerRunning.toggle()

                        }

                }

            }

        }

        .padding(10)

    }

I've reported this bug and found a work around with an Apple dev. Don't use @State and instead use @EnvironmentObject.

I am seeing the same thing on Sonoma and the lastest version of Xcode. I have updated to using @EnvironmentObject and I do not see any updated in my UI.

Same.

I worked around this by putting the MenuBarExtra into a struct: Scene and its content into a struct: View

var body: some Scene {
	@State var state = AppState.shared
	
	MenuBar(state: state)
}

private struct MenuBar: Scene {
	@ObservedObject var state: AppState
	
	var body: some Scene {
		MenuBarExtra("App Name Here", image: state.logo) {
			MenuBarContent(state: state)
		}
	}
}

private struct MenuBarContent: View {
	@ObservedObject var state: AppState
	
	var body: some View {
		Text("App Name Here")
		if let browser = self.state.browser {
			Divider()
			Text("Running for \(browser.getDisplayName())")
		}
		Divider()
		Button("Chrome") { state.setBrowser(.chrome) }
		Button("Firefox") { state.setBrowser(.firefox) }
		Button("Quit") { NSApp.terminate(nil) }
	}
}
SwiftUI MenuBarExtra not updating when State changes
 
 
Q