Fix empty worktree list on first launch - #52
Merged
Merged
Conversation
On cold start the AppDelegate selection observer syncs worktreeViewModel.repository before any window exists, intentionally without loading worktrees (the status menu loads lazily). ContentView's initial-load task then skipped loading because repository was already non-nil, and onChange never fired since the selection happened before the view appeared — so the main window opened with an empty list until the user switched repositories. Replace the nil-guarded load with WorktreeListViewModel.windowAppeared, which always syncs the current selection and reloads when the window content appears. Add regression unit tests covering the pre-synced cold-start state. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On first launch, the main window shows "No Worktrees" (0 count) for the selected repository. Switching to another repository loads the list correctly.
Root cause
A cold-start ordering bug between three pieces that are individually correct:
AppDelegate.observeSelectedRepository()syncsworktreeViewModel.repositoryto the restored selection — intentionally without loading worktrees (the status menu loads lazily; pinned byselectedRepoDoesNotEagerLoadWorktrees)..taskonly loaded the list whenworktreeViewModel.repository == nil— but step 1 already set it, so the initial load was skipped..onChange(of: selectedRepository)never fired either, because the selection happened before the view appeared.Net effect: nothing ever loads the list until the user changes repositories.
repository != nildoes not imply the list has been loaded — the.taskguard assumed it does.Fix
WorktreeListViewModel.windowAppeared(selectedRepository:): always syncs the current selection and reloads when the window content appears..taskdelegates to it instead of the nil-guarded load.Testing
windowAppearedmust still load.AppDelegateColdStartTestshas a pre-existing flaky AppKit_NSWindowTransformAnimationover-release crash (crash reports pre-date this change) that any added window-lifecycle test destabilizes — suite hardening is tracked separately.swiftlint lintclean, full suite (446 tests) green 3× consecutively,scripts/coverage.shgate passes.🤖 Generated with Claude Code