Skip to content

Commit 94b9b04

Browse files
fix(web): show scroll-to-end as soon as the last message slips under the composer
Scrolling up in a thread required travelling a whole composer height before the scroll-to-end pill appeared, because the end check subtracted the composer inset twice: contentLength already includes the inset spacer, and the composer covers the same amount of viewport, so the two cancel and the plain contentLength - scroll - scrollLength gap is the real distance to the visible edge. resolveTimelineIsAtEnd also short-circuited on LegendList's own isAtEnd, which is true anywhere inside that composer-height band, so the pill was suppressed even after the geometry check would have fired. Drop the inset parameter and the flag short-circuit; the flag is now only the fallback for state without geometry. Co-Authored-By: Claude Code <[email protected]>
1 parent 9159b80 commit 94b9b04

4 files changed

Lines changed: 22 additions & 29 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,8 +4219,7 @@ function ChatViewContent(props: ChatViewProps) {
42194219
// up, and a gesture landing in that window while still pinned would
42204220
// otherwise break follow with no scroll event left to re-arm it.
42214221
const viewportIsAwayFromEnd = () =>
4222-
resolveTimelineIsAtEnd(legendListRef.current?.getState(), composerOverlayHeight) ===
4223-
false;
4222+
resolveTimelineIsAtEnd(legendListRef.current?.getState()) === false;
42244223
// Only an upward wheel is a navigation intent; wheeling down while
42254224
// following either does nothing (at the end) or moves toward it.
42264225
const handleWheel = (event: WheelEvent) => {
@@ -4299,7 +4298,7 @@ function ChatViewContent(props: ChatViewProps) {
42994298
}
43004299
removeListeners?.();
43014300
};
4302-
}, [activeThread?.id, composerOverlayHeight, timelineRealContentOverflowsViewport]);
4301+
}, [activeThread?.id, timelineRealContentOverflowsViewport]);
43034302

43044303
const onTimelineAnchorReady = useCallback((messageId: MessageId, anchorIndex: number) => {
43054304
// Anchored-end space can be remeasured when the turn completes. Once the

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,21 @@ export interface TimelineEndState {
135135
*/
136136
export const TIMELINE_FOLLOW_REARM_THRESHOLD_PX = 40;
137137

138-
export function resolveTimelineIsAtEnd(
139-
state: TimelineEndState | undefined,
140-
endInset = 0,
141-
): boolean | undefined {
138+
export function resolveTimelineIsAtEnd(state: TimelineEndState | undefined): boolean | undefined {
142139
if (!state) {
143140
return undefined;
144141
}
145-
if (state.isAtEnd) {
146-
return true;
147-
}
148142
const { contentLength, scroll, scrollLength } = state;
149143
if (contentLength === undefined || scroll === undefined || scrollLength === undefined) {
150144
return state.isAtEnd;
151145
}
152-
// contentLength includes the end inset (composer overlay), so subtract it to
153-
// measure the distance to the real content bottom.
154-
return contentLength - scroll - scrollLength - endInset <= TIMELINE_FOLLOW_REARM_THRESHOLD_PX;
146+
// contentLength includes the composer inset spacer, but the composer hides
147+
// the same amount of viewport, so the inset cancels: plain
148+
// contentLength - scroll - scrollLength is the gap between the last real row
149+
// and the visible edge above the composer. LegendList's own isAtEnd subtracts
150+
// the inset and is true anywhere in the bottom composer-height band, so it is
151+
// only a fallback here, never a short-circuit.
152+
return contentLength - scroll - scrollLength <= TIMELINE_FOLLOW_REARM_THRESHOLD_PX;
155153
}
156154

157155
export function shouldPreserveAssistantLineBreaks(text: string): boolean {

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,17 @@ describe("MessagesTimeline", () => {
378378
scrollLength: 800,
379379
}),
380380
).toBe(false);
381-
// The composer inset is part of contentLength and must not count as
382-
// distance-to-end.
381+
// LegendList's isAtEnd is true anywhere within the composer-height band
382+
// (it subtracts the inset); the last row is still hidden under the
383+
// composer there, so the flag must not short-circuit the geometry.
383384
expect(
384-
resolveTimelineIsAtEnd(
385-
{ isAtEnd: false, contentLength: 2100, scroll: 1170, scrollLength: 800 },
386-
100,
387-
),
388-
).toBe(true);
385+
resolveTimelineIsAtEnd({
386+
isAtEnd: true,
387+
contentLength: 2000,
388+
scroll: 1100,
389+
scrollLength: 800,
390+
}),
391+
).toBe(false);
389392
// Geometry missing (older state shape): fall back to the strict flag.
390393
expect(resolveTimelineIsAtEnd({ isAtEnd: false })).toBe(false);
391394

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
555555

556556
const handleScroll = useCallback(() => {
557557
const state = listRef.current?.getState?.();
558-
const isAtEnd = resolveTimelineIsAtEnd(state, contentInsetEndAdjustment);
558+
const isAtEnd = resolveTimelineIsAtEnd(state);
559559
if (isAtEnd !== undefined && !citationPositioning) {
560560
onIsAtEndChange(isAtEnd);
561561
}
@@ -581,14 +581,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
581581

582582
strip.dataset.inView = inView ? "true" : "false";
583583
}
584-
}, [
585-
citationPositioning,
586-
contentInsetEndAdjustment,
587-
listRef,
588-
minimapItems,
589-
minimapStripMap,
590-
onIsAtEndChange,
591-
]);
584+
}, [citationPositioning, listRef, minimapItems, minimapStripMap, onIsAtEndChange]);
592585

593586
useEffect(() => {
594587
const frame = requestAnimationFrame(handleScroll);

0 commit comments

Comments
 (0)