You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using useWindowVirtualizer along with auto-loading new items once the user reaches the bottom of the page. I do this by comparing if virtualItems[virtualItems.length - 1].index >= nItems - 2 (as you will see in the codesandbox). This works well. However, once I add
and also hide the list div by using display: none, the length of getVirtualItems() for some reason always increases to the total number of items, i.e. count. This causes my auto-load function to load the next items, which then increases the count, which then causes getVirtualItems() length to increase again, causing the auto-load function to run, and so on forever.
It appears that the use of display: none along with measureElement breaks something and causes getVirtualItems() to return the entire (or close to) list of elements in memory, i.e. count.
You will also notice in the codesandbox and video below that after re-showing the list after hiding it, it looks like that when the window is scrolled to the top the length of virtual items skyrockets and stacks most of the items on top of each other in z-axis.
I am not sure if this bug occurs with a non-window virtualizer.
Notice the top-right stats box showing current virtual items count. Everything is fine here and scrolling loads more items.
Click the button to hide the list.
Notice how now the numbers are increasing forever, which in a real setting causes infinite api calls to backend and slows down browser
Expected behavior
Expected that nothing should change when hiding the list, or at least nothing as drastic as this
How often does this bug happen?
Every time
Screenshots or Videos
tanstack-virtual-window-infinite-bug.mp4
Platform
macOS
Chrome 123.0.6312.87
tanstack-virtual version
3.2.0
TypeScript version
5.2.2
Additional context
The example uses vite since it's a fork of the example from this repo, but the issue also occurs when using nextjs too.
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.
The text was updated successfully, but these errors were encountered:
ConnorLanglois
changed the title
useWindowVirtualizer with measureElement and auto-load items causes getVirtualItems length to go to infinity
useWindowVirtualizer with measureElement, hidden list, and auto-load items causes getVirtualItems length to go to infinity
Apr 2, 2024
ConnorLanglois
changed the title
useWindowVirtualizer with measureElement, hidden list, and auto-load items causes getVirtualItems length to go to infinity
useWindowVirtualizer with measureElement, hidden list, and auto-loading items causes getVirtualItems length to go to infinity
Apr 2, 2024
@ConnorLanglois the issue here is that when hiding a list with display none resize observer will kiks in and read the size of elements as 0. There are two solution for it, you can pass custom measureElement that will return prev size when updateSize size false,
Describe the bug
I am using useWindowVirtualizer along with auto-loading new items once the user reaches the bottom of the page. I do this by comparing if
virtualItems[virtualItems.length - 1].index >= nItems - 2
(as you will see in the codesandbox). This works well. However, once I addand also hide the list div by using
display: none
, the length of getVirtualItems() for some reason always increases to the total number of items, i.e.count
. This causes my auto-load function to load the next items, which then increases thecount
, which then causes getVirtualItems() length to increase again, causing the auto-load function to run, and so on forever.It appears that the use of
display: none
along withmeasureElement
breaks something and causesgetVirtualItems()
to return the entire (or close to) list of elements in memory, i.e. count.You will also notice in the codesandbox and video below that after re-showing the list after hiding it, it looks like that when the window is scrolled to the top the length of virtual items skyrockets and stacks most of the items on top of each other in z-axis.
I am not sure if this bug occurs with a non-window virtualizer.
Your minimal, reproducible example
https://codesandbox.io/p/github/ConnorLanglois/tanstack-virtual-window-infinite-bug
Steps to reproduce
Expected behavior
Expected that nothing should change when hiding the list, or at least nothing as drastic as this
How often does this bug happen?
Every time
Screenshots or Videos
tanstack-virtual-window-infinite-bug.mp4
Platform
macOS
Chrome 123.0.6312.87
tanstack-virtual version
3.2.0
TypeScript version
5.2.2
Additional context
The example uses vite since it's a fork of the example from this repo, but the issue also occurs when using nextjs too.
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: