virtual icon indicating copy to clipboard operation
virtual copied to clipboard

Dynamically updating count seems to not trigger an update

Open wuarmin opened this issue 2 years ago • 1 comments

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.

wuarmin avatar Aug 03 '22 09:08 wuarmin

Same error here

himself65 avatar Aug 04 '22 03:08 himself65

@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?

wuarmin avatar Aug 11 '22 13:08 wuarmin

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 :)

christiankaindl avatar Aug 11 '22 17:08 christiankaindl

@wuarmin I think this PR should fix your issue -> #366

christiankaindl avatar Aug 11 '22 17:08 christiankaindl

I don't know if that's intentional, but the PR in #366 was not merged yet

christiankaindl avatar Aug 12 '22 15:08 christiankaindl

Hi, any updates for this issue? :( I really don't like that we have to use a workaround.

SvetaSR avatar Oct 21 '22 12:10 SvetaSR

any update of this issue?

coycoylaniba avatar Dec 03 '23 18:12 coycoylaniba