Skip to content

Fix worktree branch selector default and loading behavior#161

Merged
juliusmarminge merged 4 commits intomainfrom
t3code/fix-worktree-branch-selector-loading
Mar 3, 2026
Merged

Fix worktree branch selector default and loading behavior#161
juliusmarminge merged 4 commits intomainfrom
t3code/fix-worktree-branch-selector-loading

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Mar 3, 2026

Summary

  • Fix branch toolbar value resolution so new worktree mode defaults to the current git branch when no explicit base branch is set.
  • Preserve explicitly selected worktree base branches, while showing the actual checked-out branch outside new-worktree selection.
  • Extract branch value resolution into resolveBranchToolbarValue and add focused unit tests for the key branch-selection scenarios.
  • Improve branch list virtualization setup by stabilizing scroll element ref handling and triggering measurement on open/content changes.
  • Refactor setThreadBranch into a memoized callback and auto-persist default branch metadata for new worktree threads.
  • Remove branch-query invalidation on menu open to avoid unnecessary loading churn.

Testing

  • Added unit tests in apps/web/src/components/BranchToolbar.logic.test.ts covering:
  • worktree mode with no active worktree path and no explicit branch defaults to currentGitBranch.
  • Explicitly selected worktree base branch is retained.
  • Non-worktree/new-selection context resolves to the checked-out git branch.
  • Lint/typecheck/test execution: Not run (not provided in commit context).

Note

Medium Risk
Medium risk: refactors BranchToolbar branch/env-mode logic and persistence, which could affect which branch/worktree a thread targets and when sessions are stopped or metadata is updated.

Overview
Fixes branch selection semantics in the toolbar, especially for new worktree flow: the displayed/used base branch now defaults to the current git branch when none is explicitly chosen, preserves an explicitly selected base branch, and otherwise shows the actually checked-out branch.

Refactors the UI by extracting the combobox/virtualized branch picker into BranchToolbarBranchSelector, adds helpers (resolveEffectiveEnvMode, resolveDraftEnvModeAfterBranchChange, resolveBranchToolbarValue) with new unit tests, and tweaks loading/virtualization behavior (invalidate only the branches query on open, stabilize scroll element refs, and re-measure on open/content changes). It also auto-persists the default base branch for new-worktree drafts and updates draft env-mode after branch/worktree changes.

Written by Cursor Bugbot for commit 1bf4fcc. This will update automatically on new commits. Configure here.

Note

Fix BranchToolbar default branch selection and loading by adding apps/web/src/components/BranchToolbarBranchSelector.tsx and using apps/web/src/components/BranchToolbar.logic.ts::resolveDraftEnvModeAfterBranchChange, resolveEffectiveEnvMode, and resolveBranchToolbarValue

Introduce utilities to resolve env mode and toolbar branch value, refactor BranchToolbar to delegate selection to BranchToolbarBranchSelector, and add tests for env mode and branch value resolution.

📍Where to Start

Start with resolveEffectiveEnvMode, resolveDraftEnvModeAfterBranchChange, and resolveBranchToolbarValue in BranchToolbar.logic.ts, then review setThreadBranch in BranchToolbar.tsx, and the selection flow in BranchToolbarBranchSelector.tsx.

Macroscope summarized 1bf4fcc.

- Default new worktree branch selection to the current checked-out branch when unset
- Extract branch value resolution into shared logic with tests
- Stabilize virtualized branch list scroll/measurement to avoid loading glitches
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch t3code/fix-worktree-branch-selector-loading

Comment @coderabbitai help to get the list of available commands and usage tips.

- Move branch combobox logic into `BranchToolbarBranchSelector` to simplify `BranchToolbar`
- Re-fetch git branches when opening the selector so options are current
- Preserve draft env mode correctly when switching between main and worktree branches
@juliusmarminge juliusmarminge merged commit 760fe64 into main Mar 3, 2026
3 checks passed
@juliusmarminge juliusmarminge deleted the t3code/fix-worktree-branch-selector-loading branch March 3, 2026 18:01
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