Fix spinner hang after display resolution changes

LA
8mo ago
+113-9

Summary

  • add a regression test that reproduces stale terminal portal geometry after a queued layout shift
  • defer terminal portal geometry synchronization until the current AppKit layout churn finishes, avoiding re-entrant sync during display changes

Testing

  • xcodebuild -quiet -project /Users/lawrence/fun/cmuxterm-hq/worktrees/issue-1541-resolution-spinner/GhosttyTabs.xcodeproj -scheme cmux-unit -destination 'platform=macOS' -derivedDataPath /tmp/cmux-issue-1541-red-final -only-testing:cmuxTests/TerminalWindowPortalLifecycleTests/testScheduledExternalGeometrySyncRefreshesAncestorLayoutShift -only-testing:cmuxTests/TerminalWindowPortalLifecycleTests/testScheduledExternalGeometrySyncWaitsForQueuedLayoutShift test (fails on 94f7529a, new regression test fails)
  • xcodebuild -quiet -project /Users/lawrence/fun/cmuxterm-hq/worktrees/issue-1541-resolution-spinner/GhosttyTabs.xcodeproj -scheme cmux-unit -destination 'platform=macOS' -derivedDataPath /tmp/cmux-issue-1541-green3 -only-testing:cmuxTests/TerminalWindowPortalLifecycleTests/testScheduledExternalGeometrySyncRefreshesAncestorLayoutShift -only-testing:cmuxTests/TerminalWindowPortalLifecycleTests/testScheduledExternalGeometrySyncWaitsForQueuedLayoutShift test (passes)
  • ./scripts/reload.sh --tag issue-1541-resolution-spinner (build succeeds)

Issues


Summary by cubic

Fixes a spinner hang after display resolution changes by deferring terminal portal geometry sync until AppKit finishes the current layout pass; closes #1541. Adds a regression test that verifies the sync waits for queued layout shifts and updates the portal position correctly.

  • Bug Fixes
    • Defer external geometry sync with double main-queue dispatch to avoid re-entrant work during layout churn.
    • Replace immediate syncs in GhosttyTerminalView with a deferred scheduler keyed by geometry revision to dedupe updates.
    • Add regression test: testScheduledExternalGeometrySyncWaitsForQueuedLayoutShift.

Summary by CodeRabbit

  • Refactor

    • Optimized geometry and layout synchronization by implementing deferred, batched updates instead of immediate synchronization calls at multiple points, reducing redundant processing during window layout changes.
  • Tests

    • Added test coverage to verify synchronization behavior when queued layout changes occur.