perf(timeline): restore VList cache + skip 80 ms timer on room revisit#659
Open
Just-Insane wants to merge 6 commits intoSableClient:devfrom
Open
perf(timeline): restore VList cache + skip 80 ms timer on room revisit#659Just-Insane wants to merge 6 commits intoSableClient:devfrom
Just-Insane wants to merge 6 commits intoSableClient:devfrom
Conversation
When navigating back to a previously-visited room, save the VList
CacheSnapshot (item heights) and scroll offset on the way out, then
on the way back:
• pass the snapshot as cache= to VList so item heights do not need
to be remeasured (VList is keyed by room.roomId so it gets a fresh
instance with the saved measurements)
• skip the 80 ms stabilisation timer — the measurements are already
known, so the scroll lands immediately and setIsReady(true) is
called without the artificial delay
First-visit rooms retain the existing 80 ms behaviour unchanged.
RoomTimeline mounts fresh per room (key={roomId} in RoomView), so the
render-phase room-change block used for save/load never fires.
- Init scrollCacheForRoomRef from roomScrollCache.load() on mount so the
CacheSnapshot is actually provided to VList on first render.
- Save the cache in handleVListScroll (and after the first-visit 80 ms
timer) rather than in the unreachable room-change block.
- Trim the room-change block to just the load + state-reset path (kept as
a defensive fallback for any future scenario where room prop changes
without remount).
Contributor
Author
|
Added a follow-up fix in the latest commit: |
…mmatic scroll-to-bottom After setIsReady(true) commits, virtua can fire onScroll events with isNowAtBottom=false during its height-correction pass (particularly on first visit when item heights above the viewport haven't been rendered yet). These intermediate events were driving atBottomState to false while isReady=true, flashing the 'Jump to Latest' button. Add programmaticScrollToBottomRef: set it before each scrollToIndex bottom-scroll, suppress the first intermediate false event (clearing the guard immediately), so the next event — the corrected position or a real user scroll — is processed normally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Caches VList item heights (via
roomScrollCache) across visits to the same room within a session. On revisit, the stored cache is provided to VList upfront and the scroll position is restored immediately — skipping the 80 ms opacity-fade stabilisation timer entirely.Also fixes a bug where the
pendingReadyRefrecovery path (triggered when the 80 ms timer fires whileprocessedEventsis empty due to aTimelineResetrace) never saved the scroll cache, causing rooms that hit this path to show the fade-in on subsequent visits.Fixes #
Type of change
Checklist:
AI disclosure:
roomScrollCache.ts— a simple session-scopedMap<roomId, { cache, scrollOffset, atBottom }>.cacheis VList'sCacheSnapshot(measured item heights),scrollOffsetis the pixel offset at save time, andatBottomis a flag used to decide whether to callscrollToIndex(bottom) orscrollTo(exact offset) on restore.In
RoomTimeline.tsx, the initial-scrolluseLayoutEffectwas extended to check for a saved cache before starting the 80 ms timer: if a cache exists, it restores position immediately and callssetIsReady(true)without the delay. The 80 ms timer path and thependingReadyRefrecovery path both now callroomScrollCache.save(...)after scrolling so subsequent visits have a cache to load.