Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMR (live reload, fast refresh) broke render in React #750

Open
2 tasks done
dartess opened this issue Jul 5, 2024 · 2 comments · May be fixed by #820
Open
2 tasks done

HMR (live reload, fast refresh) broke render in React #750

dartess opened this issue Jul 5, 2024 · 2 comments · May be fixed by #820

Comments

@dartess
Copy link

dartess commented Jul 5, 2024

Describe the bug

After the hot reload, new list items are not rendered

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-virtual-dc5j1h?file=src%2Fmain.tsx,src%2FRowVirtualizerFixed.tsx&preset=node

Steps to reproduce

  1. open repl
  2. edit console.log('foo'); with some different text
  3. press cmd/ctrl+S for save and live reload
  4. scroll list
  5. see that list is empty

Expected behavior

it should just work

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

any platform , any bundler — vite, wepack, rspack

tanstack-virtual version

3.8.1

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.
@dartess dartess changed the title HMR (live reload, fast refresh) broke render HMR (live reload, fast refresh) broke render in React Jul 5, 2024
@mr-devboy
Copy link

Same here

@hophiphip
Copy link

hophiphip commented Aug 29, 2024

TLDR: scrollElement gets cleared in _didMount and that is why virtualizer stops working.

The only methods that can change scrollElement are: _willUpdate and _didMount.

  1. On the initial run _willUpdate and _didMount are called in this order:
    2024-08-29-16:45:41-screenshot

  2. After triggering HMR _willUpdate and _didMount will be called in this order:
    2024-08-29-16:48:18-screenshot

[2] - This means scrollElement gets cleared and set to null which "breaks" the virtualizer.

You can debug this in this CodeSandbox: https://codesandbox.io/p/devbox/4wnzrm
There you can find fixed useVirtualizerBase in src/hooks/useVirtualizerFixed.tsx.

Video how to reproduce the bug:
https://github.com/user-attachments/assets/90b33824-e89f-42f1-a98a-98936d5f1227

See fix in: #820

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants