TypeScript
fix(web): the composer rests on scroll when a thread opens above its end (#15025)
tiliakoosc13d058b91ff
diff --git a/apps/web/src/components/chat/timelineScrollAnchoring.test.tsx b/apps/web/src/components/chat/timelineScrollAnchoring.test.tsxindex 6300a803389..d868ef83f8e 100644--- a/apps/web/src/components/chat/timelineScrollAnchoring.test.tsx+++ b/apps/web/src/components/chat/timelineScrollAnchoring.test.tsx@@ -57,7 +57,33 @@ describe("timelineContentOverflowsViewport", () => {inset,),).toBe(false);+ expect(+ timelineContentOverflowsViewport(+ buildState({ positions: [0, Number.NaN], sizes: [200] }),+ inset,+ ),+ ).toBe(false);});++ it.each([+ { measurement: "missing", sizes: [200] },+ { measurement: "NaN", sizes: [200, Number.NaN] },+ ])(+ "reports overflow with a $measurement tail size without inventing anchor metrics",+ ({ sizes }) => {+ const state = buildState({ positions: [0, 900], sizes });+ expect(timelineContentOverflowsViewport(state, inset)).toBe(true);+ expect(getRowBottom(state, 1)).toBeNull();+ expect(+ getAnchoredTurnMetrics({+ state,+ anchorIndex: 0,+ composerOverlayHeight: 100,+ anchorOffset: 24,+ }),+ ).toBeNull();+ },+ );});describe("timeline scroll anchoring", () => {diff --git a/apps/web/src/components/chat/timelineScrollAnchoring.ts b/apps/web/src/components/chat/timelineScrollAnchoring.tsindex 74b04e10b95..d06b56a52eb 100644--- a/apps/web/src/components/chat/timelineScrollAnchoring.ts+++ b/apps/web/src/components/chat/timelineScrollAnchoring.ts@@ -75,7 +75,7 @@ export function getRowBottom(state: TimelineListMeasurementState, index: number)/*** The list's own content length includes the composer inset spacer, so this- * measures from the last row instead. Unknown row geometry or an unmeasured+ * measures from the last row instead. Unknown row positions or an unmeasured* viewport counts as fitting.*/export function timelineContentOverflowsViewport(@@ -89,7 +89,12 @@ export function timelineContentOverflowsViewport(if (typeof scrollLength !== "number" || !Number.isFinite(scrollLength) || scrollLength <= 0) {return false;}- const lastBottom = getRowBottom(state, state.data.length - 1);+ const lastIndex = state.data.length - 1;+ // Overflow can use an unmeasured tail's lower bound; anchored-turn metrics need its height.+ const lastTop = state.positionAtIndex(lastIndex);+ const lastBottom =+ getRowBottom(state, lastIndex) ??+ (typeof lastTop === "number" && Number.isFinite(lastTop) ? lastTop + 1 : null);if (lastBottom === null) {return false;}