Timing issue with updating two state variables

I have a SwiftUI view with:

@State var url: URL? 
@State var isShowingBrowser: Bool

func displayURL(url: URL) {
  self.url = url
  self.isShowingBrowser = true
}

var body: some View {
  Group {
    // ......
  }
  .sheet(isPresented: $isShowingBrowser) { 
    // browser view
  }
}

The first time I call displayBrowser, an empty browser sheet appears, with no URL. The second time, it works.

It doesn't matter if I reorder the assignments in displayURL. It's like the view refreshes once with a nil URL and isShowingBrowser true, then refreshes again with the URL value.

If I move both variable to an @Observable view model class then it works fine - that update seems to happen atomically.

For my own project, the view model is the right way to do this, but I was confused by this behavior. What am I missing about SwiftUI?

Still curious why this is happening. It also works fine if I use sheet(item: $url). But it doesn't work as above.

What happens if you init isShowingBrowser to false?

Timing issue with updating two state variables
 
 
Q