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
{{ message }}
Repository navigation
React Compiler: useVirtual results are cached at their initial values #736
Since the virtualizer ref never changes, the virtual items never get updated.
Not sure if this should be a Tanstack Virtual issue or React Compiler needs to apply less assumptions when caching values, but thought that would be good to flag the problem here.
Wrapping useVirtual into something like this fixes the issue:
constuseVirtualWrapper=(...args)=>{'use no memo';return{ ...useVirtual(...args)};}
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.
changed the title [-]React Compiler Compat: useVirtual results are cached at their initial values[/-][+]React Compiler: useVirtual results are cached at their initial values[/+]on May 23, 2024
got same problem, very annoying when using react-compiler. My workaround was to save an instance of virtualizer as state when the onChange function is saved, and use that instance in my component instead of the instance returned by the hook.
Here's a solution that works with TS and pretty strict eslint rules (e.g. where spreading classes is forbidden)
constuseVirtual=(options: Parameters<typeofuseVirtualizer>[0])=>{'use no memo';const{ getVirtualItems, getTotalSize }=useVirtualizer(options);return{virtualItems: getVirtualItems(),totalSize: getTotalSize(),/*...and whatever else you need*/};};
But I'd also like to understand how the virtualizer triggers a rerender in the first place if its reference remains stable (which it seems to be according to the compiler output). How does React notice a change if you need to call getVirtualItems during a render to get new items?
The issue could be fixed by returning 'reactive' things directly as new references instead of returning a function to call, e.g returning virtualItems as an array instead of getVirtualItems as a function. This way the virtualizer can remain stable and you can opt into each feature that should rerender your component by simply destructuring what you need.
any news on actually fixing the issue? "use no memo" directive is just a workaround and the related PR seems to have been closed almost a year ago #851
Reacted by Szymon Dolnik, hexcowboy, Wayne Brantley, anton-raxalle, Dániel Gergely and Raj Siva-Rajah
Btw, @eikowagenknecht, I’d also add overflow-anchor: none to the scrolling container. Sometimes the browser’s scroll anchoring conflicts with virtualization, so it’s better to disable automatic scroll adjustment.
Activity
[-]React Compiler Compat: useVirtual results are cached at their initial values[/-][+]React Compiler: useVirtual results are cached at their initial values[/+]relsunkaev commentedon Jun 15, 2024
Similar thing happens if the component is wrapped in
memo. @tannerlinsley this error only shows up with strict mode off (i.e. in production).relsunkaev commentedon Jun 15, 2024
Specifying
initialRectmade it work for menicolo-danzi-ok commentedon Jul 31, 2024
got same problem, very annoying when using react-compiler. My workaround was to save an instance of virtualizer as state when the onChange function is saved, and use that instance in my component instead of the instance returned by the hook.
any official solution or hint?
piecyk commentedon Dec 12, 2024
'use no memo' seems like a reasonable temporary workaround! https://react.dev/learn/react-compiler#something-is-not-working-after-compilation
Grawl commentedon Dec 19, 2024
Can you show how exactly did you get it?
GrahamQuan commentedon Mar 9, 2025
this works for me
PaloSP commentedon Jul 10, 2025
Any news?
lgrones commentedon Jul 12, 2025
Here's a solution that works with TS and pretty strict eslint rules (e.g. where spreading classes is forbidden)
But I'd also like to understand how the virtualizer triggers a rerender in the first place if its reference remains stable (which it seems to be according to the compiler output). How does React notice a change if you need to call
getVirtualItemsduring a render to get new items?The issue could be fixed by returning 'reactive' things directly as new references instead of returning a function to call, e.g returning
virtualItemsas an array instead ofgetVirtualItemsas a function. This way the virtualizer can remain stable and you can opt into each feature that should rerender your component by simply destructuring what you need.Something like this
[compiler]: add `@tanstack/react-virtual` to known incompatible libra…
[compiler]: add `@tanstack/react-virtual` to known incompatible libra…
[compiler]: add `@tanstack/react-virtual` to known incompatible libra…
ivan-palatov commentedon Jan 14, 2026
any news on actually fixing the issue? "use no memo" directive is just a workaround and the related PR seems to have been closed almost a year ago #851
Add handling for compatibility of @tanstack/react-virtual with react …
Add handling for compatibility of @tanstack/react-virtual with react …
10 remaining items
piecyk commentedon Jun 8, 2026
Btw, @eikowagenknecht, I’d also add overflow-anchor: none to the scrolling container. Sometimes the browser’s scroll anchoring conflicts with virtualization, so it’s better to disable automatic scroll adjustment.
refactor(web): drop CardGrid scrollToGroup lazy-init ref
fix(web): stop admin cards search from freezing the browser on every …
fix(web): stop ~5Hz admin cards idle render loop and typing freeze
refactor(web): stop hiding TanStack hooks from react-compiler
refactor(web): adopt TanStack Virtual directDomUpdates, retire the wr…
fix(web): disable browser scroll anchoring on the window scroll root
[compiler]: add `useWindowVirtualizer` to known incompatible libraries (
[compiler]: add `useWindowVirtualizer` to known incompatible libraries (
[compiler]: add `useWindowVirtualizer` to known incompatible libraries (
[compiler]: add `useWindowVirtualizer` to known incompatible libraries (
[compiler]: add `useWindowVirtualizer` to known incompatible libraries (
feat(react-virtual): add useVirtualizerSnapshot for React Compiler co…