Skip to content

flushSync was called from inside a lifecycle method #1094

@hossein197176

Description

@hossein197176

Describe the bug

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

also we could see the error message in the official document example with the latest version when we reach the end of the scrollable element:
https://tanstack.com/virtual/latest/docs/framework/react/examples/infinite-scroll

Your minimal, reproducible example

https://tanstack.com/virtual/latest/docs/framework/react/examples/infinite-scroll

Steps to reproduce

Run the official document example

Expected behavior

we should not see the mentioned warning

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

windows 11 - chrome

tanstack-virtual version

v3.13.13

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions