React: Conditionally rendering causes scroll element to scroll to top
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 466
- Avg merge
- 2d 31m
- Merged PRs (30d)
- 13
Description
Describe the bug
When a 2nd conditionally rendered virtual list is rendered, the page automatically scrolls to the top
Your minimal, reproducible example
https://codesandbox.io/p/devbox/cranky-fermat-vzkmd3
Steps to reproduce
Scroll to bottom and click the Render More button. Once clicked the 2nd virtualized list will render and the page will scroll to the top
Expected behavior
When the 2nd virtualized list is rendered, the page should not scroll to the top.
How often does this bug happen?
Every time
Screenshots or Videos
https://github.com/user-attachments/assets/4309df5d-4e1c-4900-bf5a-aced7b66757a
Platform
- OS: macOS
- Browser: Chrome 137
tanstack-virtual version
3.13.12
TypeScript version
5.8.3
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction and inspect how the second virtualized list is rendered after clicking “Render More.” Compare the page scroll position before and after that render in the reported environment. Done means the second list renders without moving the page to the top, while the existing reproduction behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100