The best way to control Claude Code, Codex and more from any computer or phone
perf(web): compact changed-file directories once (#27073)
Utkarsh Patil committed
Nov 2, 2026 at 03:11 UTC
e4d1edaabdcef2a44f2f0a825015f08c4555c1c9
2 files changed
+16
-8
apps/web/src/lib/turnDiffTree.test.ts
+15
@@ -87,6 +87,21 @@ describe("buildTurnDiffTree", () => {
87
});
88
89
it("compacts only single-directory chains and stops at branch points", () => {
90
+ expect(
91
+ buildTurnDiffTree([
92
+ { path: "src/a/b/first.ts", kind: "modified", additions: 1, deletions: 0 },
93
+ { path: "src/c/d/second.ts", kind: "modified", additions: 2, deletions: 0 },
94
+ ]),
95
+ ).toMatchObject([
96
+ {
97
+ name: "src",
98
+ children: [
99
+ { name: "a/b", path: "src/a/b", children: [{ name: "first.ts" }] },
100
+ { name: "c/d", path: "src/c/d", children: [{ name: "second.ts" }] },
101
+ ],
102
+ },
103
+ ]);
104
+
105
const tree = buildTurnDiffTree([
106
{ path: "apps/server/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
107
{ path: "apps/server/main.ts", kind: "modified", additions: 4, deletions: 0 },
apps/web/src/lib/turnDiffTree.ts
+1
-8
@@ -56,14 +56,7 @@ function readStat(file: TurnDiffFileChange): TurnDiffStat | null {
56
}
57
58
function compactDirectoryNode(node: TurnDiffTreeDirectoryNode): TurnDiffTreeDirectoryNode {
59
- const compactedChildren = node.children.map((child) =>
60
- child.kind === "directory" ? compactDirectoryNode(child) : child,
61
- );
62
-
63
- let compactedNode: TurnDiffTreeDirectoryNode = {
64
- ...node,
65
- children: compactedChildren,
66
- };
59
+ let compactedNode = node;
60
61
while (compactedNode.children.length === 1 && compactedNode.children[0]?.kind === "directory") {
62
const onlyChild = compactedNode.children[0];