Skip to content

Commit 855c266

Browse files
Yash-Singh1claude
andcommitted
fix(web): a link to removed lines in a deleted file positions instead of waiting forever
A removed line was mapped to the new side before checking whether it sat in a hunk, so a deleted file asked the viewer to load contents it never has, and the reveal waited on it for good. Removed lines inside a hunk are now left as is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ed6ebd3 commit 855c266

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎apps/web/src/components/diffs/useCodeViewFileReveal.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,35 @@ describe("createCodeViewFileReveal", () => {
119119
partial = false;
120120
reveal.flush();
121121
expect(view.scrolls).toEqual([{ type: "range", id: "a", range, align: "center" }]);
122+
123+
// Removed lines always sit in a hunk, and a deleted file has no contents to load.
124+
const deleted = viewer(["d"]);
125+
const removedRange = { start: 3, end: 4, side: "deletions" } as const;
126+
reveal.attach({
127+
...deleted,
128+
getInstance: () => ({
129+
getRenderedItems: () => [
130+
{
131+
id: "d",
132+
instance: {
133+
...instance,
134+
getDiffForSearch: () =>
135+
({
136+
isPartial: true,
137+
hunks: [
138+
{ additionStart: 0, additionCount: 0, deletionStart: 1, deletionCount: 8 },
139+
],
140+
}) as never,
141+
},
142+
},
143+
],
144+
}),
145+
});
146+
reveal.request("d", removedRange);
147+
expect(expanded).toHaveLength(1);
148+
expect(deleted.scrolls).toEqual([
149+
{ type: "range", id: "d", range: removedRange, align: "center" },
150+
]);
122151
});
123152

124153
it("drops a pending reveal when another diff's viewer replaces it, but repositions a range a remount loses", () => {

‎apps/web/src/components/diffs/useCodeViewFileReveal.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@ export function createCodeViewFileReveal() {
108108
// Wait for the file contents the expander asked for.
109109
if (pending.loadingFile) return;
110110
const { expandHunk } = rendered.instance;
111-
const opened = [...new Set([startLine, endLine])].map((line) =>
112-
expandPartialDiffToLine(diff, line, expandHunk),
113-
);
111+
// A removed line is always in a hunk, and a deleted file has no contents to load.
112+
const removed = (line: number, side: SelectionSide | undefined) =>
113+
side === "deletions" &&
114+
diff.hunks.some(
115+
(hunk) => line >= hunk.deletionStart && line < hunk.deletionStart + hunk.deletionCount,
116+
);
117+
const outside = [
118+
...new Set([
119+
...(removed(range.start, range.side) ? [] : [startLine]),
120+
...(removed(range.end, range.endSide ?? range.side) ? [] : [endLine]),
121+
]),
122+
];
123+
const opened = outside.map((line) => expandPartialDiffToLine(diff, line, expandHunk));
114124
if (opened.some(Boolean)) {
115125
pending.loadingFile = true;
116126
return;

0 commit comments

Comments
 (0)