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.
This commit is contained in:
Jinjing
2026-08-04 21:13:28 -07:00
parent 034fa50970
commit d65921c13b
@@ -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 =>