@devries-cameron20 / t3code-1 / commits / 9ea9c3d5d2
Fork 0

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

fix(web): keep a file-to-symlink type change from crashing the diff view (#11075)

Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>

Igor Makowski committed Sep 18, 2026 at 13:42 UTC 9ea9c3d5d2c444133e3ddff40eecf38737951589
5 files changed +87 -8
apps/web/src/components/diffs/DiffFileTree.test.tsx
+19
@@ -5,7 +5,10 @@ import { act, type MouseEvent, type ReactNode } from "react";
5 import { create, type ReactTestRenderer } from "react-test-renderer";
6 import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
7
8 +import type { FileDiffMetadata } from "@pierre/diffs";
9 +
10 import { DiffFileTree, type DiffFileTreeEntry } from "./DiffFileTree";
11 +import { diffFileTreeEntries } from "./diffFileTree.logic";
12 import { useCodeViewFileReveal } from "./useCodeViewFileReveal";
13
14 vi.mock("../../hooks/useTheme", () => ({ useTheme: () => ({ resolvedTheme: "dark" }) }));
@@ -112,6 +115,22 @@ describe("diff tree file activation", () => {
115 vi.unstubAllGlobals();
116 });
117
118 + it("mounts a file-to-symlink type change as one tree row", async () => {
119 + // Git carries a type change as a deletion and an addition of the same path.
120 + const typeChange = diffFileTreeEntries([
121 + { type: "deleted", name: "AGENTS.md", prevName: "AGENTS.md" } as FileDiffMetadata,
122 + { type: "new", name: "AGENTS.md", prevName: "AGENTS.md" } as FileDiffMetadata,
123 + { type: "change", name: "CLAUDE.md", prevName: "CLAUDE.md" } as FileDiffMetadata,
124 + ]);
125 + await mount({ files: [...typeChange] });
126 +
127 + const tree = model();
128 + expect(tree.getItem("AGENTS.md")?.isDirectory()).toBe(false);
129 + expect(tree.getItem("CLAUDE.md")?.isDirectory()).toBe(false);
130 + await activate("AGENTS.md");
131 + expect(targets).toEqual([{ type: "item", id: "AGENTS.md\u0000AGENTS.md", align: "start" }]);
132 + });
133 +
134 it("reissues the reveal when the sole selected file is activated again", async () => {
135 await mount();
136 await activate("02-short.ts");
apps/web/src/components/diffs/diffFileTree.logic.test.ts
+17
@@ -34,6 +34,23 @@ describe("diffFileTreeEntries", () => {
34 });
35 });
36
37 +describe("diffFileTreeEntries", () => {
38 + it("folds a file-to-symlink type change into one modified entry", () => {
39 + expect(
40 + diffFileTreeEntries([
41 + file("change", "CLAUDE.md"),
42 + file("deleted", "AGENTS.md"),
43 + file("new", "AGENTS.md"),
44 + file("new", "docs/new.md"),
45 + ]),
46 + ).toEqual([
47 + { path: "CLAUDE.md", status: "modified" },
48 + { path: "AGENTS.md", status: "modified" },
49 + { path: "docs/new.md", status: "added" },
50 + ]);
51 + });
52 +});
53 +
54 describe("collectDirectoryPaths", () => {
55 it("lists every ancestor once, parents first, with Pierre's trailing slash", () => {
56 expect(collectDirectoryPaths(["apps/web/src/a.ts", "apps/web/b.ts", "README.md"])).toEqual([
apps/web/src/components/diffs/diffFileTree.logic.ts
+13 -2
@@ -23,11 +23,22 @@ function toGitStatus(file: FileDiffMetadata): GitStatus {
23 }
24 }
25
26 -/** Maps parsed diff files to tree entries, keeping the diff's own order. */
26 +/**
27 + * Maps parsed diff files to tree entries, keeping the diff's own order. A path
28 + * appears once: a type change (regular file to symlink) is a deletion plus an
29 + * addition of the same path, and the tree shows the surviving file as modified.
30 + */
31 export function diffFileTreeEntries(
32 files: ReadonlyArray<FileDiffMetadata>,
33 ): ReadonlyArray<DiffFileTreeEntry> {
30 - return files.map((file) => ({ path: resolveFileDiffPath(file), status: toGitStatus(file) }));
34 + const statusByPath = new Map<string, GitStatus>();
35 + for (const file of files) {
36 + const path = resolveFileDiffPath(file);
37 + const status = toGitStatus(file);
38 + const previous = statusByPath.get(path);
39 + statusByPath.set(path, previous === undefined || previous === status ? status : "modified");
40 + }
41 + return [...statusByPath].map(([path, status]) => ({ path, status }));
42 }
43
44 /**
apps/web/src/lib/diffRendering.test.ts
+32 -5
@@ -35,10 +35,10 @@ describe("buildPatchCacheKey", () => {
35
36 describe("getRenderablePatch", () => {
37 it.each([
38 - ["a/example.ts", "a/example.ts"],
39 - ["b/example.ts", "b/example.ts"],
40 - ["a/before.ts", "b/after.ts"],
41 - ])("preserves repository paths from %s to %s", (previousPath, path) => {
38 + ["a/example.ts", "a/example.ts", "change"],
39 + ["b/example.ts", "b/example.ts", "change"],
40 + ["a/before.ts", "b/after.ts", "rename-changed"],
41 + ])("preserves repository paths from %s to %s", (previousPath, path, type) => {
42 const parsed = getRenderablePatch(
43 [
44 `diff --git a/${previousPath} b/${path}`,
@@ -59,7 +59,7 @@ describe("getRenderablePatch", () => {
59 if (!file) return;
60 expect(resolveFileDiffPath(file)).toBe(path);
61 expect(resolveFileDiffPreviousPath(file)).toBe(previousPath);
62 - expect(buildFileDiffIdentityKey(file)).toBe(`${previousPath}\0${path}`);
62 + expect(buildFileDiffIdentityKey(file)).toBe(`${previousPath}\0${path}\0${type}`);
63 });
64
65 it("compacts partial hunk render offsets for virtualized review diffs", () => {
@@ -137,6 +137,33 @@ describe("diff file reconciliation", () => {
137 expect(buildFileDiffRenderKey(file)).toBe(key);
138 });
139
140 + it("gives a type change its own identity per block", () => {
141 + const patch = [
142 + "diff --git a/AGENTS.md b/AGENTS.md",
143 + "deleted file mode 100644",
144 + "--- a/AGENTS.md",
145 + "+++ /dev/null",
146 + "@@ -1 +0,0 @@",
147 + "-duplicated instructions",
148 + "diff --git a/AGENTS.md b/AGENTS.md",
149 + "new file mode 120000",
150 + "--- /dev/null",
151 + "+++ b/AGENTS.md",
152 + "@@ -0,0 +1 @@",
153 + "+CLAUDE.md",
154 + ].join("\n");
155 + const parsed = getRenderablePatch(patch, "type-change");
156 + expect(parsed?.kind).toBe("files");
157 + if (parsed?.kind !== "files") return;
158 + const [deleted, added] = parsed.files;
159 + expect(deleted?.type).toBe("deleted");
160 + expect(added?.type).toBe("new");
161 + if (!deleted || !added) return;
162 +
163 + expect(buildFileDiffIdentityKey(deleted)).not.toBe(buildFileDiffIdentityKey(added));
164 + expect(new Set(parsed.files.map(buildFileDiffIdentityKey)).size).toBe(parsed.files.length);
165 + });
166 +
167 it("keeps identities stable and versions local to the changed file", () => {
168 const patch = (secondLine: string) =>
169 [
apps/web/src/lib/diffRendering.ts
+6 -1
@@ -166,8 +166,13 @@ export function resolveFileDiffPreviousPath(fileDiff: FileDiffMetadata): string
166 return fileDiffPath(fileDiff.prevName ?? fileDiff.name ?? "");
167 }
168
169 +/**
170 + * Stable across re-renders of the same file, distinct for every block in a
171 + * patch. A type change (regular file to symlink) arrives as a deletion and an
172 + * addition of the same path, so the change type is part of the identity.
173 + */
174 export function buildFileDiffIdentityKey(fileDiff: FileDiffMetadata): string {
170 - return `${resolveFileDiffPreviousPath(fileDiff)}\u0000${resolveFileDiffPath(fileDiff)}`;
175 + return `${resolveFileDiffPreviousPath(fileDiff)}\u0000${resolveFileDiffPath(fileDiff)}\u0000${fileDiff.type}`;
176 }
177
178 export function buildFileDiffRenderKey(fileDiff: FileDiffMetadata): string {