From d65921c13b17c53df9dc1f0a2c065607c8ecc797 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Tue, 4 Aug 2026 21:13:28 -0700 Subject: [PATCH] fix(diff): keep renderedIndicesRef pure during render React Doctor blocks ref mutation during render; sync the on-screen section set in a layout effect instead so static analysis can pass. --- src/renderer/src/components/editor/CombinedDiffViewer.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/editor/CombinedDiffViewer.tsx b/src/renderer/src/components/editor/CombinedDiffViewer.tsx index dfb01be99f1..794808d09dd 100644 --- a/src/renderer/src/components/editor/CombinedDiffViewer.tsx +++ b/src/renderer/src/components/editor/CombinedDiffViewer.tsx @@ -902,8 +902,10 @@ export default function CombinedDiffViewer({ }) const combinedDiffTotalSize = virtualizer.getTotalSize() const combinedDiffVirtualItems = virtualizer.getVirtualItems() - // Why: retrySection needs the on-screen set without taking the virtualizer as a dep. - renderedIndicesRef.current = new Set(combinedDiffVirtualItems.map((item) => item.index)) + // Why: keep render pure (React Doctor); retrySection still needs the on-screen set without the virtualizer as a dep. + useLayoutEffect(() => { + renderedIndicesRef.current = new Set(combinedDiffVirtualItems.map((item) => item.index)) + }, [combinedDiffVirtualItems]) const getCombinedDiffSectionKey = useCallback((section: DiffSection): string => section.key, []) const getCombinedDiffSectionElementKey = useCallback( (element: Element): string | null =>