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 22, 23:15 UTC
fix(web): expanding all folders in Files no longer walks node_modules (#21258)
Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
tiliakoos committed
Oct 20, 2026 at 00:24 UTC
64a76c84ef795b41cffa884491a4c961f9ac0af4
2 files changed
+104
-14
apps/web/src/components/files/FileBrowserPanel.browser.test.tsx
+87
-2
@@ -15,7 +15,7 @@ const files = vi.hoisted(() => ({
15
searchPending: false,
16
searchError: null as string | null,
17
loadingDirectories: new Set<string>() as ReadonlySet<string>,
18
- load: vi.fn(async () => {}),
18
+ load: vi.fn(async (_directoryPath: string) => {}),
19
refresh: vi.fn(),
20
}));
21
@@ -52,7 +52,7 @@ vi.mock("~/components/ui/tooltip", () => ({
52
TooltipPopup: () => null,
53
}));
54
55
-describe("Files panel search", () => {
55
+describe("Files panel", () => {
56
let root: Root | undefined;
57
let container: HTMLDivElement | undefined;
58
const props = {
@@ -243,4 +243,89 @@ describe("Files panel search", () => {
243
expect(hasMessage("No matching files.")).toBe(false);
244
expect(container!.textContent).toContain("Workspace search failed.");
245
});
246
+
247
+ describe("expand all", () => {
248
+ const workspace: Record<string, ProjectEntry[]> = {
249
+ src: [
250
+ { path: "src/lib", kind: "directory" },
251
+ { path: "src/index.ts", kind: "file" },
252
+ ],
253
+ "src/lib": [{ path: "src/lib/util.ts", kind: "file" }],
254
+ node_modules: [
255
+ { path: "node_modules/react", kind: "directory", ignored: true },
256
+ { path: "node_modules/.modules.yaml", kind: "file", ignored: true },
257
+ ],
258
+ "node_modules/react": [{ path: "node_modules/react/index.js", kind: "file", ignored: true }],
259
+ };
260
+ const listed = () => files.load.mock.calls.map(([path]) => path);
261
+
262
+ // Answer each listing the panel asks for, as the server would, until it asks for no more.
263
+ async function answerListings() {
264
+ const answered = new Set<string>();
265
+ for (;;) {
266
+ const path = listed().find((requested) => !answered.has(requested));
267
+ if (path === undefined) return;
268
+ answered.add(path);
269
+ files.directoryEntries = [...files.directoryEntries, ...(workspace[path] ?? [])];
270
+ await render();
271
+ }
272
+ }
273
+
274
+ function button(label: "Expand all folders" | "Collapse all folders") {
275
+ const match = container!.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
276
+ expect(match, label).not.toBeNull();
277
+ return match!;
278
+ }
279
+
280
+ async function clickRow(path: string) {
281
+ const row = container!
282
+ .querySelector("file-tree-container")!
283
+ .shadowRoot!.querySelector<HTMLElement>(`[data-item-path="${path}"]`);
284
+ expect(row, path).not.toBeNull();
285
+ await act(async () => row!.click());
286
+ await answerListings();
287
+ }
288
+
289
+ beforeEach(() => {
290
+ files.load.mockClear();
291
+ files.directoryEntries = [
292
+ { path: "src", kind: "directory" },
293
+ { path: "node_modules", kind: "directory", ignored: true },
294
+ { path: "README.md", kind: "file" },
295
+ ];
296
+ });
297
+
298
+ it("opens every folder except ignored ones, which it never lists", async () => {
299
+ await render();
300
+ await act(async () => button("Expand all folders").click());
301
+ await answerListings();
302
+
303
+ expect(listed().toSorted()).toEqual(["src", "src/lib"]);
304
+ expect(visiblePaths()).toContain("src/lib/util.ts");
305
+ expect(visiblePaths()).not.toContain("node_modules/.modules.yaml");
306
+ button("Collapse all folders");
307
+
308
+ // Collapsing a folder by hand ends expand all; reopening it counts as all expanded again,
309
+ // with the ignored folder still closed.
310
+ await clickRow("src/lib/");
311
+ button("Expand all folders");
312
+ await clickRow("src/lib/");
313
+ button("Collapse all folders");
314
+ });
315
+
316
+ it("opens an ignored folder by hand without walking into it, and collapses it with the rest", async () => {
317
+ await render();
318
+ await act(async () => button("Expand all folders").click());
319
+ await answerListings();
320
+
321
+ await clickRow("node_modules/");
322
+ expect(listed()).toContain("node_modules");
323
+ expect(listed()).not.toContain("node_modules/react");
324
+ expect(visiblePaths()).toContain("node_modules/react/");
325
+ expect(visiblePaths()).not.toContain("node_modules/react/index.js");
326
+
327
+ await act(async () => button("Collapse all folders").click());
328
+ expect(visiblePaths()).toEqual(["node_modules/", "src/", "README.md"]);
329
+ });
330
+ });
331
});
apps/web/src/components/files/FileBrowserPanel.tsx
+17
-12
@@ -130,8 +130,12 @@ function buildTreeEntries(
130
entries.map((entry) => [entry.path, entry.kind] as const),
131
);
132
const treePaths = entries.map(treePath);
133
- const directoryPaths = entries.filter((entry) => entry.kind === "directory").map(treePath);
134
- return { entries, entryKinds, treePaths, directoryPaths };
133
+ const directories = entries.filter((entry) => entry.kind === "directory");
134
+ const directoryPaths = directories.map(treePath);
135
+ // Expanding a folder lists it, and an ignored one such as `node_modules` can hold tens of
136
+ // thousands, so expand all skips ignored folders. They still open by hand.
137
+ const expandableDirectoryPaths = directories.filter((entry) => !entry.ignored).map(treePath);
138
+ return { entries, entryKinds, treePaths, directoryPaths, expandableDirectoryPaths };
139
}
140
141
export default function FileBrowserPanel({
@@ -165,12 +169,8 @@ export default function FileBrowserPanel({
169
{ environmentId, cwd: hostFolder ? null : cwd, query: query.slice(0, 256) },
170
200,
171
);
168
- const { entries, entryKinds, treePaths, directoryPaths } = buildTreeEntries(
169
- directoryEntries,
170
- pathSearch.entries,
171
- pathSearch.isPending,
172
- query,
173
- );
172
+ const { entries, entryKinds, treePaths, directoryPaths, expandableDirectoryPaths } =
173
+ buildTreeEntries(directoryEntries, pathSearch.entries, pathSearch.isPending, query);
174
const entryKindsRef = useRef(entryKinds);
175
const previousTreePathsRef = useRef<readonly string[] | null>(null);
176
const syncingSelectionRef = useRef(false);
@@ -321,12 +321,16 @@ export default function FileBrowserPanel({
321
// Pierre restores the unfiltered tree when a search has no matches.
322
const hasNoSearchMatches = search.value.trim().length > 0 && search.matchingPaths.length === 0;
323
const allDirectoriesExpanded = useFileTreeSelector(model, (currentModel) =>
324
- areAllDirectoriesExpanded(currentModel, directoryPaths),
324
+ areAllDirectoriesExpanded(currentModel, expandableDirectoryPaths),
325
);
326
const toggleAllDirectories = () => {
327
const expanded = !(expandAll || allDirectoriesExpanded);
328
setExpandAll(expanded);
329
- setAllDirectoriesExpanded(model, directoryPaths, expanded);
329
+ setAllDirectoriesExpanded(
330
+ model,
331
+ expanded ? expandableDirectoryPaths : directoryPaths,
332
+ expanded,
333
+ );
334
};
335
const closeSearch = () => {
336
setQuery("");
@@ -411,8 +415,9 @@ export default function FileBrowserPanel({
415
}, [ready, entryKinds, model, treePaths]);
416
417
useEffect(() => {
414
- if (expandAll && !query.trim()) setAllDirectoriesExpanded(model, directoryPaths, true);
415
- }, [directoryPaths, expandAll, model, query]);
418
+ if (expandAll && !query.trim())
419
+ setAllDirectoriesExpanded(model, expandableDirectoryPaths, true);
420
+ }, [expandableDirectoryPaths, expandAll, model, query]);
421
422
useEffect(() => {
423
if (!selectedPath) {