Skip to content

Commit f109eed

Browse files
refactor(web): drop the redundant diff stat wrapper and comment-file ref
DiffStatLabel is already memoized on its two numbers, so the DiffFileHeaderStat wrapper added nothing. beginComment now reads the file diff and path from the viewer item it is handed, which removes the filesByKey ref and its layout effect while keeping the callback stable. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent f71ec89 commit f109eed

2 files changed

Lines changed: 7 additions & 24 deletions

File tree

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ function DiffFileHeaderSuffix({
186186
);
187187
}
188188

189-
/** Line counts for one file header; re-renders only when its own file changes. */
190-
function DiffFileHeaderStat({ additions, deletions }: { additions: number; deletions: number }) {
191-
return <DiffStatLabel additions={additions} deletions={deletions} />;
192-
}
193-
194189
interface DiffPanelProps {
195190
mode?: DiffPanelMode;
196191
composerDraftTarget: ScopedThreadRef | DraftId;
@@ -1175,7 +1170,7 @@ export default function DiffPanel({
11751170
renderHeaderMetadata: (fileDiff: FileDiffMetadata) => {
11761171
const stat = fileStats.get(resolveFileDiffPath(fileDiff));
11771172
return stat ? (
1178-
<DiffFileHeaderStat
1173+
<DiffStatLabel
11791174
additions={stat.additions}
11801175
deletions={stat.deletions}
11811176
/>

‎apps/web/src/components/diffs/AnnotatableCodeView.tsx‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ import type {
88
} from "@pierre/diffs";
99
import type { CodeViewHandle } from "@pierre/diffs/react";
1010
import type { ScopedThreadRef } from "@t3tools/contracts";
11-
import {
12-
useCallback,
13-
useLayoutEffect,
14-
useMemo,
15-
useRef,
16-
useState,
17-
type ReactNode,
18-
type Ref,
19-
} from "react";
11+
import { useCallback, useMemo, useState, type ReactNode, type Ref } from "react";
2012

2113
import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
22-
import { fnv1a32 } from "~/lib/diffRendering";
14+
import { fnv1a32, resolveFileDiffPath } from "~/lib/diffRendering";
2315
import {
2416
buildDiffReviewComment,
2517
restoreDiffReviewCommentRange,
@@ -140,10 +132,6 @@ export function AnnotatableCodeView({
140132
const [draftText, setDraftText] = useState("");
141133

142134
const filesByKey = useMemo(() => new Map(files.map((file) => [file.fileKey, file])), [files]);
143-
const filesByKeyRef = useRef(filesByKey);
144-
useLayoutEffect(() => {
145-
filesByKeyRef.current = filesByKey;
146-
}, [filesByKey]);
147135
const items = useMemo<CodeViewDiffItem<DiffCommentAnnotationGroup>[]>(
148136
() =>
149137
files.map(({ fileDiff, filePath, fileKey, fileVersion, collapsed }) => {
@@ -229,15 +217,15 @@ export function AnnotatableCodeView({
229217
if (!range) return;
230218
const item = context.item;
231219
if (item.type !== "diff") return;
232-
const file = filesByKeyRef.current.get(item.id);
233-
if (!file) return;
220+
// Read from the item, not the file list, so this callback keeps its identity as
221+
// patches arrive; the viewer re-applies its options whenever it changes.
234222
const id = nextFileCommentId();
235223
const comment = buildDiffReviewComment({
236224
id,
237225
sectionId,
238226
sectionTitle,
239-
filePath: file.filePath,
240-
fileDiff: file.fileDiff,
227+
filePath: resolveFileDiffPath(item.fileDiff),
228+
fileDiff: item.fileDiff,
241229
range,
242230
text: "",
243231
});

0 commit comments

Comments
 (0)