@devries-cameron20 / t3code-1 / commits / 178e2abce9
Fork 0

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

fix(web): keep large collapsed file trees virtualized (#21831)

Utkarsh Patil committed Oct 20, 2026 at 01:56 UTC 178e2abce998bfb608ee12a804501868c3d716f8
2 files changed +41 -11
apps/web/src/components/chat/ChangedFilesTree.browser.test.tsx
+39 -7
@@ -107,12 +107,12 @@ describe("ChangedFilesTree", () => {
107 file(`src/file-${index.toString().padStart(5, "0")}.ts`),
108 );
109
110 - it("virtualizes above 250 expanded files and disables it when folders collapse below that count", async () => {
110 + it("virtualizes above 250 visible rows and disables it when folders collapse below that count", async () => {
111 await render(
112 <div style={{ height: 280, overflowY: "auto" }}>
113 <ChangedFilesTree
114 runId={RunId.make("run-1")}
115 - files={[...manyFiles.slice(0, 250), file("extra/overflow.ts")]}
115 + files={[...manyFiles.slice(0, 248), file("extra/overflow.ts")]}
116 allDirectoriesExpanded={false}
117 resolvedTheme="light"
118 onOpenTurnDiff={() => {}}
@@ -122,20 +122,52 @@ describe("ChangedFilesTree", () => {
122 expect(container.querySelectorAll("button").length).toBe(2);
123
124 await act(async () => buttonWithText("src").click());
125 - expect(container.querySelectorAll("button").length).toBe(252);
126 - expect(text()).toContain("file-00249.ts");
125 + expect(container.querySelectorAll("button").length).toBe(250);
126 + expect(text()).toContain("file-00247.ts");
127 expect(text()).not.toContain("overflow.ts");
128
129 await act(async () => buttonWithText("extra").click());
130 expect(container.querySelectorAll("button").length).toBeLessThan(60);
131 - expect(text()).not.toContain("file-00249.ts");
131 + expect(text()).not.toContain("file-00247.ts");
132
133 await act(async () => buttonWithText("extra").click());
134 - expect(container.querySelectorAll("button").length).toBe(252);
135 - expect(text()).toContain("file-00249.ts");
134 + expect(container.querySelectorAll("button").length).toBe(250);
135 + expect(text()).toContain("file-00247.ts");
136 expect(text()).not.toContain("overflow.ts");
137 });
138
139 + it("keeps 1,000 collapsed folders virtualized and reachable after scrolling", async () => {
140 + const files = Array.from({ length: 1_000 }, (_, index) =>
141 + file(`folder-${index.toString().padStart(4, "0")}/index.ts`),
142 + );
143 + const content = (expanded: boolean) => (
144 + <div style={{ height: 280, overflowY: "auto" }}>
145 + <ChangedFilesTree
146 + runId={RunId.make("run-1")}
147 + files={files}
148 + allDirectoriesExpanded={expanded}
149 + resolvedTheme="light"
150 + onOpenTurnDiff={() => {}}
151 + />
152 + </div>
153 + );
154 + await render(content(true));
155 + expect(container.querySelectorAll("button").length).toBeLessThan(60);
156 +
157 + await render(content(false));
158 + expect(container.querySelectorAll("button").length).toBeLessThan(60);
159 + expect(text()).toContain("folder-0000");
160 + expect(text()).not.toContain("index.ts");
161 + expect(text()).not.toContain("folder-0999");
162 +
163 + const viewport = container.firstElementChild as HTMLElement;
164 + await scrollTo(viewport, viewport.scrollHeight);
165 + expect(text()).toContain("folder-0999");
166 + expect(container.querySelectorAll("button").length).toBeLessThan(60);
167 + await act(async () => buttonWithText("folder-0999").click());
168 + expect(text()).toContain("index.ts");
169 + });
170 +
171 it("keeps expand-all bounded and opens files after scrolling the surrounding viewport", async () => {
172 const onOpenTurnDiff = vi.fn();
173 const onFileContextMenu = vi.fn();
apps/web/src/components/chat/ChangedFilesTree.tsx
+2 -4
@@ -18,7 +18,7 @@ import { MorphIcon } from "~/components/MorphIcon";
18 import { observeResize } from "~/lib/observeResize";
19
20 const EMPTY_DIRECTORY_OVERRIDES: Record<string, boolean> = {};
21 -const VIRTUALIZE_AFTER_FILES = 250;
21 +const VIRTUALIZE_AFTER_ROWS = 250;
22 const ROW_OVERSCAN = 8;
23
24 interface ChangedFileRow {
@@ -170,9 +170,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
170 };
171
172 const rows = collectExpandedRows(treeNodes, expandedDirectories, allDirectoriesExpanded);
173 - const virtualized =
174 - rows.reduce((count, row) => count + (row.node.kind === "file" ? 1 : 0), 0) >
175 - VIRTUALIZE_AFTER_FILES;
173 + const virtualized = rows.length > VIRTUALIZE_AFTER_ROWS;
174
175 const renderRow = ({ node, depth }: ChangedFileRow) => {
176 const leftPadding = 8 + depth * 14;