[GH-ISSUE #1931] Chat transcript should open already positioned at latest message #947

Closed
opened 2026-10-21 05:23:57 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1931

Originally assigned to: @Promansis on GitHub.

Problem

Opening an existing chat visibly opens, then scrolls down to the latest/bottom message. It should open already positioned at the bottom message, without the intermediate visible scroll.

Expected behavior

  • Selecting/opening a chat should render the initial transcript viewport at the bottom immediately.
  • The user should not see a post-mount smooth scroll from an earlier position to the bottom.
  • Existing "load more older messages" scroll preservation should keep working.

Observed behavior

  • When a chat is opened, the transcript renders first, then the auto-scroll effect moves the viewport to messagesEndRef.
  • Because the initial scroll happens after paint and uses smooth scrolling in non-streaming cases, the user can see the chat "open and then scroll" instead of opening at the final position.

Evidence from code inspection

  • Conversation mode:

    • src/features/modes/conversation/components/ConversationView.tsx
    • scrollRef and messagesEndRef are created around lines 495-496.
    • Initial/new-message scroll is handled by a useEffect around lines 544-553:
      • it calls messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
      • dependencies include newestMsgId, streaming buffers, typing state, etc.
    • A second useEffect around lines 841-848 also smooth-scrolls after staggered line reveal state changes.
  • Roleplay mode:

    • src/features/modes/roleplay/hooks/use-roleplay-transcript-scroll.ts
    • Initial/new-message scroll is handled by a useEffect around lines 84-91:
      • it calls messagesEndRef.current?.scrollIntoView({ behavior: isStreaming ? "auto" : "smooth" })
  • Shared data loading:

    • src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts
    • useChatMessages provides paged messages, then the hook reverses pages and flattens them into chronological render order.
    • src/features/catalog/chats/hooks/use-chats.ts fetches the latest page first via listChatMessages(... limit pageSize ...), so the bottom target exists after the initial messages query resolves.

Suspected root cause

The initial bottom positioning is implemented as a normal React effect after render/paint, not as a mount-time layout positioning step. Since the effect uses smooth scrolling while opening a non-streaming chat, the browser paints the initial transcript position first and then animates to the bottom.

Suggested fix direction

  • Add a per-chat initial-scroll path that runs before paint (useLayoutEffect) once the first message page is available.
  • For initial open/chat switch, set the scroll container directly, e.g. scrollRef.current.scrollTop = scrollRef.current.scrollHeight, or use scrollIntoView({ behavior: "auto" }).
  • Keep smooth scrolling only for subsequent live events such as new optimistic/user messages, generated assistant messages, streaming, or staggered reveal.
  • Ensure the existing load-more preservation path remains separate so prepending older pages still restores scrollTop by the height delta.

Acceptance criteria

  • Opening an existing conversation chat lands at the latest message without a visible animated scroll.
  • Opening an existing roleplay chat lands at the latest message without a visible animated scroll.
  • Sending/generating new messages can still auto-scroll when the user is near the bottom.
  • Loading older messages preserves the current viewport position.
Originally created by @Promansis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1931 Originally assigned to: @Promansis on GitHub. ## Problem Opening an existing chat visibly opens, then scrolls down to the latest/bottom message. It should open already positioned at the bottom message, without the intermediate visible scroll. ## Expected behavior - Selecting/opening a chat should render the initial transcript viewport at the bottom immediately. - The user should not see a post-mount smooth scroll from an earlier position to the bottom. - Existing "load more older messages" scroll preservation should keep working. ## Observed behavior - When a chat is opened, the transcript renders first, then the auto-scroll effect moves the viewport to `messagesEndRef`. - Because the initial scroll happens after paint and uses smooth scrolling in non-streaming cases, the user can see the chat "open and then scroll" instead of opening at the final position. ## Evidence from code inspection - Conversation mode: - `src/features/modes/conversation/components/ConversationView.tsx` - `scrollRef` and `messagesEndRef` are created around lines 495-496. - Initial/new-message scroll is handled by a `useEffect` around lines 544-553: - it calls `messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })` - dependencies include `newestMsgId`, streaming buffers, typing state, etc. - A second `useEffect` around lines 841-848 also smooth-scrolls after staggered line reveal state changes. - Roleplay mode: - `src/features/modes/roleplay/hooks/use-roleplay-transcript-scroll.ts` - Initial/new-message scroll is handled by a `useEffect` around lines 84-91: - it calls `messagesEndRef.current?.scrollIntoView({ behavior: isStreaming ? "auto" : "smooth" })` - Shared data loading: - `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts` - `useChatMessages` provides paged messages, then the hook reverses pages and flattens them into chronological render order. - `src/features/catalog/chats/hooks/use-chats.ts` fetches the latest page first via `listChatMessages(... limit pageSize ...)`, so the bottom target exists after the initial messages query resolves. ## Suspected root cause The initial bottom positioning is implemented as a normal React effect after render/paint, not as a mount-time layout positioning step. Since the effect uses smooth scrolling while opening a non-streaming chat, the browser paints the initial transcript position first and then animates to the bottom. ## Suggested fix direction - Add a per-chat initial-scroll path that runs before paint (`useLayoutEffect`) once the first message page is available. - For initial open/chat switch, set the scroll container directly, e.g. `scrollRef.current.scrollTop = scrollRef.current.scrollHeight`, or use `scrollIntoView({ behavior: "auto" })`. - Keep smooth scrolling only for subsequent live events such as new optimistic/user messages, generated assistant messages, streaming, or staggered reveal. - Ensure the existing load-more preservation path remains separate so prepending older pages still restores `scrollTop` by the height delta. ## Acceptance criteria - Opening an existing conversation chat lands at the latest message without a visible animated scroll. - Opening an existing roleplay chat lands at the latest message without a visible animated scroll. - Sending/generating new messages can still auto-scroll when the user is near the bottom. - Loading older messages preserves the current viewport position.
bsakaguchi 2026-10-21 05:23:57 +07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#947
No description provided.