ViewThatFits + conditional Toolbar bug on macOS

I have a weird macOS bug that I have narrowed down to a combination of using ViewThatFits and a conditional toolbar, which results in the toolbar not updating when the state changes.

The code below shows the issue. When toggling the state using the "Toggle" button, the toolbar doesn't update correctly on macOS.

If I comment out the ViewThatFits {} view, it works.

If I try this outside a .sheet(isPresented:), it works.

If I try it on iOS it works.

macOS: 13.4.1 (22F82) Xcode: 14.3.1 (14E300c) iOS: 16.5.1

import SwiftUI

struct ContentView: View {
    @State var showSheet = false
    @State var isOn: Bool = false

    #if os(iOS)
        let placement: ToolbarItemPlacement = .bottomBar
    #else
        let placement: ToolbarItemPlacement = .automatic
    #endif

    var body: some View {
        VStack {
            Button(action: { showSheet = true }) {
                Text("Show sheet")
            }
        }
        .padding()
        .sheet(isPresented: $showSheet) {
            NavigationStack {
                VStack {
                    ViewThatFits {
                        Text("This view creates a problem on macOS :/")
                    }
                    Text("isOn?: \(isOn ? "Yes" : "No")")
                    Button(action: { isOn.toggle() }) {
                        Text("Toggle")
                    }
                }
                .frame(minWidth: 300, minHeight: 300)
                .toolbar {
                    ToolbarItemGroup(placement: placement) {
                        if isOn {
                            Button(action: {}) {
                                Text("Yes")
                            }
                        } else {
                            Button(action: {}) {
                                Text("No")
                            }
                        }
                    }
                }
            }
        }
    }
}
ViewThatFits + conditional Toolbar bug on macOS
 
 
Q