@devries-cameron20 / t3code Mirror · read-only / commits / c62480abff
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, 08:00 UTC

perf(web): query hooks compile with the React Compiler (#20455)

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

Julius Marminge committed Oct 16, 2026 at 18:46 UTC c62480abff883376fc5b0d3df16097c468cd526b
2 files changed +57 -45
apps/web/reactCompiledFiles.ts
+1
@@ -30,4 +30,5 @@ export const REACT_COMPILED_FILES = [
30 "apps/web/src/assets/assetUrls.ts",
31 "apps/web/src/components/ui/toggle-group.tsx",
32 "apps/web/src/components/ThreadNotificationCoordinator.tsx",
33 + "apps/web/src/state/queries.ts",
34 ] as const;
apps/web/src/state/queries.ts
+56 -45
@@ -22,7 +22,7 @@ import type {
22 import * as Cause from "effect/Cause";
23 import * as Option from "effect/Option";
24 import { AsyncResult, Atom } from "effect/reactivity";
25 -import { useCallback, useEffect, useMemo, useState } from "react";
25 +import { useEffect, useState } from "react";
26
27 import { appAtomRegistry } from "../rpc/atomRegistry";
28 import { useFilesystemReadAccess } from "./filesystem";
@@ -84,10 +84,8 @@ export function useThreadSearch(
84 const debouncedQuery = useDebouncedValue(normalizedQuery, THREAD_SEARCH_DEBOUNCE_MS);
85 const canSearch = environmentIds.length > 0 && normalizedQuery.length >= 2;
86 const settledQuery = canSearch && normalizedQuery === debouncedQuery ? debouncedQuery : null;
87 - const searchKey = useMemo(
88 - () => (settledQuery === null ? null : makeThreadSearchKey(environmentIds, settledQuery)),
89 - [environmentIds, settledQuery],
90 - );
87 + const searchKey =
88 + settledQuery === null ? null : makeThreadSearchKey(environmentIds, settledQuery);
89 const result = useAtomValue(
90 searchKey === null ? EMPTY_THREAD_SEARCH_ATOM : threadSearchResultsAtom(searchKey),
91 );
@@ -99,6 +97,38 @@ 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";
112 + const pageAtoms =
113 + environmentId !== null && cwd !== null
114 + ? cursors.map((cursor) =>
115 + vcsEnvironment.listRefs({
116 + environmentId,
117 + input: {
118 + cwd,
119 + ...(query.length > 0 ? { query } : {}),
120 + ...(cursor === undefined ? {} : { cursor }),
121 + limit: VCS_REF_LIST_LIMIT,
122 + },
123 + }),
124 + )
125 + : [];
126 + const pagesAtom = Atom.make((get) => pageAtoms.map((atom) => get(atom))).pipe(
127 + Atom.withLabel(`web:vcs-ref-pages:${targetKey ?? "empty"}`),
128 + );
129 + return { pageAtoms, pagesAtom };
130 +}
131 +
132 export function usePaginatedBranches(target: VcsRefTarget) {
133 const query = target.query?.trim() ?? "";
134 const targetKey =
@@ -113,29 +143,12 @@ export function usePaginatedBranches(target: VcsRefTarget) {
143 cursors: INITIAL_BRANCH_CURSORS,
144 });
145 const cursors = pagination.targetKey === targetKey ? pagination.cursors : INITIAL_BRANCH_CURSORS;
116 - const pageAtoms = useMemo(
117 - () =>
118 - target.environmentId !== null && target.cwd !== null
119 - ? cursors.map((cursor) =>
120 - vcsEnvironment.listRefs({
121 - environmentId: target.environmentId!,
122 - input: {
123 - cwd: target.cwd!,
124 - ...(query.length > 0 ? { query } : {}),
125 - ...(cursor === undefined ? {} : { cursor }),
126 - limit: VCS_REF_LIST_LIMIT,
127 - },
128 - }),
129 - )
130 - : [],
131 - [cursors, query, target.cwd, target.environmentId],
132 - );
133 - const pagesAtom = useMemo(
134 - () =>
135 - Atom.make((get) => pageAtoms.map((atom) => get(atom))).pipe(
136 - Atom.withLabel(`web:vcs-ref-pages:${targetKey ?? "empty"}`),
137 - ),
138 - [pageAtoms, targetKey],
146 + const { pageAtoms, pagesAtom } = useBranchPageAtoms(
147 + target.environmentId,
148 + target.cwd,
149 + query,
150 + cursors,
151 + targetKey,
152 );
153 const results = useAtomValue(pagesAtom);
154 const values = results.flatMap((result) => {
@@ -171,25 +184,26 @@ export function usePaginatedBranches(target: VcsRefTarget) {
184 : "Failed to load refs.";
185 })()
186 : null;
174 - const refresh = useCallback(() => {
187 + const refresh = () => {
188 const firstPage = pageAtoms[0];
189 setPagination({ targetKey, cursors: INITIAL_BRANCH_CURSORS });
190 if (firstPage !== undefined) {
191 appAtomRegistry.refresh(firstPage);
192 }
180 - }, [pageAtoms, targetKey]);
181 - const loadNext = useCallback(() => {
182 - if (targetKey === null || data?.nextCursor === null || data?.nextCursor === undefined) {
193 + };
194 + const nextCursor = data?.nextCursor;
195 + const loadNext = () => {
196 + if (targetKey === null || nextCursor === null || nextCursor === undefined) {
197 return;
198 }
199 setPagination((current) => {
200 const currentCursors =
201 current.targetKey === targetKey ? current.cursors : INITIAL_BRANCH_CURSORS;
188 - return currentCursors.includes(data.nextCursor!)
202 + return currentCursors.includes(nextCursor)
203 ? { targetKey, cursors: currentCursors }
190 - : { targetKey, cursors: [...currentCursors, data.nextCursor!] };
204 + : { targetKey, cursors: [...currentCursors, nextCursor] };
205 });
192 - }, [data?.nextCursor, targetKey]);
206 + };
207
208 return {
209 data,
@@ -226,16 +240,13 @@ export function useProjectPathSearch(
240 options?: { readonly allowEmptyQuery?: boolean },
241 ) {
242 const allowEmptyQuery = options?.allowEmptyQuery === true;
229 - const normalizedTarget = useMemo(
230 - () => ({
231 - environmentId: target.environmentId,
232 - cwd: target.cwd,
233 - query: target.query == null ? null : target.query.trim(),
234 - kind: target.kind,
235 - imageOnly: target.imageOnly,
236 - }),
237 - [target.cwd, target.environmentId, target.imageOnly, target.kind, target.query],
238 - );
243 + const normalizedTarget = {
244 + environmentId: target.environmentId,
245 + cwd: target.cwd,
246 + query: target.query == null ? null : target.query.trim(),
247 + kind: target.kind,
248 + imageOnly: target.imageOnly,
249 + };
250 const debouncedTarget = useDebouncedValue(normalizedTarget, PROJECT_PATH_SEARCH_DEBOUNCE_MS);
251 const fileAccess = useFilesystemReadAccess(debouncedTarget.environmentId);
252 const { canReadFiles } = fileAccess;