From c6636d00a2be67613516b2cd52b4fcecb9e22344 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 12 Sep 2026 02:24:42 -0700 Subject: [PATCH] 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. --- .../src/components/editor/pierre-diff/PierreDiffSurface.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/editor/pierre-diff/PierreDiffSurface.tsx b/src/renderer/src/components/editor/pierre-diff/PierreDiffSurface.tsx index adf7c00123b..b1efcbf7285 100644 --- a/src/renderer/src/components/editor/pierre-diff/PierreDiffSurface.tsx +++ b/src/renderer/src/components/editor/pierre-diff/PierreDiffSurface.tsx @@ -110,8 +110,10 @@ export function PierreDiffSurface({ ) const containerRef = useRef(null) const editorRef = useRef | 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;