Skip to content

fix(timeline): scroll stay-at-bottom, Jump to Latest button, and phantom unread regressions#688

Closed
Just-Insane wants to merge 11 commits intoSableClient:devfrom
Just-Insane:fix/ui-regressions
Closed

fix(timeline): scroll stay-at-bottom, Jump to Latest button, and phantom unread regressions#688
Just-Insane wants to merge 11 commits intoSableClient:devfrom
Just-Insane:fix/ui-regressions

Conversation

@Just-Insane
Copy link
Copy Markdown
Contributor

Description

A collection of scroll and UI regression fixes for the VList-based timeline:

  1. Phantom unread dot + blank notification page recovery — fix stale unread indicators and empty notification view after room transitions.
  2. useLayoutEffect for auto-scroll recovery after timeline reset — when sliding sync upgrades timeline_limit (1 → 50), a TimelineReset replaces VList content. The old useEffect fired after paint, causing a visible flash at the wrong scroll position. Switching to useLayoutEffect corrects scroll before the browser paints.
  3. scrollToIndex for stay-at-bottom — use virtua's scrollToIndex instead of scrollToBottom for the stay-at-bottom behaviour, and remove a premature scroll call that raced with layout.
  4. Timestamp-based settling window for Jump to Latest button — replace the boolean programmaticScrollToBottomRef guard with a timestamp + 200 ms settling window (SCROLL_SETTLE_MS). VList fires multiple intermediate onScroll events during re-measurement after scrollToIndex(); the old boolean guard cleared on the first isNowAtBottom=true callback, 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

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 ignores atBottom=false reports within 200 ms, letting VList's re-measurement pass complete without false negatives. AI also assisted with updating the useTimelineSync test to push a new event before TimelineReset so the useLayoutEffect auto-scroll recovery fires correctly.

- 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.
Copilot AI review requested due to automatic review settings April 15, 2026 02:38
@Just-Insane Just-Insane requested review from 7w1 and hazre as code owners April 15, 2026 02:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useLayoutEffect and 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.

Comment thread src/app/features/room/RoomTimeline.tsx Outdated
Comment on lines 256 to 260
// 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' });
}, []);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/app/features/room/RoomTimeline.tsx Outdated
Comment on lines +424 to +430
if (eventId && !isReady && timelineSync.liveTimelineLinked && timelineSync.eventsLength > 0) {
scrollToBottom();
setIsReady(true);
}
}, [
eventId,
isReady,
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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,

Copilot uses AI. Check for mistakes.
Just-Insane and others added 7 commits April 15, 2026 09:50
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>
@Just-Insane Just-Insane marked this pull request as draft April 17, 2026 11:55
@Just-Insane Just-Insane deleted the fix/ui-regressions branch April 17, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants