The best way to control Claude Code, Codex and more from any computer or phone
fix(web): collapsing a changed-files folder no longer leaves a one-frame gap (#22311)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Yuruzuu committed
Oct 31, 2026 at 16:43 UTC
e1e60080b99f8e014f372d171bca71ddd164faa3
2 files changed
+87
-3
apps/web/src/components/chat/ChangedFilesTree.tsx
+9
-1
@@ -1,3 +1,4 @@
1
+import { useSyncLayout } from "@legendapp/list/react";
2
import { type OrchestrationV2CheckpointFileTotals, type RunId } from "@t3tools/contracts";
3
import { type MouseEvent, type ReactNode, memo, useLayoutEffect, useRef, useState } from "react";
4
import { type TurnDiffFileChange } from "../../types";
@@ -45,6 +46,7 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
46
onOpenTurnDiff,
47
onFileContextMenu,
48
} = props;
49
+ const syncTimelineLayout = useSyncLayout();
50
const hiddenFileCount = totals.count - files.length;
51
const hasDirectories = files.some((file) => /[/\\]/.test(file.path));
52
@@ -83,7 +85,10 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
85
allDirectoriesExpanded ? "Collapse all folders" : "Expand all folders"
86
}
87
data-scroll-anchor-ignore
86
- onClick={onToggleAllDirectories}
88
+ onClick={() => {
89
+ onToggleAllDirectories();
90
+ syncTimelineLayout();
91
+ }}
92
/>
93
}
94
>
@@ -157,6 +162,7 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
162
key: string | null;
163
overrides: Record<string, boolean>;
164
}>({ key: null, overrides: {} });
165
+ const syncTimelineLayout = useSyncLayout();
166
const treeNodes = buildTurnDiffTree(files);
167
const directoryPathsKey = collectDirectoryPaths(treeNodes).join("\u0000");
168
const hasDirectoryNodes = directoryPathsKey.length > 0;
@@ -177,6 +183,8 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
183
},
184
};
185
});
186
+ // Measure before paint instead of waiting for LegendList's deferred shrink measurement.
187
+ syncTimelineLayout();
188
};
189
190
const rows = collectExpandedRows(treeNodes, expandedDirectories, allDirectoriesExpanded);
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+78
-2
@@ -1,3 +1,4 @@
1
+import { flushSync } from "react-dom";
2
import { AudioPreview } from "../files/AudioPreview";
3
import { page } from "vite-plus/test/browser";
4
import {
@@ -15,8 +16,15 @@ import {
16
ThreadId,
17
type OrchestrationV2Subagent,
18
} from "@t3tools/contracts";
18
-import type { LegendListRef } from "@legendapp/list/react";
19
-import { createRef, Profiler, StrictMode, type ComponentProps, type ReactElement } from "react";
19
+import { LegendList, type LegendListRef } from "@legendapp/list/react";
20
+import {
21
+ createRef,
22
+ Profiler,
23
+ StrictMode,
24
+ useState,
25
+ type ComponentProps,
26
+ type ReactElement,
27
+} from "react";
28
import * as DateTime from "effect/DateTime";
29
import { Atom } from "effect/reactivity";
30
import { describe, expect, it, onTestFinished, vi } from "vite-plus/test";
@@ -25,6 +33,7 @@ import "~/index.css";
33
34
import { environmentThreadDetails } from "../../state/threads";
35
import { act, fakeTimers, render, stubGlobal } from "../../../test/render";
36
+import { ChangedFilesCard } from "./ChangedFilesTree";
37
import { MessagesTimeline } from "./MessagesTimeline";
38
import { makeStreamingTimelineFixture } from "../../test-fixtures";
39
import {
@@ -1192,6 +1201,73 @@ it("renders automatic compaction as one live divider that finishes with its reas
1201
expect(container.textContent).not.toContain("Compacting before");
1202
});
1203
1204
+function TimelineChangedFilesCard() {
1205
+ const [expanded, setExpanded] = useState(true);
1206
+ return (
1207
+ <ChangedFilesCard
1208
+ runId={RunId.make("run-1")}
1209
+ files={["src/a.ts", "src/b.ts", "src/c.ts"].map((path) => ({
1210
+ path,
1211
+ kind: "modified",
1212
+ additions: 1,
1213
+ deletions: 0,
1214
+ }))}
1215
+ totals={{ count: 3, additions: 3, deletions: 0 }}
1216
+ allDirectoriesExpanded={expanded}
1217
+ resolvedTheme="light"
1218
+ onToggleAllDirectories={() => setExpanded((value) => !value)}
1219
+ onOpenTurnDiff={() => {}}
1220
+ />
1221
+ );
1222
+}
1223
+
1224
+function ChangedFilesTimeline() {
1225
+ return (
1226
+ <LegendList
1227
+ data={["files", "after"]}
1228
+ keyExtractor={(item) => item}
1229
+ estimatedItemSize={100}
1230
+ recycleItems={false}
1231
+ className="h-[600px]"
1232
+ renderItem={({ item }) =>
1233
+ item === "files" ? <TimelineChangedFilesCard /> : <div data-testid="after">After</div>
1234
+ }
1235
+ />
1236
+ );
1237
+}
1238
+
1239
+describe("ChangedFilesCard", () => {
1240
+ it.each(["folder", "all folders"])(
1241
+ "measures %s collapse and expansion in the same commit",
1242
+ async (toggle) => {
1243
+ await using screen = await render(<ChangedFilesTimeline />);
1244
+ const after = () =>
1245
+ screen.container.querySelector('[data-testid="after"]')!.getBoundingClientRect().top;
1246
+ const cardBottom = () =>
1247
+ screen.container.querySelector("[data-changed-files-state]")!.getBoundingClientRect()
1248
+ .bottom;
1249
+ await vi.waitFor(() => expect(after()).toBe(cardBottom()));
1250
+ const topBefore = after();
1251
+ const button = () =>
1252
+ screen.container.querySelector<HTMLButtonElement>(
1253
+ toggle === "folder"
1254
+ ? '[data-changed-file-row="src"] button'
1255
+ : 'button[aria-label$="all folders"]',
1256
+ )!;
1257
+ await act(() => {
1258
+ flushSync(() => button().click());
1259
+ expect(screen.container.textContent).not.toContain("a.ts");
1260
+ expect(after()).toBe(topBefore - 3 * 28);
1261
+ });
1262
+ await act(() => {
1263
+ flushSync(() => button().click());
1264
+ expect(screen.container.textContent).toContain("a.ts");
1265
+ expect(after()).toBe(topBefore);
1266
+ });
1267
+ },
1268
+ );
1269
+});
1270
+
1271
it("keeps concurrent approvals actionable outside collapsed work and restores settled rows", async () => {
1272
setup();
1273
const fixture = makeStreamingTimelineFixture();