mirror of
https://github.com/fsolla/teqo.git
synced 2026-12-01 03:53:05 +00:00
fix: stabilize virtualizer getItemKey with ref to prevent row remounts during RSC revalidation
This commit is contained in:
parent
452cb396d9
commit
c2229596e4
1 changed files with 4 additions and 2 deletions
|
|
@ -177,6 +177,8 @@ export const CampaignInfiniteTable = <Row,>({
|
||||||
const extra = appended.pages.flat().filter((row) => !seedKeys.has(rowKey(row)))
|
const extra = appended.pages.flat().filter((row) => !seedKeys.has(rowKey(row)))
|
||||||
return [...rows, ...extra]
|
return [...rows, ...extra]
|
||||||
}, [rows, appended.pages, rowKey])
|
}, [rows, appended.pages, rowKey])
|
||||||
|
const loadedRowsRef = useRef(loadedRows)
|
||||||
|
loadedRowsRef.current = loadedRows
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setScrollElement(rootRef.current?.closest(CAMPAIGN_CONTENT_SCROLL_SELECTOR) ?? null)
|
setScrollElement(rootRef.current?.closest(CAMPAIGN_CONTENT_SCROLL_SELECTOR) ?? null)
|
||||||
|
|
@ -259,10 +261,10 @@ export const CampaignInfiniteTable = <Row,>({
|
||||||
overscan: 8,
|
overscan: 8,
|
||||||
getItemKey: useCallback(
|
getItemKey: useCallback(
|
||||||
(index: number) => {
|
(index: number) => {
|
||||||
const row = loadedRows[index]
|
const row = loadedRowsRef.current[index]
|
||||||
return row ? rowKey(row) : `skeleton-${index}`
|
return row ? rowKey(row) : `skeleton-${index}`
|
||||||
},
|
},
|
||||||
[loadedRows, rowKey],
|
[rowKey],
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue