Avoid popover binding writes during SwiftUI updates

Merged
TE
2mo ago
+5-1

Summary

Extracted from the broader #13403 repair so the current-main sidebar failure can land independently.

ArrowlessPopoverAnchor.updateNSView runs inside SwiftUI's view-update pass. When isPresented == false, calling coordinator.dismiss() rewrites the already-false binding, which emits repeated Modifying state during view update faults during parent re-evaluation.

Use the existing dismiss(resetPresentation: false) path from dismantleNSView when the binding already owns the false state.

Red-before evidence

Current app-host census run 35635891245, shard 5/6, strict SidebarWorkspaceSwitchLayoutFaultTests step:

  • switchingWorkspacesDoesNotReenterHostingViewLayout()
  • failure at SidebarWorkspaceSwitchLayoutFaultTests.swift:57
  • observed repeated Modifying state during view update, this will cause undefined behavior. faults

The same one-line fix is present in #13403, where its full-suite run reports the sidebar layout faults changing from 15 failures to 0.

Scope

One production line plus explanatory comment. No fixture changes. The existing strict sidebar workspace-switch regression is the acceptance test.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Prevents repeated SwiftUI Modifying state during view update faults when the popover is closed. ArrowlessPopoverAnchor.updateNSView now uses the same dismiss(resetPresentation: false) path as dismantleNSView instead of rewriting the already-false binding on every parent re-evaluation, including sidebar workspace switches. No behavior change to popover presentation; this is extracted from the broader #13403 repair so the current-main sidebar failure can land independently.

Summary by CodeRabbit

  • Bug Fixes
    • Improved popover dismissal behavior when it is already marked as closed.
    • Prevented unnecessary presentation-state updates during view refreshes.
    • Preserved existing state-reset behavior for other popover dismissal actions.
    • Popovers should now close more reliably without unexpectedly changing their presentation state.