petyosi / react-virtuoso

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

[BUG] restoreStateFrom not always restoring correctly #951

Closed matthewwo closed 1 year ago

matthewwo commented 1 year ago

Describe the bug The restoreStateFrom property doesn't always restore the scroll position correctly despite the data hasn't changed.

I followed the example in (https://github.com/petyosi/react-virtuoso/blob/master/examples/state.tsx), and created a CodeSandbox example to test it out. When I repeatedly click on the Log State, the list sometimes fails to restore the state and goes back to the start of the list.

Reproduction CodeSandbox

To Reproduce

  1. Scroll down in the list to an item (e.g. Item 28)
  2. Click on the Log State button multiple times

Expected behavior The list should remain the same scroll position after each click of the Log State button, but instead sometimes it fails to restore the scroll position and resets the scroll position to the top of the list.

Screenshots CleanShot 2023-07-19 at 16 49 02

Desktop (please complete the following information):

Additional context I believe the same issue also affects the chat example where repeatedly switching between chat-rooms will lose the scroll position at some point.

petyosi commented 1 year ago

Confirming - I managed to reproduce it on my side, though it took me a while. Thank you for the sandbox.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.4.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: