fix(timeline): scroll stay-at-bottom, Jump to Latest button, and phantom unread regressions#688
fix(timeline): scroll stay-at-bottom, Jump to Latest button, and phantom unread regressions#688Just-Insane wants to merge 11 commits intoSableClient:devfrom
Conversation
- room.ts: exclude own events from unread notification check - RoomTimeline.tsx: recovery effect reveals timeline when event load fails
…t When sliding sync upgrades a room subscription (timeline_limit 1 → 50), a TimelineReset replaces the VList content. The auto-scroll recovery was using useEffect, which fires after paint — causing a visible flash where the user sees content at the wrong scroll position for one frame. Switch to useLayoutEffect so the scroll position is corrected before the browser paints. Also remove the redundant scrollToBottom call from the useLiveTimelineRefresh callback, which was operating on the pre-commit DOM with a stale scrollSize.
…ure scroll
scrollToBottom used scrollTo(scrollSize) which reads a stale pixel offset
before VList has measured newly-arrived items. Switch to
scrollToIndex(lastIndex, { align: 'end' }) which works reliably regardless
of measurement state.
Remove the premature scrollToBottom call from useLiveEventArrive — it fired
before React committed the new timeline state, so scrollSize was stale and
the auto-scroll useLayoutEffect was suppressed by lastScrolledAtEventsLengthRef.
The useLayoutEffect now handles all stay-at-bottom scrolling after commit.
…us Jump to Latest button Replace the boolean programmaticScrollToBottomRef guard with a timestamp (Date.now()) and a 200 ms settling window (SCROLL_SETTLE_MS). VList (virtua) fires multiple intermediate onScroll events while re-measuring item heights after a programmatic scrollToIndex(); the old boolean guard was cleared on the first isNowAtBottom=true callback, leaving subsequent re-measurement callbacks free to set atBottom=false and flash the button. The timestamp approach lets the settling window expire naturally — no manual clearing is needed — and correctly suppresses false-negative reports for the entire measurement pass. Also update the useTimelineSync test to push a new event before emitting TimelineReset so the useLayoutEffect auto-scroll recovery (which depends on eventsLength changing) actually fires.
There was a problem hiding this comment.
Pull request overview
Fixes several VList-based timeline regressions related to unread indicators, initial/auto scrolling, and “Jump to Latest” UI stability—especially around TimelineReset and sliding-sync timeline_limit upgrades.
Changes:
- Prevent “phantom unread” by excluding self-sent notification events from unread detection.
- Move auto-scroll recovery after timeline resets to
useLayoutEffectand remove a premature pre-commit scroll. - Replace bottom-pinning scroll logic with
scrollToIndex(..., { align: 'end' })and add a timestamp-based settling window to suppress transient “not at bottom” scroll callbacks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/app/utils/room.ts |
Adjusts unread detection to ignore self-sent notification events. |
src/app/hooks/timeline/useTimelineSync.ts |
Uses useLayoutEffect for post-reset scroll recovery; removes racing scroll call. |
src/app/hooks/timeline/useTimelineSync.test.tsx |
Updates TimelineReset anchoring test to better simulate real reset behavior. |
src/app/features/room/RoomTimeline.tsx |
Switches to scrollToIndex bottom pinning and adds timestamp-based settling guard + fallback “blank page” recovery effect. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Guard against VList's intermediate height-correction scroll events that | ||
| // would otherwise call setAtBottom(false) before the scroll settles. | ||
| programmaticScrollToBottomRef.current = Date.now(); | ||
| vListRef.current.scrollToIndex(lastIndex, { align: 'end' }); | ||
| }, []); |
There was a problem hiding this comment.
The settling-window guard relies on programmaticScrollToBottomRef being updated before every programmatic scrollToIndex(..., { align: 'end' }) that is intended to keep the user pinned to the bottom. In this file there are still end-aligned scrollToIndex calls (e.g. in the top-spacer recalculation rAF and the post-pagination "wasAtBottom" branch) that do not set the timestamp, so the "Jump to Latest" button can still flash during Virtua re-measurement for those cases. Consider centralizing a helper (e.g. scrollToBottomWithSettle()) and using it for all bottom-pinning scrolls.
| if (eventId && !isReady && timelineSync.liveTimelineLinked && timelineSync.eventsLength > 0) { | ||
| scrollToBottom(); | ||
| setIsReady(true); | ||
| } | ||
| }, [ | ||
| eventId, | ||
| isReady, |
There was a problem hiding this comment.
This recovery effect can also run on a successful eventId load: liveTimelineLinked/eventsLength>0 can become true before the setIsReady(true) scheduled by the focusItem effects is committed, and then this effect will call scrollToBottom() and potentially override the intended scroll-to-event behavior. To avoid fighting the normal jump-to-event flow, gate this effect on an explicit failure signal (e.g. !timelineSync.focusItem) or a dedicated "load failed" flag from useTimelineSync.
| if (eventId && !isReady && timelineSync.liveTimelineLinked && timelineSync.eventsLength > 0) { | |
| scrollToBottom(); | |
| setIsReady(true); | |
| } | |
| }, [ | |
| eventId, | |
| isReady, | |
| if ( | |
| eventId && | |
| !isReady && | |
| !timelineSync.focusItem && | |
| timelineSync.liveTimelineLinked && | |
| timelineSync.eventsLength > 0 | |
| ) { | |
| scrollToBottom(); | |
| setIsReady(true); | |
| } | |
| }, [ | |
| eventId, | |
| isReady, | |
| timelineSync.focusItem, |
Accept optional 'instant' | 'smooth' behavior parameter and pass it
through to scrollToIndex. useTimelineSync calls scrollToBottom('instant')
so the signature needs to match.
…nning scrolls Resolves flash of the 'Jump to Latest' button during VList re-measurement when (a) the top-spacer collapses after backward-pagination fills the view and (b) backward pagination completes while the user was already at the bottom. Also prevents the recovery effect from calling scrollToBottom() and overriding a successful scroll-to-event by gating on focusItem. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…croll, fix eventId drag-to-bottom, increase list timeline limit - useTimelineSync: change auto-scroll recovery useEffect → useLayoutEffect to prevent one-frame flash after timeline reset - useTimelineSync: remove premature scrollToBottom from useLiveTimelineRefresh (operated on pre-commit DOM with stale scrollSize) - useTimelineSync: remove scrollToBottom + eventsLengthRef suppression from useLiveEventArrive; let useLayoutEffect handle scroll after React commits - RoomTimeline: init atBottomState to false when eventId is set, and reset it in the eventId useEffect, so auto-scroll doesn't drag to bottom on bookmark nav - RoomTimeline: change instant scrollToBottom to use scrollToIndex instead of scrollTo(scrollSize) — works correctly regardless of VList measurement state - slidingSync: increase DEFAULT_LIST_TIMELINE_LIMIT 1→3 to reduce empty previews when recent events are reactions/edits/state Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore scrollToBottom call in useLiveEventArrive with instant/smooth based on sender, add back eventsLengthRef and lastScrolledAt suppression, restore scrollToBottom in useLiveTimelineRefresh when wasAtBottom, and revert instant scrollToBottom to scrollTo(scrollSize) matching upstream. The previous changes removed all scroll calls from event arrival handlers and relied solely on the useLayoutEffect auto-scroll recovery, which has timing issues with VList measurement. Upstream's pattern of scrolling in the event handler and suppressing the effect works reliably. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove behavior parameter from scrollToBottom — always use scrollTo(scrollSize) matching upstream. The smooth scrollToIndex was scrolling to stale lastIndex (before new item measured), leaving new messages below the fold. - Revert auto-scroll recovery from useLayoutEffect back to useEffect (matches upstream). useLayoutEffect fires before VList measures new items and before setAtBottom(false) in eventId effect. - Remove stale scrollCacheForRoomRef that referenced missing imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
A collection of scroll and UI regression fixes for the VList-based timeline:
useLayoutEffectfor auto-scroll recovery after timeline reset — when sliding sync upgradestimeline_limit(1 → 50), aTimelineResetreplaces VList content. The olduseEffectfired after paint, causing a visible flash at the wrong scroll position. Switching touseLayoutEffectcorrects scroll before the browser paints.scrollToIndexfor stay-at-bottom — use virtua'sscrollToIndexinstead ofscrollToBottomfor the stay-at-bottom behaviour, and remove a premature scroll call that raced with layout.programmaticScrollToBottomRefguard with a timestamp + 200 ms settling window (SCROLL_SETTLE_MS). VList fires multiple intermediateonScrollevents during re-measurement afterscrollToIndex(); the old boolean guard cleared on the firstisNowAtBottom=truecallback, letting subsequent callbacks flash the button. The timestamp approach suppresses false negatives for the entire measurement pass.Related to #635
Related to #55
Type of change
Checklist:
AI disclosure:
AI assisted with diagnosing the scroll timing issues and writing the timestamp-based settling window. The settling window stores
Date.now()when a programmatic scroll starts and ignoresatBottom=falsereports within 200 ms, letting VList's re-measurement pass complete without false negatives. AI also assisted with updating theuseTimelineSynctest to push a new event beforeTimelineResetso theuseLayoutEffectauto-scroll recovery fires correctly.