Description
Component
Virtualizer (Preview)
Package version
9.64.0
React version
18.3.1
Environment
any
Current Behavior
I'm leveraging Virtualizer to render a set of rows that can be added or removed. If the user is scrolled to the bottom of the list, and they start removing the last rows in the list, the virtualizer stops filling in the new (previous) rows which should start coming into the top of the viewport. The user can remove all the visible rows, then be left with a completely empty viewport. Even scrolling up/down at that point just shows an empty/blank content rather than showing the remaining rows.
Expected Behavior
When rows are needed at the top of the viewport, due to rows being removed from the bottom, they should be rendered.
The issue is due to this line:
useVirtualizer.ts#L411
That block is there for a performance optimization, preventing re-rerenders if the user is already at the end of the list -- assuming that means it doesn't need to redraw anything above it. However, it doesn't consider this scenario, where the number of rows is changing between renders.
If I add:
newStartIndex === actualIndex &&
to the start of that if condition, it fixes the issue. I have patched our repo's react-virtualizer package with this (pnpm patch) for now.
Reproduction
https://stackblitz.com/edit/gfsqkbfr?file=src%2Fexample.tsx
Steps to reproduce
- Scroll down to the bottom of the list
- Click the Remove button on the last row (Node 99)
- Repeat step 2 about 10 times (Node 98...90)
You'll be left with only a couple of rows (or no rows if you delete them all). They don't even recover after scrolling up/down.
Are you reporting an Accessibility issue?
None
Suggested severity
High - No workaround
Products/sites affected
Azure portal
Are you willing to submit a PR to fix?
yes
Validations
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.