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
flushSync was called from inside a lifecycle method #1094
when i use window virtualization with TanStack/virtual, a warning appears in the console:
Warning: flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task.
The reporter notes that this warning seems to come from a flushSync call that was added in a previous change (PR #608) and asks for recommendations to fix it. They also share a local workaround guarding the callback with a mounted check to avoid the error. closed github issue
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 Alexei Karatai, RaenonX, Jewgienij Moisejew, Glovvie, mrbean27123, Michail Shcherbakov, nikec, Volodymyr Mishyn, jochong, Jason Bratt and 13 more
I tried everything I could think of (queueMicrotask(), requestAnimationFrame(), setTimeout(), useEffect(), scrollend listener, virtualizer isScrolling trigger, rolling back to v3.13.12) and nothing worked. Eventually I decided to try setting virtualizer.isScrolling = false before my update and the error seems to have gone away without any downsides 🤞. However, it's definitely a hack so use it with caution.
Note that I was also able to suppress the errors by setting isScrollingResetDelay: 0 but that could affect the normal operation of the virtualizer so I decided against it. In my particular case the problematic render is being triggered by async code that only runs occassionally when the user scrolls close to the top/bottom of the scroll element so I think the risk of manually reseting isScrolling is low though I'd still prefer an upstream solution.
If anybody else has a better solution please let us know!
@amorey warning itself doesn’t really affect anything in this case.
As commented in #1098 the flushSync is intentionally used to synchronously apply the scroll correction during measurement to limit visible white space while scrolling.
I think we should make this configurable under a flag in @tanstack/react-virtual
Closing this as we now have useFlushSync available in React Virtual, which gives more control over how updates are scheduled and can help reduce the perceived re-render issues during scrolling.
Activity
daniliukmark commentedon Dec 21, 2025
Were you able to fix it?
mrbean27123 commentedon Dec 22, 2025
by rolling back to v3.13.12
daniliukmark commentedon Dec 22, 2025
That worked, thx!
amorey commentedon Dec 22, 2025
I tried everything I could think of (
queueMicrotask(),requestAnimationFrame(),setTimeout(),useEffect(),scrollendlistener, virtualizerisScrollingtrigger, rolling back to v3.13.12) and nothing worked. Eventually I decided to try settingvirtualizer.isScrolling = falsebefore my update and the error seems to have gone away without any downsides 🤞. However, it's definitely a hack so use it with caution.Note that I was also able to suppress the errors by setting
isScrollingResetDelay: 0but that could affect the normal operation of the virtualizer so I decided against it. In my particular case the problematic render is being triggered by async code that only runs occassionally when the user scrolls close to the top/bottom of the scroll element so I think the risk of manually resetingisScrollingis low though I'd still prefer an upstream solution.If anybody else has a better solution please let us know!
chore: add issue reference TanStack#1094
piecyk commentedon Dec 28, 2025
@amorey warning itself doesn’t really affect anything in this case.
As commented in #1098 the flushSync is intentionally used to synchronously apply the scroll correction during measurement to limit visible white space while scrolling.
I think we should make this configurable under a flag in @tanstack/react-virtual
feat: add deferFlushSync option for React 19 compatibility
amorey commentedon Dec 29, 2025
@piecyk Making it configurable sounds great. I'll watch the PR for updates.
piecyk commentedon Mar 10, 2026
Closing this as we now have useFlushSync available in React Virtual, which gives more control over how updates are scheduled and can help reduce the perceived re-render issues during scrolling.
https://tanstack.com/virtual/latest/docs/framework/react/react-virtual#useflushsync
fix(react19): kill the unmount-time removeChild crash at its two real…
feat: 日志统计变换 + README 文档同步 + useFlushSync 修复
Disable virtualizer flushSync to fix React 19 mid-render scroll warning