fix: stabilize virtualizer getItemKey with ref to prevent row remounts during RSC revalidation

This commit is contained in:
Francisco Ignácio Fontoura Solla 2026-08-06 01:03:33 -03:00
parent 452cb396d9
commit c2229596e4

View file

@ -177,6 +177,8 @@ export const CampaignInfiniteTable = <Row,>({
const extra = appended.pages.flat().filter((row) => !seedKeys.has(rowKey(row)))
return [...rows, ...extra]
}, [rows, appended.pages, rowKey])
const loadedRowsRef = useRef(loadedRows)
loadedRowsRef.current = loadedRows
useEffect(() => {
setScrollElement(rootRef.current?.closest(CAMPAIGN_CONTENT_SCROLL_SELECTOR) ?? null)
@ -259,10 +261,10 @@ export const CampaignInfiniteTable = <Row,>({
overscan: 8,
getItemKey: useCallback(
(index: number) => {
const row = loadedRows[index]
const row = loadedRowsRef.current[index]
return row ? rowKey(row) : `skeleton-${index}`
},
[loadedRows, rowKey],
[rowKey],
),
})