Skip to content

Commit 84b0fa7

Browse files
committed
fix: don't enrich chapter-filtered diffs with full file content
Pierre requires all hunks to be present when isPartial=false (trailing context must match on both sides). Chapter pages show a subset of hunks, so enrichment is only correct on the Files page where the full per-file diff is used.
1 parent e31d137 commit 84b0fa7

2 files changed

Lines changed: 6 additions & 21 deletions

File tree

packages/web/src/lib/filter-files-for-chapter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { getSingularPatch } from "@pierre/diffs";
22
import type { HunkReference } from "@stagereview/types/chapters";
3-
import type { FileContentsMap } from "@stagereview/types/diff";
43
import type { FileDiffEntry } from "./parse-diff";
5-
import { enrichFileDiff, fileDiffToPullRequestFile } from "./parse-diff";
4+
import { fileDiffToPullRequestFile } from "./parse-diff";
65

76
const HUNK_HEADER_RE = /^@@\s+-(\d+)(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/;
87
const FILE_BREAK = /\ndiff --git /g;
@@ -89,7 +88,6 @@ function filterHunksInFile(perFileText: string, oldStarts: ReadonlySet<number>):
8988
export function filterFilesForChapter(
9089
patch: string,
9190
hunkRefs: readonly HunkReference[],
92-
fileContents?: FileContentsMap,
9391
): FileDiffEntry[] {
9492
if (hunkRefs.length === 0) return [];
9593

@@ -120,8 +118,7 @@ export function filterFilesForChapter(
120118
const filteredText = filterHunksInFile(segment.text, oldStarts);
121119
if (filteredText === null) continue;
122120

123-
const baseDiff = getSingularPatch(filteredText);
124-
const diff = enrichFileDiff(baseDiff, fileContents);
121+
const diff = getSingularPatch(filteredText);
125122
result.push({ file: fileDiffToPullRequestFile(diff), diff });
126123
}
127124

packages/web/src/routes/chapter-detail-page.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Chapter, LineRef } from "@stagereview/types/chapters";
2-
import type { FileContentsMap } from "@stagereview/types/diff";
32
import { Link, useNavigate } from "@tanstack/react-router";
43
import { useCallback, useMemo, useRef, useState } from "react";
54
import { useHotkeys } from "react-hotkeys-hook";
@@ -58,28 +57,17 @@ export function ChapterDetailPage({ runId, chapterNumber }: ChapterDetailPagePro
5857
}
5958

6059
return (
61-
<ChapterDetailContent
62-
chapter={chapter}
63-
chapterIndex={chapterIndex}
64-
patch={diffData.patch}
65-
fileContents={diffData.fileContents}
66-
/>
60+
<ChapterDetailContent chapter={chapter} chapterIndex={chapterIndex} patch={diffData.patch} />
6761
);
6862
}
6963

7064
interface ChapterDetailContentProps {
7165
chapter: Chapter;
7266
chapterIndex: number;
7367
patch: string;
74-
fileContents: FileContentsMap;
7568
}
7669

77-
function ChapterDetailContent({
78-
chapter,
79-
chapterIndex,
80-
patch,
81-
fileContents,
82-
}: ChapterDetailContentProps) {
70+
function ChapterDetailContent({ chapter, chapterIndex, patch }: ChapterDetailContentProps) {
8371
const { runId, chapters: allChapters } = useChapterContext();
8472
const view = useViewState(runId);
8573
const [focusedKeyChangeId, setFocusedKeyChangeId] = useState<string | null>(null);
@@ -93,8 +81,8 @@ function ChapterDetailContent({
9381
}
9482

9583
const chapterEntries = useMemo(
96-
() => filterFilesForChapter(patch, chapter.hunkRefs, fileContents),
97-
[patch, chapter.hunkRefs, fileContents],
84+
() => filterFilesForChapter(patch, chapter.hunkRefs),
85+
[patch, chapter.hunkRefs],
9886
);
9987

10088
const allLineRefsByFile = useMemo(

0 commit comments

Comments
 (0)