petyosi / react-virtuoso

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

[BUG] Scroll position change when prepending one item of unknown height with increaseViewportBy #947

Open danielsantiago opened 1 year ago

danielsantiago commented 1 year ago

Describe the bug When you are at the top of the list, and you prepend a new item with an unknown height, the list is changing the scroll position.

Reproduction https://codesandbox.io/s/sandpack-project-forked-gzs242?file=/App.js

To Reproduce Steps to reproduce the behavior:

  1. Go to the sandbox
  2. Click 'prepend'

Expected behavior When prepend there should be no automatic scroll changes.

Screenshots https://github.com/petyosi/react-virtuoso/assets/619122/8dfcfe79-7795-41f4-bdf4-cff5ace6d2b2

Desktop (please complete the following information):

Additional context If I remove increaseViewportBy then it works the first time I do prepend, but if I then manually scroll to the top of the list and do prepend again, then it fails even without defining increaseViewportBy.

danielsantiago commented 1 year ago

For reference, I did a hack or workaround adding a ResizeObserver before doing prepend to do the correct scroll top calculation.

https://codesandbox.io/s/sandpack-project-forked-sqjxcj?file=/App.js

petyosi commented 1 year ago

Confirming, the problem is related to increaseViewportBy. This should work, I will look for a fix.

dinhtheloc commented 4 months ago

Has anyone got a solution to this issue?