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

Dynamically updating count seems to not trigger an update #363

Closed
2 tasks done
wuarmin opened this issue Aug 3, 2022 · 7 comments · Fixed by #414
Closed
2 tasks done

Dynamically updating count seems to not trigger an update #363

wuarmin opened this issue Aug 3, 2022 · 7 comments · Fixed by #414

Comments

@wuarmin
Copy link

wuarmin commented Aug 3, 2022

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

  • 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.
@himself65
Copy link

Same error here

@wuarmin
Copy link
Author

wuarmin commented Aug 11, 2022

@christiankaindl Do you have a hint about the correct way to fix this?
count is updated via

instance.setOptions(resolvedOptions)

Where should we trigger the update?

@christiankaindl
Copy link
Contributor

Yes, you need to re-calculate the virtual item range in setOptions(), which is defined here:

setOptions = (opts: VirtualizerOptions<TScrollElement, TItemElement>) => {

So call this.calculateRange() at the end of setOptions(). Tested this locally and it seems to work nicely, will open a PR shortly :)

@christiankaindl
Copy link
Contributor

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

@christiankaindl
Copy link
Contributor

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

@SvetaSR
Copy link

SvetaSR commented Oct 21, 2022

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

kuanoni added a commit to kuanoni/react-security-badging-system that referenced this issue Nov 4, 2022
@coycoylaniba
Copy link

any update of this issue?

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