TypeScript
fix(web): show scroll-to-end as soon as the last message slips under the composer (#9280)
Julius Marmingec742edd46c5b
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 2bd86e0eb24..cadb8b3028b 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -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 thediff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.tsindex 60ec9a56f48..980a93a59bd 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts@@ -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 {diff --git a/apps/web/src/components/chat/MessagesTimeline.test.tsx b/apps/web/src/components/chat/MessagesTimeline.test.tsxindex 323dac4f111..1044a956bb6 100644--- a/apps/web/src/components/chat/MessagesTimeline.test.tsx+++ b/apps/web/src/components/chat/MessagesTimeline.test.tsx@@ -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);diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsxindex 167eb700f84..95f4b35f665 100644--- a/apps/web/src/components/chat/MessagesTimeline.tsx+++ b/apps/web/src/components/chat/MessagesTimeline.tsx@@ -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);