@devries-cameron20 / t3code Mirror · read-only / commits / 767da3b06d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 05:30 UTC

refactor(web): the branch selector keeps its caching without "use memo" (#20822)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 17, 2026 at 00:34 UTC 767da3b06dfcd816fdb496c6ad5aeb38741ac507
1 file changed +40 -63
apps/web/src/components/BranchToolbarBranchSelector.tsx
+40 -63
@@ -95,39 +95,6 @@ function toBranchActionErrorMessage(error: unknown): string {
95 return error instanceof Error ? error.message : "An error occurred.";
96 }
97
98 -// The picker's list keys on these arrays, so they stay cached across the
99 -// queries and transitions the selector calls after computing them.
100 -function useBranchPickerItems({
101 - refs,
102 - createBranchItemValue,
103 - checkoutPullRequestItemValue,
104 - normalizedQuery,
105 -}: {
106 - refs: ReadonlyArray<VcsRef>;
107 - createBranchItemValue: string | null;
108 - checkoutPullRequestItemValue: string | null;
109 - normalizedQuery: string;
110 -}) {
111 - "use memo";
112 - const branchPickerItems = [
113 - ...(checkoutPullRequestItemValue ? [checkoutPullRequestItemValue] : []),
114 - ...refs.map((refName) => refName.name),
115 - ...(createBranchItemValue ? [createBranchItemValue] : []),
116 - ];
117 - const filteredBranchPickerItems =
118 - normalizedQuery.length === 0
119 - ? branchPickerItems
120 - : branchPickerItems.filter((itemValue) =>
121 - shouldIncludeBranchPickerItem({
122 - itemValue,
123 - normalizedQuery,
124 - createBranchItemValue,
125 - checkoutPullRequestItemValue,
126 - }),
127 - );
128 - return { branchPickerItems, filteredBranchPickerItems };
129 -}
130 -
98 export function BranchToolbarBranchSelector({
99 forceNewWorktree = false,
100 ref,
@@ -256,35 +223,18 @@ export function BranchToolbarBranchSelector({
223 input: { cwd: branchCwd },
224 }),
225 );
259 - const trimmedBranchQuery = branchQuery.trim();
260 - const deferredTrimmedBranchQuery = deferredBranchQuery.trim();
261 - // The server filters refs by substring, so it has to be given the sanitized
262 - // name as well: querying the raw "new branch" drops an existing new-branch
263 - // from the response entirely, which would defeat the collision check below.
264 - // Ref names cannot contain an ASCII space, so sanitizing loses no matches.
265 - const branchRefQuery = sanitizeNewRefName(deferredTrimmedBranchQuery);
226 const branchRefState = usePaginatedBranches({
227 environmentId,
228 cwd: branchCwd,
269 - query: branchRefQuery,
229 + // The server filters refs by substring, so it has to be given the sanitized
230 + // name as well: querying the raw "new branch" drops an existing new-branch
231 + // from the response entirely, which would defeat the collision check below.
232 + // Ref names cannot contain an ASCII space, so sanitizing loses no matches.
233 + query: sanitizeNewRefName(deferredBranchQuery.trim()),
234 });
235 + const trimmedBranchQuery = branchQuery.trim();
236 + const deferredTrimmedBranchQuery = deferredBranchQuery.trim();
237 const refs = branchRefState.refs;
272 - const hasNextPage =
273 - branchRefState.data?.nextCursor !== null && branchRefState.data?.nextCursor !== undefined;
274 - const isFetchingNextPage = branchRefState.isFetchingNextPage;
275 - const isInitialBranchesLoadPending = branchRefState.isPending && branchRefState.data === null;
276 - const currentGitBranch =
277 - branchStatusQuery.data?.refName ?? refs.find((refName) => refName.current)?.name ?? null;
278 - const sourceControlPresentation = getSourceControlPresentation(
279 - branchStatusQuery.data?.sourceControlProvider,
280 - );
281 - const SourceControlIcon = sourceControlPresentation.Icon;
282 - const canonicalActiveBranch = resolveBranchToolbarValue({
283 - envMode: effectiveEnvMode,
284 - activeWorktreePath,
285 - activeThreadBranch,
286 - currentGitBranch,
287 - });
238 const branchByName = new Map(refs.map((refName) => [refName.name, refName] as const));
239 const normalizedDeferredBranchQuery = deferredTrimmedBranchQuery.toLowerCase();
240 const prReference = parsePullRequestReference(trimmedBranchQuery);
@@ -301,11 +251,39 @@ export function BranchToolbarBranchSelector({
251 const createBranchItemValue = canCreateBranch
252 ? `__create_new_branch__:${trimmedBranchQuery}`
253 : null;
304 - const { branchPickerItems, filteredBranchPickerItems } = useBranchPickerItems({
305 - refs,
306 - createBranchItemValue: hasExactBranchMatch ? null : createBranchItemValue,
307 - checkoutPullRequestItemValue,
308 - normalizedQuery: normalizedDeferredBranchQuery,
254 + const defaultBranchName = refs.find((refName) => refName.isDefault)?.name ?? null;
255 + const pickerCreateBranchItemValue = hasExactBranchMatch ? null : createBranchItemValue;
256 + const branchPickerItems = [
257 + ...(checkoutPullRequestItemValue ? [checkoutPullRequestItemValue] : []),
258 + ...refs.map((refName) => refName.name),
259 + ...(pickerCreateBranchItemValue ? [pickerCreateBranchItemValue] : []),
260 + ];
261 + const filteredBranchPickerItems =
262 + normalizedDeferredBranchQuery.length === 0
263 + ? branchPickerItems
264 + : branchPickerItems.filter((itemValue) =>
265 + shouldIncludeBranchPickerItem({
266 + itemValue,
267 + normalizedQuery: normalizedDeferredBranchQuery,
268 + createBranchItemValue: pickerCreateBranchItemValue,
269 + checkoutPullRequestItemValue,
270 + }),
271 + );
272 + const hasNextPage =
273 + branchRefState.data?.nextCursor !== null && branchRefState.data?.nextCursor !== undefined;
274 + const isFetchingNextPage = branchRefState.isFetchingNextPage;
275 + const isInitialBranchesLoadPending = branchRefState.isPending && branchRefState.data === null;
276 + const currentGitBranch =
277 + branchStatusQuery.data?.refName ?? refs.find((refName) => refName.current)?.name ?? null;
278 + const sourceControlPresentation = getSourceControlPresentation(
279 + branchStatusQuery.data?.sourceControlProvider,
280 + );
281 + const SourceControlIcon = sourceControlPresentation.Icon;
282 + const canonicalActiveBranch = resolveBranchToolbarValue({
283 + envMode: effectiveEnvMode,
284 + activeWorktreePath,
285 + activeThreadBranch,
286 + currentGitBranch,
287 });
288 const [resolvedActiveBranch, setOptimisticBranch] = useOptimistic(
289 canonicalActiveBranch,
@@ -499,7 +477,6 @@ export function BranchToolbarBranchSelector({
477 });
478 };
479
502 - const defaultBranchName = refs.find((refName) => refName.isDefault)?.name ?? null;
480 const worktreeBaseBranchCandidate = isInitialBranchesLoadPending
481 ? null
482 : (defaultBranchName ?? currentGitBranch);