virtual
virtual copied to clipboard
Dynamically updating count seems to not trigger an update
Describe the bug
When dataCount
changes from 0 to 1000, the list is not updated.
const rowVirtualizer = useVirtualizer({
count: dataCount,
getScrollElement: () => tableContainer.current,
estimateSize: () => 21,
overscan: 5
});
Your minimal, reproducible example
https://codesandbox.io/s/react-virtual-only-one-item-is-rendered-at-first-bfoj5r?file=/src/main.tsx
Steps to reproduce
Checkout following sandbox:
https://codesandbox.io/s/react-virtual-only-one-item-is-rendered-at-first-bfoj5r?file=/src/main.tsx
At first glance only one row will be visible. This is because on first render dataCount
is 0, but then it changes to 1000, but the list is not updated.
Expected behavior
All items, which fit in the tableContainer
, should be rendered.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
-OS Linux Ubuntu Browser: Firefox 103.0b9 (64-bit)
tanstack-virtual version
3.0.0-beta.14
TypeScript version
No response
Additional context
#353
Terms & Code of Conduct
- [X] I agree to follow this project's Code of Conduct
- [X] 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.
Same error here
@christiankaindl Do you have a hint about the correct way to fix this?
count
is updated via https://github.com/TanStack/virtual/blob/f4698d85f33b4a62ca949c0c2dfa0c05c8ed0f4a/packages/react-virtual/src/index.tsx#L37
Where should we trigger the update?
Yes, you need to re-calculate the virtual item range in setOptions()
, which is defined here:
https://github.com/TanStack/virtual/blob/f4698d85f33b4a62ca949c0c2dfa0c05c8ed0f4a/packages/virtual-core/src/index.ts#L286
So call this.calculateRange()
at the end of setOptions()
. Tested this locally and it seems to work nicely, will open a PR shortly :)
@wuarmin I think this PR should fix your issue -> #366
I don't know if that's intentional, but the PR in #366 was not merged yet
Hi, any updates for this issue? :( I really don't like that we have to use a workaround.
any update of this issue?