You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and virtualizerRef.getVirtualItems() was being hoisted / memo'd by the compiler in such a way that it was always returning 0 for getVirutalItems.
To fix it we just dropped the virtualizer in a ref…
constvirtualizer=useWindowVirtualizer({count: branches.length,estimateSize: ()=>66,overscan: 5,scrollMargin: listRef.current?.offsetTop??0,});// we do this because react 19 was optimzing it awayconstvirtualizerRef=useRef(virtualizer);…virtualizerRef.current.getVirtualItems()// etc…
Your minimal, reproducible example
n/a
Steps to reproduce
Don't have time to spin up a test case sorry!
Expected behavior
Expected getVirtualItems() to return items.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
macos, chrome, react 19
tanstack-virtual version
3.7.0
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct
I agree to follow this project's Code of Conduct
I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Reacted by Jan Vollmer, dfoley112, BestCodes, Thinh Ngo, Kyle June, Dương Tiến Vinh, Allan Kimmer Jensen, Antonín Kříž, Lorenzo Pieri, Jeremiah and 1 more
const useNoMemo = (factory: () => T): T => {
'use no memo';
return factory();
}
which I then use like this:
const virtualItems = useNoMemo(() => virtualizer.getVirtualItems());
This de-opts just the call to virtualizer.getVirtualItems without de-opting the rest of the component.
This has been addressed with the directDomUpdates option. When enabled, the virtualizer writes item positions and container sizes directly to the DOM, bypassing React's render cycle for scroll-driven updates. This makes the React Compiler's memoization of getVirtualItems() harmless, since position updates no longer depend on React re-renders.
Activity
Prains commentedon Jul 3, 2024
same issue here, but droppind a virtualizer in a ref does not helps
izakfilmalter commentedon Jul 3, 2024
Running into the same issue.
useRefseems to work for now for us.simonrey1 commentedon Nov 14, 2024
It gives me an issue with eslint however.
Edit: it might be removed in a PR
https://github.com/facebook/react/pull/30843/files
cacabo commentedon Dec 11, 2024
+1, I am seeing this with:
{ "@tanstack/react-virtual": "^3.11.1", "react": "^18.3.1", "react-compiler-runtime": "^19.0.0-beta-63b359f-20241101", "react-dom": "^18.3.1", }Putting a hook in the component after
.getVirtualItemsappears to be another workaroundAnother option is "use no memo"
https://react.dev/learn/react-compiler#something-is-not-working-after-compilation
piecyk commentedon Dec 12, 2024
Yep, 'use no memo' seems like a reasonable temporary workaround! 👍
🪛(fix): react compiler bug in react-table
zeorin commentedon May 20, 2025
I work around this with the following hook:
which I then use like this:
This de-opts just the call to
virtualizer.getVirtualItemswithout de-opting the rest of the component.See react/react#33057 (comment)
🪛(fix): react compiler bug in react-table
fix: React 19 virtualizer optimization workaround
fix: React 19 virtualizer optimization workaround (#434)
fix: completely disable virtualization to fix React errors #418/#185
fix: completely disable virtualization to fix React errors #418/#185 (#…
kaushal-dhrangad-techno commentedon May 28, 2026
+1 works for me :-) thanks!
zeorin commentedon May 30, 2026
I've published a compiler-compatible package that is a near drop-in replacement for
@tanstack/react-virtual: react-hook-tanstack-virtual.piecyk commentedon Jun 2, 2026
This has been addressed with the
directDomUpdatesoption. When enabled, the virtualizer writes item positions and container sizes directly to the DOM, bypassing React's render cycle for scroll-driven updates. This makes the React Compiler's memoization ofgetVirtualItems()harmless, since position updates no longer depend on React re-renders.The feature is covered by dedicated e2e tests that build with
babel-plugin-react-compilerand verify scrolling works correctly.Closing as resolved. If you're not using
directDomUpdates, the"use no memo"workaround mentioned above remains a valid alternative.adi-works commentedon Jul 19, 2026
@piecyk Slick, but it didn't work for me. However, the
useNoMemoworkaround did work.feat(react-virtual): add useVirtualizerSnapshot for React Compiler co…
Scope the React compiler opt-out to the row virtualizer