Skip to content

Fix intermittently reappearing main-window title - #56

Merged
sapsaldog merged 1 commit into
mainfrom
fix/main-window-title-visibility-race
Jun 12, 2026
Merged

sapsaldog merged 1 commit into
mainfrom
fix/main-window-title-visibility-race

Conversation

@sapsaldog

Copy link
Copy Markdown
Owner

Problem

The main window is supposed to show no titlebar title (the glass toolbar is the first content row under a transparent titlebar), but "Oh My Worktree" intermittently appeared next to the traffic lights — sometimes right after opening the window, and it persisted until app restart.

Root cause

A last-writer-wins race between AppKit and SwiftUI on NSWindow.titleVisibility. An lldb breakpoint on -[NSWindow setTitleVisibility:] captured the sequence on the main window:

  1. NSHostingView.viewDidMoveToWindow → SwiftUI BarAppearanceBridge.updateWindowTitle sets .visible (bridging ContentView's .navigationTitle("Oh My Worktree"))
  2. AppDelegate.configureMainWindowChrome sets .hidden ✓
  3. MainWindowChromeConfigurator probe re-applies .hidden ✓
  4. Async NSHostingView.preferencesDidChange (ViewGraph render) → BarAppearanceBridge sets .visible again — final writer, title shows

NSHostingController bridges title/toolbar scene preferences to its host window by default, and the bridge re-runs on async preference updates (first layout, content loads, window tiling), so whether the title showed depended on whichever side wrote last. Cold-start window creation (launch → open window ~2s later) reproduced it 3/3.

Fix

Set sceneBridgingOptions = [] on the NSHostingController used for AppDelegate-managed windows, so AppKit stays the sole owner of the window chrome. .navigationTitle stays in ContentView for the WindowGroup path; the manual window's title string is already set via window.title for the title-based window lookup.

Verification

  • Cold-start repro protocol (launch → reopen at +2s → screenshot): 3/3 showed the title before the fix, 3/3 clean after
  • swiftlint lint clean
  • Full test suite: 473 tests in 44 suites pass
  • AppDelegate+*.swift is on the coverage exclusion list, so the 100% gate is unaffected

🤖 Generated with Claude Code

SwiftUI's hosting bar-appearance bridge mirrors ContentView's
.navigationTitle onto the AppKit-owned main window and re-asserts
titleVisibility = .visible on asynchronous preference updates (first
layout, content loads, window tiling). That races
configureMainWindowChrome's .hidden and wins whenever it fires last,
so the title showed up intermittently — reliably on cold-start window
creation. Disable scene bridging on the manual window's
NSHostingController so AppKit stays the sole owner of the window
chrome.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sapsaldog
sapsaldog merged commit fdff876 into main Jun 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant