petyosi / react-virtuoso

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

[BUG] - Possible bug with GroupedVirtuoso initialTopMostItemIndex and resizing items #1069

Closed emfmesquita closed 4 months ago

emfmesquita commented 4 months ago

Describe the bug Using GroupedVirtuoso with initialTopMostItemIndex (or scrollToIndex) to an item that is not the first of the group and the items change size (like loading server side data) causes the intended top item to shift position.

Reproduction sandbox

To Reproduce Steps to reproduce the behaviour:

  1. Go the the link above.
  2. Wait a second for the items to load.
  3. Observe the item 40003 shift position.
  4. Since the heights are random a reload might be necessary.

Expected behavior The item 40003 should be at the top even after the content load.

Screenshots image

Desktop (please complete the following information):

Additional context My guess is that when an item is at the top and it is not the first of the group the previous item is actually hidden behind the group at the top. And probably being mistaken for the top item, then when it resizes it moves the intended top item.

petyosi commented 4 months ago

This is not a bug. You need to re-design your data loading strategy.