fix(web): reliably follow latest thread content #5905
main fromrefs/pull/5905/head·opened View on GitHubWhat Changed#
- Scope live-follow state to the full environment/thread route so a newly selected thread follows from its first render.
- Settle send-time anchoring when LegendList reports authoritative row-height changes from markdown, images, and tool output.
- Return control to normal end-following when the reader reaches the live edge.
- Invalidate deferred follow callbacks across route changes, including rapid A → B → A switches.
- Preserve the existing scroll-away affordance and history-prepend viewport behavior.
- Add focused regressions for thread switching, delayed layout, live follow, scroll-away, follow restoration, and route-switch races.
Why#
Initial positioning depended on LegendList's one-shot initialScrollAtEnd, while live-follow state survived SPA route changes until a post-render reset. A thread could therefore render once with stale follow state, and delayed row measurement could occur after the initial correction had already finished.
The fix keeps the existing virtualization architecture and only follows while the reader remains at the live edge. It does not add persisted scroll state, timers, or render-time scrollToBottom() calls.
Closes #5903
UI Changes#
This is a timing and interaction change. Before/after screenshots and a short recording will be added while the PR is in draft.
Verification#
pnpm exec vp test run apps/web/src/components/chat/timelineScrollAnchoring.test.tsx apps/web/src/components/chat/MessagesTimeline.test.tsx packages/client-runtime/src/state/threads-pagination.test.ts— 38 passedpnpm --filter @t3tools/web typecheckpnpm --filter @t3tools/client-runtime typecheck- Focused lint and format checks
git diff --check- Independent review: PASS
Manual verification:
- A long buffered response settled with its final line visible.
- A 19,011px-long existing thread opened within 0.5px of the live edge.
- Scrolling upward preserved the reading position while content grew.
- Returning to the bottom restored normal follow behavior.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes
- I included a video for animation/interaction changes
Built with GPT-5.6-Sol in T3 Code through the Codex harness.
Note
Fix thread chat view to reliably follow latest content across route changes and size updates#
- Live-follow state is now scoped per route/thread so opening a new thread always starts in follow mode, even if the previous thread was paused.
- Late row height measurements (e.g. buffered completions) now trigger a deferred single-frame scroll via a new
onTimelineItemSizeChangedhandler to keep the live edge visible. - Anchor state is fully cleared when the user returns to the end of a thread, preventing residual anchor space or stale offsets from persisting.
- New helpers in timelineScrollAnchoring.ts (
resolveTimelineRouteEpoch,clearTimelineAnchor,getAnchoredTurnEndRevealOffset) centralize route- and thread-aware scroll logic. - Behavioral Change: scroll reveal after anchoring a new turn now uses absolute offset arithmetic instead of delta-based math, and fires without animation.
📊 Macroscope summarized 87be81e. 3 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues#
No issues evaluated.
Note
Medium Risk Touches core chat scroll state, LegendList integration, and thread-switch timing; behavior is heavily regression-tested but wrong scroll logic is user-visible.
Overview Fixes chat timeline scroll/follow so new threads start at the live edge and streaming content stays visible after late layout.
Live-follow is keyed by route/thread (routeThreadKey instead of activeThread?.id for resets and list remount). A thread you open while another had follow disabled still gets liveFollowEnabled on the first paint via resolveTimelineLiveFollowEnabled, before the route reset effect runs.
Send-time anchoring reacts to real row heights: MessagesTimeline forwards LegendList onItemSizeChanged; ChatView debounces with requestAnimationFrame and calls revealActiveTimelineTurnEnd, which uses new getAnchoredTurnEndRevealOffset (absolute scroll target) instead of inlined delta scroll math. Route epochs drop stale deferred reveals on fast A→B→A switches.
Returning to the live edge clears pending/positioned/settled anchor refs and applies clearTimelineAnchor so send-time anchor space does not linger after ordinary bottom-follow resumes.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -3658,3 +3686,4 @@36583686 },36593687 [composerOverlayHeight],36603688 );3689+ const revealActiveTimelineTurnEnd = useCallback(() => {
🟡 Medium
components/ChatView.tsx:3689onTimelineItemSizeChangedcoalesces size-change notifications into a singlerequestAnimationFramecallback that callsrevealActiveTimelineTurnEnd, butrevealActiveTimelineTurnEnddrops the invocation whenpositionedTimelineAnchorRefis set andsettledTimelineAnchorRefhas not caught up yet. If a row gets its final measured height while the anchor'sscrollToIndexanimation is still in flight, that size-change signal is consumed and discarded, and no retry is scheduled when the anchor promise later resolves — so the turn's final content can remain hidden below the composer. Consider preserving a pending size-change flag and re-invoking the reveal aftersettledTimelineAnchorRefis set, or callingrevealActiveTimelineTurnEndinside the anchorscrollToIndex.then()callback.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/ChatView.tsx around line 3689: `onTimelineItemSizeChanged` coalesces size-change notifications into a single `requestAnimationFrame` callback that calls `revealActiveTimelineTurnEnd`, but `revealActiveTimelineTurnEnd` drops the invocation when `positionedTimelineAnchorRef` is set and `settledTimelineAnchorRef` has not caught up yet. If a row gets its final measured height while the anchor's `scrollToIndex` animation is still in flight, that size-change signal is consumed and discarded, and no retry is scheduled when the anchor promise later resolves — so the turn's final content can remain hidden below the composer. Consider preserving a pending size-change flag and re-invoking the reveal after `settledTimelineAnchorRef` is set, or calling `revealActiveTimelineTurnEnd` inside the anchor `scrollToIndex` `.then()` callback. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 87be81ef6417ff9d477de772d361e6230bb20a04. Configure [here](https://www.cursor.com/dashboard/bugbot).@@ -2,0 +15,21 @@15+}16+17+export function clearTimelineAnchor<Message>(18+ state: TimelineAnchorState<Message>,19+): TimelineAnchorState<Message> {20+ return state.messageId === null ? state : { ...state, messageId: null };21+}22+23+export function resolveTimelineRouteEpoch(24+ current: TimelineRouteEpoch,25+ threadKey: string,26+): TimelineRouteEpoch {27+ return current.threadKey === threadKey ? current : { threadKey };28+}29+30+export function resolveTimelineLiveFollowEnabled(31+ state: TimelineLiveFollowState,32+ threadKey: string,33+): boolean {34+ return state.threadKey === threadKey ? state.enabled : true;35+}Return visit skips live follow#
Medium Severity
resolveTimelineLiveFollowEnabledonly defaults to follow when the storedthreadKeydiffers from the route. On a rapid A → B → A switch, state can still be{ threadKey: A, enabled: false }when A remounts, so the first paint keepsliveFollowEnabledfalse. Late row measurement can finish in that window before the route reset effect turns follow back on, leaving the thread short of the live edge.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 87be81ef6417ff9d477de772d361e6230bb20a04. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (1)
Approvability#
Verdict: Needs human review
1 blocking correctness issue found. This PR modifies scroll anchoring behavior with timing-sensitive state management. Two Medium-severity unresolved findings identify potential race conditions: one where size-change signals may be lost during anchor animations, and another affecting rapid thread switching. These edge cases in the new scroll reveal logic warrant human review.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
This comment is posted by Julius' dot
Closing because the required UI verification evidence is missing. The PR reports focused tests and manual scroll checks, but still promises screenshots and a recording later. Please add before/after images and a short recording showing thread switching, delayed content growth, scrolling away and returning to the live edge, then request reconsideration.
juliusmarminge closed this
Sign in to join this conversation.

Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
aca9fb78-05fd-4ab2-9e64-d79cb96edb34You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share