fix(diff): stop writing the auto-focus context ref during render

React Doctor flagged it in CI: a ref mutated during render can leak from work React discards or
replays. The write was also redundant -- useRef captures the first render's values and the
auto-focus effect runs once per mount, so those are already the values it reads.
This commit is contained in:
Neil
2026-09-12 02:24:42 -07:00
parent a598987a09
commit c6636d00a2
@@ -110,8 +110,10 @@ export function PierreDiffSurface({
)
const containerRef = useRef<HTMLDivElement | null>(null)
const editorRef = useRef<Editor<'file-diff', PierreDiffAnnotationData, undefined> | null>(null)
// Why no reassignment: useRef captures the first render's values and the effect below runs once
// per mount, so those are exactly the values it needs. Writing during render is impure -- React
// can discard a render, and the mutation would leak from UI that never commits.
const autoFocusContextRef = useRef({ worktreeId, activeGroupId })
autoFocusContextRef.current = { worktreeId, activeGroupId }
// Why: Monaco focused the single-file DiffEditor on mount so Cmd+F/F7 worked
// without a click. Combined DiffSectionItem did not — do not steal there.
// Skip when the user already moved to a terminal/input or another tab group;