Skip to content

Commit b504136

Browse files
dastratakosclaude
andcommitted
Address bot review feedback on PR #6
* Match prior overlay measurements by LineRef coordinates instead of object identity, so parents that recreate refs across renders don't flicker the highlight boxes. * Drop the dead isHoveringRef guard from pierre-diff-viewer since the hover utility is disabled. * Default useIsMac SSR snapshot to false to avoid a hydration mismatch on non-Mac systems. * Fix the fixture patch hunk header so its line counts match the body. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2868ba2 commit b504136

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

web/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const SAMPLE_PATCH = `diff --git a/src/greet.ts b/src/greet.ts
1212
index 1111111..2222222 100644
1313
--- a/src/greet.ts
1414
+++ b/src/greet.ts
15-
@@ -1,5 +1,7 @@
15+
@@ -1,3 +1,6 @@
1616
-export function greet(name: string) {
1717
- return "Hello, " + name + "!";
1818
+export function greet(name: string): string {

web/src/components/chapter/hunk-highlight-overlay.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ function measureLineRange(
114114
}
115115

116116
/**
117-
* Matching by ref identity preserves prior measurements when the current
118-
* measurement fails (shadow root missing, line not yet rendered) and avoids
119-
* index-aliasing bugs when the refs array changes between renders.
117+
* Matching by coordinates (not object identity) preserves prior measurements
118+
* even when the parent recreates LineRef objects between renders, while still
119+
* avoiding the index-aliasing bugs you'd get from matching by array position.
120120
*/
121121
function measureAll(
122122
refs: readonly LineRef[],
@@ -130,7 +130,14 @@ function measureAll(
130130
? measureLineRange(shadowRoot, ref, container, containerRect)
131131
: null;
132132
if (measured) return { ref, box: measured };
133-
const prevBox = prev.find((p) => p.ref === ref)?.box ?? null;
133+
const prevBox =
134+
prev.find(
135+
(p) =>
136+
p.ref.filePath === ref.filePath &&
137+
p.ref.side === ref.side &&
138+
p.ref.startLine === ref.startLine &&
139+
p.ref.endLine === ref.endLine,
140+
)?.box ?? null;
134141
return { ref, box: prevBox };
135142
});
136143
}

web/src/components/chapter/pierre-diff-viewer.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,15 @@ export function PierreDiffViewer({
118118

119119
const diffContainerRef = useRef<HTMLDivElement>(null);
120120

121-
const isHoveringRef = useRef(false);
122-
123-
// Suppress onLineSelected during hover — Pierre fires it when the selectedLines
124-
// prop changes, but hover highlights shouldn't trigger any selection logic.
125121
const guardedOnLineSelected = useCallback(
126122
(range: SelectedLineRange | null) => {
127-
if (isHoveringRef.current) return;
128123
if (!range) {
129124
onLineSelected?.(null);
130125
return;
131126
}
127+
// Pierre's drag-to-select emits `{ start: anchor, end: currentLine }`
128+
// without ordering them, so dragging upward produces a range where
129+
// start > end — normalize so downstream consumers see ascending bounds.
132130
const normalized: SelectedLineRange =
133131
range.start <= range.end
134132
? range

web/src/lib/use-is-mac.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getSnapshot() {
1818
}
1919

2020
function getServerSnapshot() {
21-
return true;
21+
return false;
2222
}
2323

2424
export function useIsMac() {

0 commit comments

Comments
 (0)