fix(web): show scroll-to-end as soon as the last message slips under the composer (#9280)

Co-authored-by: Claude Code <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Code authored and GitHub committed 2026-09-02 16:06:31 -07:00
1 parent 63f334baf3
commit c742edd46c
4 files changed
+22 -29

No files matched your search

+2 -3
View File
@@ -4408,8 +4408,7 @@ function ChatViewContent(props: ChatViewProps) {
// up, and a gesture landing in that window while still pinned would
// otherwise break follow with no scroll event left to re-arm it.
const viewportIsAwayFromEnd = () =>
resolveTimelineIsAtEnd(legendListRef.current?.getState(), composerOverlayHeight) ===
false;
resolveTimelineIsAtEnd(legendListRef.current?.getState()) === false;
// Only an upward wheel is a navigation intent; wheeling down while
// following either does nothing (at the end) or moves toward it.
const handleWheel = (event: WheelEvent) => {
@@ -4488,7 +4487,7 @@ function ChatViewContent(props: ChatViewProps) {
}
removeListeners?.();
};
}, [activeThread?.id, composerOverlayHeight, timelineRealContentOverflowsViewport]);
}, [activeThread?.id, timelineRealContentOverflowsViewport]);
const onTimelineAnchorReady = useCallback((messageId: MessageId, anchorIndex: number) => {
// Anchored-end space can be remeasured when the turn completes. Once the
@@ -145,23 +145,21 @@ export interface TimelineEndState {
*/
export const TIMELINE_FOLLOW_REARM_THRESHOLD_PX = 40;
export function resolveTimelineIsAtEnd(
state: TimelineEndState | undefined,
endInset = 0,
): boolean | undefined {
export function resolveTimelineIsAtEnd(state: TimelineEndState | undefined): boolean | undefined {
if (!state) {
return undefined;
}
if (state.isAtEnd) {
return true;
}
const { contentLength, scroll, scrollLength } = state;
if (contentLength === undefined || scroll === undefined || scrollLength === undefined) {
return state.isAtEnd;
}
// contentLength includes the end inset (composer overlay), so subtract it to
// measure the distance to the real content bottom.
return contentLength - scroll - scrollLength - endInset <= TIMELINE_FOLLOW_REARM_THRESHOLD_PX;
// contentLength includes the composer inset spacer, but the composer hides
// the same amount of viewport, so the inset cancels: plain
// contentLength - scroll - scrollLength is the gap between the last real row
// and the visible edge above the composer. LegendList's own isAtEnd subtracts
// the inset and is true anywhere in the bottom composer-height band, so it is
// only a fallback here, never a short-circuit.
return contentLength - scroll - scrollLength <= TIMELINE_FOLLOW_REARM_THRESHOLD_PX;
}
export function shouldPreserveAssistantLineBreaks(text: string): boolean {
@@ -378,14 +378,17 @@ describe("MessagesTimeline", () => {
scrollLength: 800,
}),
).toBe(false);
// The composer inset is part of contentLength and must not count as
// distance-to-end.
// LegendList's isAtEnd is true anywhere within the composer-height band
// (it subtracts the inset); the last row is still hidden under the
// composer there, so the flag must not short-circuit the geometry.
expect(
resolveTimelineIsAtEnd(
{ isAtEnd: false, contentLength: 2100, scroll: 1170, scrollLength: 800 },
100,
),
).toBe(true);
resolveTimelineIsAtEnd({
isAtEnd: true,
contentLength: 2000,
scroll: 1100,
scrollLength: 800,
}),
).toBe(false);
// Geometry missing (older state shape): fall back to the strict flag.
expect(resolveTimelineIsAtEnd({ isAtEnd: false })).toBe(false);
@@ -555,7 +555,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
const handleScroll = useCallback(() => {
const state = listRef.current?.getState?.();
const isAtEnd = resolveTimelineIsAtEnd(state, contentInsetEndAdjustment);
const isAtEnd = resolveTimelineIsAtEnd(state);
if (isAtEnd !== undefined && !citationPositioning) {
onIsAtEndChange(isAtEnd);
}
@@ -581,14 +581,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
strip.dataset.inView = inView ? "true" : "false";
}
}, [
citationPositioning,
contentInsetEndAdjustment,
listRef,
minimapItems,
minimapStripMap,
onIsAtEndChange,
]);
}, [citationPositioning, listRef, minimapItems, minimapStripMap, onIsAtEndChange]);
useEffect(() => {
const frame = requestAnimationFrame(handleScroll);