petyosi / react-virtuoso

The most powerful virtual list component for React
https://virtuoso.dev
MIT License
5.25k stars 301 forks source link

[BUG] #816

Closed opsmith96 closed 1 year ago

opsmith96 commented 1 year ago

rangeChanged dont get called when only startIndex is changed. I have a table with different height items and when the bottom item is high and i scroll, the top item can change multiple rows but since bottom row dont change, the rangeChanged dont get called.

I store startIndex in the browser so i can keep scroll position to next time i open the table, when startIndex dont change its off by a bit

Reproduce https://codesandbox.io/s/react-virtuoso-rangechanged-hg6w00?file=/src/App.js

  1. Open link.
  2. Scroll in the table to see in the console that rangeChanged is called.
  3. Click the scroll to 880 button.
  4. Item 910 should be high, keep scrolling downwards in the table to see that rangeChanged dont get called before item 911 appear in the bottom.

Expected behavior Expected rangeChanged to get called even when only startIndex is changed

petyosi commented 1 year ago

This has been discussed before - the virtualization algorithm is "non-greedy" when purging items outside the viewport. The range is recalculated only when the existing items are no longer filling in the viewport. If you open the console, you will notice that the top items (880) are still in the DOM.

Up to your case, you can listen to the onScroll event for that purpose.

opsmith96 commented 1 year ago

ok, but I dont understand how onScroll is gonna help me get the index of the top visible element in the table in this position: image