Skip to content
Source
Sign inSign up
TanStack/virtual

fix(virtual-core): reconcile index scrolls after pending measurements #1294

Mergedminwookshin(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/1294/headmerged by piecyk

Showing 5 changed files with 59 additions and 2 deletions (loading 2).

x
0 of 5 viewed, 5 left
5 additions and 0 deletions.changeset/tidy-scroll-measurements.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/virtual-core': patch
+---
+​
+Keep scrollToIndex reconciliation active until pending ResizeObserver measurements can update its target, including when useAnimationFrameWithResizeObserver is enabled. Respect an external scroll away from a reached target during this settling period.
26 additions and 2 deletionspackages/react-virtual/e2e/app/cached-measurements/main.tsxModified
View file
@@ -1,5 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
+import { flushSync } from 'react-dom'
import { useVirtualizer } from '@tanstack/react-virtual'
​
const items = Array.from({ length: 20 }, (_, i) => ({
@@ -11,14 +12,19 @@
const App = () => {
const parentRef = React.useRef<HTMLDivElement>(null)
const [hidden, setHidden] = React.useState(false)
+ const [expanded, setExpanded] = React.useState(false)
​
const rowVirtualizer = useVirtualizer({
count: items.length,
getScrollElement: () => parentRef.current,
- estimateSize: (i) => items[i].height,