t3code icon indicating copy to clipboard operation
t3code copied to clipboard

fix(web): preserve scroll when composer grows

Open caezium opened this issue 4 months ago โ€ข 6 comments

What Changed

  • Bind wheel and touch navigation directly to the timeline, and treat only scrollbar presses as pointer navigation, so reader intent cannot be missed without ordinary timeline clicks disabling live follow.
  • Disable layout-based end following after the reader leaves the live edge, while preserving existing data-change and item-layout behavior.
  • Scope the layout-follow state to the active thread so a scrolled-up thread cannot leak stale state into the next thread.
  • Add focused regression coverage for the ChatView state handoff, LegendList configuration, and navigation bindings.

Why

When manual-navigation listeners miss the timeline during mount, scrolling upward does not cancel live following. Growing the composer with Shift+Enter then updates the timeline's bottom inset and reruns end-following logic, forcing the transcript to the bottom.

The timeline now receives navigation handlers through its normal component lifecycle and only keeps layout-based end following enabled while the reader is at the live edge. Explicit scroll-to-end, thread changes, and sends restore following.

UI Changes

Before

Shift+Enter grows the composer and moves the transcript from the reader's earlier position to the live edge.

Before: Shift+Enter snaps the transcript to the bottom

Before result at the live edge

After

The composer grows while the same earlier transcript position remains in view.

After: Shift+Enter preserves the transcript position

After result with the earlier position preserved

Validation

  • vp test run apps/web/src/components/chat/MessagesTimeline.test.tsx apps/web/src/components/chat/timelineScrollAnchoring.test.tsx apps/web/src/components/ChatView.logic.test.ts (59 passed)
  • vp lint --report-unused-disable-directives apps/web/src/components/ChatView.tsx apps/web/src/components/chat/MessagesTimeline.tsx apps/web/src/components/chat/MessagesTimeline.test.tsx
  • vp run --filter @t3tools/web typecheck
  • Browser regression on untouched upstream/main: real Shift+Enter grew the composer from 70px to 90.96px and moved scrollTop from 652.08px to the 1252.08px live edge.
  • Browser verification on this branch: the same Shift+Enter and composer growth kept scrollTop at 652.08px.

Checklist

  • [x] This PR is small and focused
  • [x] I explained what changed and why
  • [x] I included before/after screenshots for any UI changes
  • [x] I included a video for animation/interaction changes

Built with GPT-5.6-Sol in T3 Code through the Codex harness.


[!NOTE] Low Risk Chat timeline scroll and composer layout behavior only; changes are localized with regression tests and no auth, data, or API impact.

Overview Fixes the transcript jumping to the live edge when the composer grows (e.g. Shift+Enter) after the user has scrolled up.

Layout follow is now gated per thread: ChatView tracks TimelineLayoutFollowState and passes maintainScrollAtEndOnLayout into MessagesTimeline. LegendList still maintains scroll on data/item layout changes, but layout end-following is turned off once the reader leaves the bottom; scrolling back, sending, or switching threads restores it. A new thread defaults to follow-at-end so scrolled-up state does not leak across threads.

Manual navigation is wired on the timeline list instead of deferred DOM listeners in ChatView: wheel, touchmove, and pointer-down on the scrollbar (via isTimelineScrollbarPointerDown) call onManualNavigation and update layout-follow state. Ordinary clicks on message content no longer cancel live follow.

Reviewed by Cursor Bugbot for commit 911cd655735ced73ad5f2d6c8ecef29b1d73f38f. Bugbot is set up for automated code reviews on this repo. Configure here.

[!NOTE]

Preserve scroll position in chat timeline when composer grows

  • Introduces per-thread layout-follow state in ChatViewContent that tracks whether the timeline should snap to the end during layout changes (e.g. composer resize).
  • Layout-follow is disabled when the user scrolls away from the end and re-enabled when they return to the end, send a message, or switch threads.
  • Wheel, touchmove, and scrollbar pointerdown events in MessagesTimeline now trigger manual-navigation, which disables layout-follow until the user returns to the end.
  • A new isTimelineScrollbarPointerDown utility in MessagesTimeline.logic.ts distinguishes scrollbar drags from content pointer interactions so only scrollbar pointerdowns count as navigation.
  • State transitions are managed by pure reducer functions in timelineScrollAnchoring.ts via reduceTimelineLayoutFollowState.

Macroscope summarized 911cd65.

Summary by CodeRabbit

  • Bug Fixes

    • Improved chat timeline scrolling when navigating between threads.
    • Preserved the correct follow position when new messages or layout changes occur.
    • Prevented automatic scrolling after manually navigating away from the latest messages.
    • Improved scrollbar, wheel, touch, and pointer interactions for manual navigation.
    • Returning to the end of the timeline now reliably restores automatic follow behavior.
  • Tests

    • Added coverage for thread switching, scrollbar interactions, manual navigation, and layout scroll behavior.

caezium avatar Aug 02 '26 13:08 caezium

Review Change Stack

๐Ÿ“ Walkthrough

Walkthrough

The timeline now tracks layout-follow state by thread. Manual navigation can disable layout retention until the timeline returns to the end. MessagesTimeline detects wheel, touch, and scrollbar interactions and applies conditional layout retention.

Changes

Timeline scroll control

Layer / File(s) Summary
Timeline follow contract and scrollbar detection
apps/web/src/components/chat/timelineScrollAnchoring.ts, apps/web/src/components/chat/MessagesTimeline.logic.ts, apps/web/src/components/chat/MessagesTimeline.tsx
The timeline defines thread-aware follow-state actions. It detects scrollbar pointer navigation and applies the follow flag only to layout retention.
Timeline follow validation
apps/web/src/components/chat/MessagesTimeline.test.tsx, apps/web/src/components/chat/timelineScrollAnchoring.test.tsx
Tests cover scrollbar detection, manual-navigation callbacks, state transitions, thread changes, and independent retention modes.
ChatView follow-state integration
apps/web/src/components/ChatView.tsx
ChatView updates follow state during navigation, end-position changes, thread switches, message sends, and plan follow-ups. It passes the derived flag to MessagesTimeline.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ChatView
  participant MessagesTimeline
  participant LegendList
  User->>MessagesTimeline: Navigate with wheel, touch, or scrollbar
  MessagesTimeline->>ChatView: Report manual navigation
  ChatView->>ChatView: Update thread follow state
  ChatView->>MessagesTimeline: Pass layout-follow flag
  MessagesTimeline->>LegendList: Configure layout retention
  LegendList-->>MessagesTimeline: Retain data and item-layout positions

Possibly related PRs

Suggested reviewers: juliusmarminge

๐Ÿšฅ Pre-merge checks | โœ… 4 | โŒ 1

โŒ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
โœ… Passed checks (4 passed)
Check name Status Explanation
Linked Issues check โœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check โœ… Passed Check skipped because no linked issues were found for this pull request.
Title check โœ… Passed The title clearly and concisely describes the main fix: preserving chat scroll position when the composer grows.
Description check โœ… Passed The description includes complete What Changed, Why, UI Changes, validation, and Checklist sections with relevant details and evidence.
โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Aug 02 '26 13:08 coderabbitai[bot]

@coderabbitai review

caezium avatar Aug 02 '26 13:08 caezium

โœ… Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Aug 02 '26 13:08 coderabbitai[bot]

Approvability

Verdict: Needs human review

This is a focused UI bug fix for scroll behavior preservation, well-tested with clear intent. However, the author is a first-time contributor to these scroll-related files, and the timeline scroll system has subtle interactions that warrant review by someone familiar with it.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Aug 02 '26 13:08 macroscopeapp[bot]

@coderabbitai review

caezium avatar Aug 02 '26 19:08 caezium

โœ… Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Aug 02 '26 19:08 coderabbitai[bot]

[!NOTE] ๐Ÿค– GPT-5.6 Sol responding on behalf of Theo

We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

Current main already stops end-of-thread scroll maintenance when live following is off. This branch adds a second composer-layout follow state for behavior that the current code already owns.

If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

t3dotgg avatar Aug 28 '26 13:08 t3dotgg