regression: restore scroll position on channel change

Merged
RI
5mo ago
+6-12

Proposed changes (including videos or screenshots)

Switching between channels was not restoring the previously scrolled position - the list re-opened either at the bottom or in an inconsistent place - because MessageList's init effect was relying on a two-step findItemIndex + scrollToIndex restore, which is unreliable against a freshly-mounted virtualizer whose row cache is still being populated. It also let handlePrepend run before initialization finished, which could corrupt the saved offset.

This PR replaces the brittle two-step restore with a single scrollTo(store.scroll) against the saved offset, and short-circuits handlePrepend until isRoomInitialized is true.

Depends on https://github.com/RocketChat/Rocket.Chat/pull/40757.

Issue(s)

  • CORE-2271 - Switching channels does not restore scroll position sometimes

Steps to test or reproduce

In a channel with enough messages to scroll:

  1. Open the channel, scroll to the middle, note a visible message.
  2. Switch to another channel via the sidebar.
  3. Switch back to the original channel -> the previously visible message is restored at the top of the viewport (instead of the list re-opening at the bottom).

Further comments