Skip to content

Commit c13d058

Browse files
fix(web): the composer rests on scroll when a thread opens above its end (pingdotgg#15025)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 29badb4 commit c13d058

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,33 @@ describe("timelineContentOverflowsViewport", () => {
5757
inset,
5858
),
5959
).toBe(false);
60+
expect(
61+
timelineContentOverflowsViewport(
62+
buildState({ positions: [0, Number.NaN], sizes: [200] }),
63+
inset,
64+
),
65+
).toBe(false);
6066
});
67+
68+
it.each([
69+
{ measurement: "missing", sizes: [200] },
70+
{ measurement: "NaN", sizes: [200, Number.NaN] },
71+
])(
72+
"reports overflow with a $measurement tail size without inventing anchor metrics",
73+
({ sizes }) => {
74+
const state = buildState({ positions: [0, 900], sizes });
75+
expect(timelineContentOverflowsViewport(state, inset)).toBe(true);
76+
expect(getRowBottom(state, 1)).toBeNull();
77+
expect(
78+
getAnchoredTurnMetrics({
79+
state,
80+
anchorIndex: 0,
81+
composerOverlayHeight: 100,
82+
anchorOffset: 24,
83+
}),
84+
).toBeNull();
85+
},
86+
);
6187
});
6288

6389
describe("timeline scroll anchoring", () => {

‎apps/web/src/components/chat/timelineScrollAnchoring.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function getRowBottom(state: TimelineListMeasurementState, index: number)
7575

7676
/**
7777
* The list's own content length includes the composer inset spacer, so this
78-
* measures from the last row instead. Unknown row geometry or an unmeasured
78+
* measures from the last row instead. Unknown row positions or an unmeasured
7979
* viewport counts as fitting.
8080
*/
8181
export function timelineContentOverflowsViewport(
@@ -89,7 +89,12 @@ export function timelineContentOverflowsViewport(
8989
if (typeof scrollLength !== "number" || !Number.isFinite(scrollLength) || scrollLength <= 0) {
9090
return false;
9191
}
92-
const lastBottom = getRowBottom(state, state.data.length - 1);
92+
const lastIndex = state.data.length - 1;
93+
// Overflow can use an unmeasured tail's lower bound; anchored-turn metrics need its height.
94+
const lastTop = state.positionAtIndex(lastIndex);
95+
const lastBottom =
96+
getRowBottom(state, lastIndex) ??
97+
(typeof lastTop === "number" && Number.isFinite(lastTop) ? lastTop + 1 : null);
9398
if (lastBottom === null) {
9499
return false;
95100
}

0 commit comments

Comments
 (0)