@@ -40,6 +40,10 @@ import { getSuggestedBranchName } from "../utils/getSuggestedBranchName";
4040
4141const COMBOBOX_LIMIT = 50 ;
4242
43+ // Shared so the two "still loading branches" render sites (the empty-list
44+ // spinner and the seeded-default row) can never drift out of sync on a copy edit.
45+ const LOADING_BRANCHES_LABEL = "Loading branches…" ;
46+
4347// Sentinel value for the "Create new branch" action. Rendered as a real
4448// ComboboxItem in the list footer so it's reachable by keyboard, not a
4549// plain button the combobox's roving focus skips over.
@@ -140,8 +144,19 @@ export function BranchSelector({
140144 const isSelectionOnly = workspaceMode === "worktree" || isCloudMode ;
141145 const displayedBranch = isSelectionOnly ? selectedBranch : currentBranch ;
142146
147+ // The branch we auto-selected, so we can tell our own pick apart from one the
148+ // user made. Lets us correct a stale default (e.g. a cached "trunk" that the
149+ // live list later contradicts) without ever clobbering a deliberate choice.
150+ const autoSelectedBranchRef = useRef < string | null > ( null ) ;
143151 useEffect ( ( ) => {
144- if ( isSelectionOnly && defaultBranch && ! selectedBranch && onBranchSelect ) {
152+ if ( ! isSelectionOnly || ! defaultBranch || ! onBranchSelect ) return ;
153+ // Adopt the default when nothing is selected yet, or when the default has
154+ // changed out from under a value we ourselves auto-selected — but leave a
155+ // user's own selection alone.
156+ const selectionIsOurs =
157+ ! selectedBranch || selectedBranch === autoSelectedBranchRef . current ;
158+ if ( selectionIsOurs && selectedBranch !== defaultBranch ) {
159+ autoSelectedBranchRef . current = defaultBranch ;
145160 onBranchSelect ( defaultBranch ) ;
146161 }
147162 } , [ isSelectionOnly , defaultBranch , selectedBranch , onBranchSelect ] ) ;
@@ -175,12 +190,28 @@ export function BranchSelector({
175190 return byBranch ;
176191 } , [ repoCheckouts ] ) ;
177192
178- const branches = isCloudMode ? ( cloudBranches ?? [ ] ) : localBranches ;
193+ const liveBranches = isCloudMode ? ( cloudBranches ?? [ ] ) : localBranches ;
179194 const effectiveLoading = loading || ( isCloudMode && cloudBranchesLoading ) ;
180195 const branchListLoading = isCloudMode
181196 ? ! ! cloudBranchesLoading
182197 : localBranchesLoading ;
183198
199+ // On a cold start the live cloud branch list is still empty while the (slow)
200+ // remote fetch runs. Surface the known default ("trunk") branch as a real
201+ // list item straight away — with a loading row rendered below it — so the
202+ // common "start on trunk" case is pickable with zero wait. Only when there's
203+ // no active search: once the user types, the results should be purely what
204+ // the remote returns.
205+ const seededDefaultBranch =
206+ isCloudMode &&
207+ branchListLoading &&
208+ liveBranches . length === 0 &&
209+ ! ! defaultBranch &&
210+ ! ( cloudSearchQuery ?? "" ) . trim ( )
211+ ? defaultBranch
212+ : null ;
213+ const branches = seededDefaultBranch ? [ seededDefaultBranch ] : liveBranches ;
214+
184215 const checkoutMutation = useMutation ( {
185216 ...trpc . git . checkoutBranch . mutationOptions ( ) ,
186217 onSuccess : ( ) => {
@@ -456,7 +487,7 @@ export function BranchSelector({
456487 ) : null }
457488
458489 { branchListLoading && branches . length === 0 ? (
459- < LoadingRow label = "Loading branches…" />
490+ < LoadingRow label = { LOADING_BRANCHES_LABEL } />
460491 ) : (
461492 < ComboboxEmpty > No branches found.</ ComboboxEmpty >
462493 ) }
@@ -519,6 +550,15 @@ export function BranchSelector({
519550 } }
520551 </ ComboboxList >
521552
553+ { /*
554+ Cold start: the default ("trunk") branch is seeded as the only list
555+ item while the remote list loads. A loading row directly below it
556+ makes clear the rest of the branches are still on the way.
557+ */ }
558+ { seededDefaultBranch ? (
559+ < LoadingRow label = { LOADING_BRANCHES_LABEL } />
560+ ) : null }
561+
522562 { isCloudMode && cloudBranchesHasMore ? (
523563 < ComboboxListFooter >
524564 < div className = "px-2 pb-2" >
0 commit comments