Skip to content

Commit 1a02177

Browse files
committed
fix(web): keep following the stream after scrolling back to the live edge
Scrolling up mid-turn and back down re-enabled live follow but left the send-time anchored end space installed. That space keeps LegendList's maintainScrollAtEnd switched off, and ChatView only drives streaming scrolls itself while the mode is "anchoring-new-turn", so the timeline settled into "following-end" with nothing pinning it: further output kept appending below the viewport, with the scroll-to-bottom pill hidden because the list did consider itself at the end. Reopening the thread was the only way back. Release the anchor when follow re-arms, the same way the scroll-to-bottom pill already does.
1 parent fd51561 commit 1a02177

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,20 @@ function chatActionErrorMessage(error: unknown): string {
11851185
return error instanceof Error ? error.message : "An error occurred.";
11861186
}
11871187

1188+
/**
1189+
* Drops the send-time anchored end space. That space is what holds a sent
1190+
* message near the top while its turn streams, and it keeps LegendList's
1191+
* maintainScrollAtEnd switched off for as long as it is installed — ChatView
1192+
* drives the streaming scrolls itself, but only in "anchoring-new-turn" mode.
1193+
* So every return to the live edge has to release the anchor too, otherwise the
1194+
* timeline settles into "following-end" with nothing following anything.
1195+
*/
1196+
function releaseChatTimelineAnchor<T extends { readonly messageId: MessageId | null }>(
1197+
current: T,
1198+
): T {
1199+
return current.messageId === null ? current : { ...current, messageId: null };
1200+
}
1201+
11881202
function ChatViewContent(props: ChatViewProps) {
11891203
const {
11901204
environmentId,
@@ -3744,9 +3758,7 @@ function ChatViewContent(props: ChatViewProps) {
37443758
activeTimelineAnchorIndexRef.current = null;
37453759
showScrollDebouncer.current.cancel();
37463760
setShowScrollToBottom(false);
3747-
setTimelineAnchor((current) =>
3748-
current.messageId === null ? current : { ...current, messageId: null },
3749-
);
3761+
setTimelineAnchor(releaseChatTimelineAnchor);
37503762
requestAnimationFrame(() => {
37513763
void legendListRef.current?.scrollToEnd?.({ animated });
37523764
});
@@ -3921,6 +3933,11 @@ function ChatViewContent(props: ChatViewProps) {
39213933
timelineScrollModeRef.current = "following-end";
39223934
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
39233935
setTimelineLiveFollowEnabled(true);
3936+
// Reachable only once manual navigation has already broken follow, so
3937+
// the anchored turn framing is over: the user scrolled back to the live
3938+
// edge and expects the stream to stick to it again, exactly like the
3939+
// scroll-to-bottom pill.
3940+
setTimelineAnchor(releaseChatTimelineAnchor);
39243941
showScrollDebouncer.current.cancel();
39253942
setShowScrollToBottom(false);
39263943
} else {

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,56 @@ describe("MessagesTimeline", () => {
432432
expect(onAnchorReady).toHaveBeenCalledWith(secondEntry.message.id, 1);
433433
});
434434

435+
it("hands end-following back to the list once the send anchor is released", () => {
436+
const firstEntry = buildUserTimelineEntry("First prompt.");
437+
const secondEntry = {
438+
...buildUserTimelineEntry("Newest prompt."),
439+
id: "entry-2",
440+
message: {
441+
...buildUserTimelineEntry("Newest prompt.").message,
442+
id: MessageId.make("message-2"),
443+
},
444+
};
445+
const timelineEntries = [firstEntry, secondEntry];
446+
447+
// While the send anchor holds the end space open, ChatView owns streaming
448+
// scrolls and LegendList must not re-pin behind it.
449+
expect(
450+
renderToStaticMarkup(
451+
<MessagesTimeline
452+
{...buildProps()}
453+
anchorMessageId={secondEntry.message.id}
454+
timelineEntries={timelineEntries}
455+
/>,
456+
),
457+
).not.toContain('data-maintain-scroll-at-end="enabled"');
458+
459+
// Dropping the anchor is what actually gives end-following back, so
460+
// returning to the live edge has to release it — re-enabling live follow
461+
// alone leaves nothing pinned to the stream.
462+
expect(
463+
renderToStaticMarkup(
464+
<MessagesTimeline
465+
{...buildProps()}
466+
anchorMessageId={null}
467+
timelineEntries={timelineEntries}
468+
/>,
469+
),
470+
).toContain('data-maintain-scroll-at-end="enabled"');
471+
472+
// Reading history still wins over both.
473+
expect(
474+
renderToStaticMarkup(
475+
<MessagesTimeline
476+
{...buildProps()}
477+
anchorMessageId={null}
478+
liveFollowEnabled={false}
479+
timelineEntries={timelineEntries}
480+
/>,
481+
),
482+
).not.toContain('data-maintain-scroll-at-end="enabled"');
483+
});
484+
435485
it("renders collapse controls for long user messages", () => {
436486
const markup = renderToStaticMarkup(
437487
<MessagesTimeline

0 commit comments

Comments
 (0)