@devries-cameron20 / t3code-1 / commits / 0a3806ca57
Fork 0

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

refactor(web): paginated branches keep their caching without "use memo" (#20743)

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

Julius Marminge committed Oct 16, 2026 at 23:21 UTC 0a3806ca57f69c7a95a21a2eaafb1d2a65001e4c
1 file changed +15 -36
apps/web/src/state/queries.ts
+15 -36
@@ -97,18 +97,21 @@ export function useThreadSearch(
97 };
98 }
99
100 -// A hook so its result is frozen: `refresh` hands a page atom to the registry,
101 -// which the compiler would treat as a mutation and leave pagesAtom uncached,
102 -// resubscribing every render.
103 -function useBranchPageAtoms(
104 - environmentId: EnvironmentId | null,
105 - cwd: string | null,
106 - query: string,
107 - cursors: ReadonlyArray<number | undefined>,
108 - targetKey: string | null,
109 -) {
110 - // Calls no hooks, so the compiler needs the directive to memoize it.
111 - "use memo";
100 +export function usePaginatedBranches(target: VcsRefTarget) {
101 + // Starts unkeyed: a key mismatch already resolves to the initial cursors, and seeding
102 + // the key here would make every derivation below straddle this hook call.
103 + const [pagination, setPagination] = useState<{
104 + readonly targetKey: string | null;
105 + readonly cursors: ReadonlyArray<number | undefined>;
106 + }>({
107 + targetKey: null,
108 + cursors: INITIAL_BRANCH_CURSORS,
109 + });
110 + const { environmentId, cwd } = target;
111 + const query = target.query?.trim() ?? "";
112 + const targetKey =
113 + environmentId !== null && cwd !== null ? JSON.stringify([environmentId, cwd, query]) : null;
114 + const cursors = pagination.targetKey === targetKey ? pagination.cursors : INITIAL_BRANCH_CURSORS;
115 const pageAtoms =
116 environmentId !== null && cwd !== null
117 ? cursors.map((cursor) =>
@@ -126,30 +129,6 @@ function useBranchPageAtoms(
129 const pagesAtom = Atom.make((get) => pageAtoms.map((atom) => get(atom))).pipe(
130 Atom.withLabel(`web:vcs-ref-pages:${targetKey ?? "empty"}`),
131 );
129 - return { pageAtoms, pagesAtom };
130 -}
131 -
132 -export function usePaginatedBranches(target: VcsRefTarget) {
133 - const query = target.query?.trim() ?? "";
134 - const targetKey =
135 - target.environmentId !== null && target.cwd !== null
136 - ? JSON.stringify([target.environmentId, target.cwd, query])
137 - : null;
138 - const [pagination, setPagination] = useState<{
139 - readonly targetKey: string | null;
140 - readonly cursors: ReadonlyArray<number | undefined>;
141 - }>({
142 - targetKey,
143 - cursors: INITIAL_BRANCH_CURSORS,
144 - });
145 - const cursors = pagination.targetKey === targetKey ? pagination.cursors : INITIAL_BRANCH_CURSORS;
146 - const { pageAtoms, pagesAtom } = useBranchPageAtoms(
147 - target.environmentId,
148 - target.cwd,
149 - query,
150 - cursors,
151 - targetKey,
152 - );
132 const results = useAtomValue(pagesAtom);
133 const values = results.flatMap((result) => {
134 const value = Option.getOrNull(AsyncResult.value(result));