Skip to content

[RFC] Chat: no instant scroll path — opening an existing conversation spring-scrolls from the top #3795

Closed

Description

@yyq1025

Problem Statement

Opening a chat that already has content (history, replay, switching sessions) plays the stream-follow spring from scrollTop: 0 across the full transcript — the ResizeObserver treats the first bulk fill like streaming growth. Users expect to open at the latest message; animation conventionally belongs to the scroll-to-bottom button and stream-follow only.

There is no instant path at any layer: scrollToBottom() is spring-only with no options, ChatLayout doesn't pass spring params through, and ChatLayoutHandle is declared in ChatLayout.tsx but never wired or exported (ref only reaches the root element).

Evidence of Demand

Any "open an existing conversation" surface hits this — we hit it building a Claude Code session GUI on ChatLayout/ChatMessageList. Survey of how comparable list/chat libraries model this (all verified against source):

Library Initial position Follow behavior Instant control
use-stick-to-bottom initial?: Animation | boolean resize?: Animation behavior values 'instant'/'smooth'
legend-list initialScrollAtEnd: boolean maintainScrollAtEnd: true | {animated?, on?} animated option
FlashList v2 maintainVisibleContentPosition: {startRenderingFromBottom} same config object scrollToEnd({animated})
react-virtuoso initialTopMostItemIndex + alignToBottom followOutput: boolean | 'auto' | 'smooth' 'auto' = instant
TanStack Virtual anchorTo: 'end' same prop scrollToEnd()
RN FlatList — (inverted pattern) — scrollToEnd({animated})

Two consistent patterns: initial position and follow behavior are separate concerns in every library, and every follow/scroll API offers an instant (non-animated) mode. The closest prior art is use-stick-to-bottom — the same design as this hook (velocity-based spring, user-scroll vs animation-scroll detection) — and it treats initial positioning as a first-class option, even distinguishing first fill from growth internally (previousHeight ? options.resize : options.initial).

Relationship to #2572 and #3635

#2572 asks for top visual anchoring (the flex spacer, when content doesn't fill the viewport); this issue is the scroll half of the same axis (where does the viewport start when content overflows). Notably an initial: false value (per use-stick-to-bottom: don't engage the follow lock on open) would serve #2572's reading-oriented surfaces from the scroll side — one initial/anchor arbitration could resolve both ends coherently. Filed under the #3635 chat-maturation theme.

Why Existing Components Don't Cover This

With ChatLayout there's no affordance at all — our workaround bypasses the system via layout context:

const layout = useChatLayoutContext();
useLayoutEffect(() => {
  const el = layout?.scrollContainerRef.current;
  if (el && rows?.length) el.scrollTop = el.scrollHeight;
}, [layout, rows]);

Standalone (useChatStreamScroll yourself) doesn't help: scrollToBottom() has no instant option — though scrollToMessage already uses behavior: 'instant' in the same file.

Rough Approaches Considered

A. initial prop on ChatLayout, aligned with use-stick-to-bottom's shape: initial?: false | 'instant' | 'spring' (default 'spring' = today's behavior; 'instant' positions at the latest message on first non-empty fill with no animation; false doesn't engage the follow lock on open). First fill vs subsequent growth split exactly as use-stick-to-bottom does.

B. scrollToBottom({instant?: boolean}) on the hook — non-breaking, mirrors ecosystem APIs, also unlocks standalone consumers.

C. Wire the declared ChatLayoutHandle (needs an API call: ref is currently the root element).

A and B/C compose; naming/shape (boolean vs behavior-value, initial vs initialPosition vs unifying with #2572's anchor) deliberately left to arbitration. Happy to implement whichever shape passes.

Accessibility Considerations

The spring ignores prefers-reduced-motion entirely — same gap 0.1.3 fixed for Spinner/ProgressBar/Skeleton; an instant path doubles as the reduced-motion fallback. Happy to split this out as a bug. role="log"/aria-busy semantics unaffected.

Performance Considerations

n/a — removes rAF scroll work per open, adds none.

Pre-submission Checklist

  • I have read the Contributing guide
  • I have read the API Conventions
  • I have checked that existing Astryx components cannot compose to solve this
  • This is a general-purpose UI pattern (not specific to one product)

Activity

  1. cixzhang commented on Jul 13, 2026

    @cixzhang
    Contributor

    Thanks for the write up.

    @kentonquatman for any design thoughts.

    I think the initial smooth scroll to bottom as unintentional. That first scroll should just be instant by default and can't imagine a case where smooth scrolling would be useful there. I think having a prop that enables initialScroll to be top or bottom would be helpful at the layout level and passed through to the chat scroller.

  2. cixzhang commented on Jul 13, 2026

    @cixzhang
    Contributor

    Dug into the mechanism to confirm the root cause before settling the shape.

    Root cause (confirmed). The messages aren't arriving late — they're in the DOM on the first commit. The spring-from-top is an effect race between two scroll triggers:

    1. useChatNewMessages attaches via observeResize, which fires its callback synchronously on registration (sharedResizeObserver: "Fires the callback once synchronously on registration"). That sync fire → onResize() → scrollIfLocked(), and since the lock defaults to true, it calls startAnimation() — the spring begins from scrollTop: 0.
    2. The hook's own initial scroll-to-bottom is instant and correct, but it's deferred inside a requestAnimationFrame, so it runs after the synchronous spring has already started.

    The hook can't distinguish "first bulk fill" from "streaming growth" — both come through the same scrollIfLocked path. That's exactly the case use-stick-to-bottom guards internally with previousHeight ? options.resize : options.initial.

    Arbitration. I'd keep the first cut tight — two composable, non-breaking changes, both in useChatStreamScroll:

    1. Guard the first fill. Track whether prior scrollable content existed; the first non-empty measurement positions instantly, subsequent growth springs as today. This is the actual bug fix and needs no new public surface — the intent to position instantly already lives in the hook, it just misses async fills.
    2. Instant option on the imperative, so standalone consumers (and the layout) can request a one-frame jump. On shape: scrollToMessage in this same file already uses behavior: 'instant', and the DOM's scrollTo/scrollIntoView use behavior: 'instant' | 'smooth' — so I lean toward scrollToBottom({behavior?: 'instant' | 'spring'}) (default 'spring' = today) over a bare {instant: boolean}, to stay consistent with the sibling API and the platform. Mechanical either way.

    Deliberately deferring the ChatLayout-level initial prop and the false/start-at-top value. Opening an existing conversation at the bottom instantly is unconditionally correct — there's no case where spring-from-top is the desired behavior, so it needs no opt-in. Initial position (top vs bottom) is a separate axis, and that's #2572 — I'd rather resolve the position knob there (as align/anchor) than introduce a second overlapping surface here. So: fix the behavior now, arbitrate the position prop on #2572.

    Reduced motion: the instant path is the natural prefers-reduced-motion fallback the spring currently ignores (same gap 0.1.3 closed for Spinner/ProgressBar/Skeleton). Fine to fold in here or split as its own bug — no strong preference.

    @yyq1025 #3800 already covers the core fix — thanks for getting ahead of it. Left specifics on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions