fix: Message list scroll position lost after switching channels and returning

Merged
DO
2mo ago
+118-2

Proposed changes (including videos or screenshots)

RoomBody initialized isAtBottom to a hardcoded true, so a room always started out believing it was pinned to the bottom β€” even when reopening one the user had left scrolled mid-history.

That matters because useKeepAtBottom observes the message list with a ResizeObserver and scrolls to the end on every resize while isAtBottom.current is true. Message rows resize repeatedly as they are measured after the list remounts, so the restored mid-history position was dragged down to the latest messages.

isAtBottom is now seeded from the atBottom value already persisted per room in RoomManager's store, falling back to true when there is no store yet (first visit).

Issue(s)

Steps to test or reproduce

  1. Open a channel with 100+ messages and scroll up so mid-history is in view.
  2. Switch to another channel, then return.
  3. The viewport should stay in the same region instead of sliding to the latest messages.

Note: with more than 5 rooms open, closeOlderRooms() evicts the room's stored position and messages, which masks the behavior β€” test with a small number of open rooms.

Further comments

SUP-1098

Summary by CodeRabbit

  • Bug Fixes

    • Improved message-list position restoration when returning to a channel.
    • Preserved the previous scroll position for channels left mid-history.
    • Continued scrolling to the latest messages for channels previously left at the bottom.
  • Tests

    • Added coverage for repeated list resizing and scroll-position restoration scenarios.