Serious Lag When Switching Between Views When Using HoverEffect/ContextMenu

After adding a HoverEffect to a Button, that when tapped, changes the current view, the Button with the HoverEffect delays when hiding, overlaying the new view. The same thing also occurs with ContextMenu.

Screenshot of lag/overlay:

This lasts for around a second before the tapped Button finally hides.

Example Code:

struct ContentView: View {
  @State var showOtherButton = false
   
  var body: some View {
    if showOtherButton {
      Button {
        showOtherButton.toggle()
      } label: {
        Text("First Button")
      }
      .padding()
      .hoverEffect()
      .contextMenu {
        Button {
          showOtherButton.toggle()
        } label: {
          Text("Toggle Button")
        }
      }
    } else {
      Button {
        showOtherButton.toggle()
      } label: {
        Text("Second Button")
      }
      .padding()
      .hoverEffect()
      .contextMenu {
        Button {
          showOtherButton.toggle()
        } label: {
          Text("Toggle Button")
        }
      }
    }
  }
}

Is this a known SwiftUI bug? Any way to fix this? I've thought about using a delay after tapping the Button between switching the views, but that's not a good solution.

Replies

Also related: You can hide a Button or switch to a new view, but if you hover over where the Button was it reappears, and you can tap it.

I run into the same issue, see: https://twitter.com/krajaac/status/1667089692301447168 Haven't found a workaround yet. Seems like the invalidation of the preview is seriously broken.