Skip to content

Commit b61dd88

Browse files
fix(web): keep a first send's anchored position when switching threads
Anchored end space holds a thread's first send near the top while live follow is on, with end-following off. The gap below it is a real position, so remember it as one instead of as at the end. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4d26a50 commit b61dd88

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,13 +1043,19 @@ describe("MessagesTimeline", () => {
10431043
}),
10441044
getScrollableNode: () => ({ scrollTop: 700, getBoundingClientRect: () => ({ top: 0 }) }),
10451045
} as unknown as LegendListRef;
1046-
const renderTimeline = (liveFollowEnabled: boolean) => (
1046+
const renderTimeline = (
1047+
liveFollowEnabled: boolean,
1048+
anchorMessageId: MessageId | null = null,
1049+
) => (
10471050
<MessagesTimeline
10481051
{...props}
10491052
isWorking
10501053
liveFollowEnabled={liveFollowEnabled}
1054+
anchorMessageId={anchorMessageId}
10511055
routeThreadKey={threadKey}
1052-
timelineEntries={entries}
1056+
timelineEntries={
1057+
anchorMessageId ? [buildUserTimelineEntry("First send"), ...entries] : entries
1058+
}
10531059
/>
10541060
);
10551061
try {
@@ -1063,6 +1069,11 @@ describe("MessagesTimeline", () => {
10631069
act(() => renderer.update(renderTimeline(false)));
10641070
act(() => list().props.onScroll());
10651071
expect(readTimelinePosition(threadKey)).toMatchObject({ atEnd: false, scrollOffset: 700 });
1072+
1073+
// A first send anchored near the top is not following the end either.
1074+
act(() => renderer.update(renderTimeline(true, MessageId.make("message-1"))));
1075+
act(() => list().props.onScroll());
1076+
expect(readTimelinePosition(threadKey)).toMatchObject({ atEnd: false, scrollOffset: 700 });
10661077
} finally {
10671078
act(() => renderer?.unmount());
10681079
vi.unstubAllGlobals();

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,9 @@ export const MessagesTimeline = memo(function MessagesTimeline({
10311031
scrollOffset: element.scrollTop,
10321032
// While live-following, a gap to the end is the follow scroll
10331033
// trailing streamed output, not a reading position to restore.
1034-
atEnd: isAtEnd || liveFollowEnabled,
1034+
// Anchored end space holds the first send near the top instead of
1035+
// following, so its gap is a real position.
1036+
atEnd: isAtEnd || (liveFollowEnabled && !anchoredEndSpace),
10351037
disclosures: {
10361038
turns: paintedExpandedTurnIds,
10371039
workGroups: paintedExpandedWorkGroupIds,
@@ -1090,6 +1092,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
10901092
rows,
10911093
listIdentityKey,
10921094
liveFollowEnabled,
1095+
anchoredEndSpace,
10931096
restoringThreadPosition,
10941097
listRef,
10951098
minimapItems,

0 commit comments

Comments
 (0)