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

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

perf(web): reveal nested files faster (#21048)

Guanying Chen committed Oct 18, 2026 at 12:12 UTC 1ea378c6f432223a84d7a38fc58781bdb38347ee
3 files changed +56 -6
apps/web/src/components/files/FileBrowserPanel.tsx
+2 -6
@@ -31,6 +31,7 @@ import { joinHostPath } from "./filePath";
31 import { createFileTreeDragMentionController } from "./fileTreeDragMention";
32 import { areAllDirectoriesExpanded, setAllDirectoriesExpanded } from "./fileTreeExpansion";
33 import { buildFileTreePathUpdates } from "./fileTreePathReconciliation";
34 +import { loadFileAncestors } from "./loadFileAncestors";
35 import { useDirectoryEntries } from "./useDirectoryEntries";
36 import { useProjectPathSearch } from "~/state/queries";
37
@@ -366,12 +367,7 @@ export default function FileBrowserPanel({
367 useEffect(() => {
368 if (!selectedPath) return;
369 const controller = new AbortController();
369 - void (async () => {
370 - const segments = selectedPath.split("/");
371 - for (let index = 0; index < segments.length && !controller.signal.aborted; index++) {
372 - await load(segments.slice(0, index).join("/"));
373 - }
374 - })();
370 + void loadFileAncestors(selectedPath, load, { signal: controller.signal });
371 return () => {
372 controller.abort();
373 };
apps/web/src/components/files/loadFileAncestors.test.ts new
+39
@@ -0,0 +1,39 @@
1 +import { expect, it } from "vite-plus/test";
2 +import { loadFileAncestors } from "./loadFileAncestors";
3 +
4 +function queuedLoader() {
5 + const paths: string[] = [];
6 + const resolve: Array<() => void> = [];
7 + const load = (path: string) => {
8 + paths.push(path);
9 + return new Promise<void>((done) => resolve.push(done));
10 + };
11 + return { paths, resolve, load };
12 +}
13 +
14 +it("bounds loads to four and finishes children even when parents finish last", async () => {
15 + const queue = queuedLoader();
16 + const loading = loadFileAncestors("a/b/c/d/e/f/file.ts", queue.load, new AbortController());
17 + for (let index = 3; index < 6; index++) {
18 + queue.resolve[index]?.();
19 + await Promise.resolve();
20 + expect(queue.paths).toHaveLength(index + 2);
21 + }
22 + expect(queue.paths).toEqual(["", "a", "a/b", "a/b/c", "a/b/c/d", "a/b/c/d/e", "a/b/c/d/e/f"]);
23 + for (const resolve of queue.resolve) resolve();
24 + await loading;
25 +});
26 +
27 +it("stops aborted reveals while a new selection loads independently", async () => {
28 + const old = queuedLoader();
29 + const controller = new AbortController();
30 + const oldReveal = loadFileAncestors("old/a/b/c/d/file.ts", old.load, controller);
31 + controller.abort();
32 + const fresh = queuedLoader();
33 + const newReveal = loadFileAncestors("new/file.ts", fresh.load, new AbortController());
34 + for (const resolve of [...old.resolve, ...fresh.resolve]) resolve();
35 + await Promise.all([oldReveal, newReveal]);
36 + await loadFileAncestors("aborted/path/file.ts", old.load, controller);
37 + expect(old.paths).toEqual(["", "old", "old/a", "old/a/b"]);
38 + expect(fresh.paths).toEqual(["", "new"]);
39 +});
apps/web/src/components/files/loadFileAncestors.ts new
+15
@@ -0,0 +1,15 @@
1 +/** The loader owns deduplication and the shared request cap, including other tree loads. */
2 +export async function loadFileAncestors(
3 + selectedPath: string,
4 + load: (directoryPath: string) => Promise<void>,
5 + options: { readonly signal: AbortSignal },
6 +) {
7 + const segments = selectedPath.split("/");
8 + let next = 0;
9 + const worker = async () => {
10 + while (next < segments.length && !options.signal.aborted) {
11 + await load(segments.slice(0, next++).join("/"));
12 + }
13 + };
14 + await Promise.all(Array.from({ length: Math.min(4, segments.length) }, worker));
15 +}