Skip to content

Commit 32d5bf1

Browse files
committed
fix(web): the composer rests on scroll when a thread opens above its end
An unmeasured last row made the overflow check report "fits", so the composer never rested. Its estimated top now counts as a lower bound.
1 parent 9333509 commit 32d5bf1

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,46 @@ describe("timelineContentOverflowsViewport", () => {
5858
),
5959
).toBe(false);
6060
});
61+
62+
it("counts an unmeasured last row past the viewport as overflowing", () => {
63+
// A thread reopened above its end: the tail has an estimated position but no size yet.
64+
const unmeasuredTail = [200, Number.NaN];
65+
expect(
66+
timelineContentOverflowsViewport(
67+
buildState({ positions: [0, 900], sizes: unmeasuredTail }),
68+
inset,
69+
),
70+
).toBe(true);
71+
expect(
72+
timelineContentOverflowsViewport(buildState({ positions: [0, 900], sizes: [200] }), inset),
73+
).toBe(true);
74+
// A short thread keeps fitting until its last row is measured.
75+
expect(
76+
timelineContentOverflowsViewport(
77+
buildState({ positions: [0, 200], sizes: unmeasuredTail }),
78+
inset,
79+
),
80+
).toBe(false);
81+
expect(
82+
timelineContentOverflowsViewport(
83+
buildState({ positions: [0, Number.NaN], sizes: unmeasuredTail }),
84+
inset,
85+
),
86+
).toBe(false);
87+
});
88+
89+
it("keeps anchored-turn metrics unknown until the last row is measured", () => {
90+
const state = buildState({ positions: [0, 900], sizes: [200] });
91+
expect(timelineContentOverflowsViewport(state, inset)).toBe(true);
92+
expect(
93+
getAnchoredTurnMetrics({
94+
state,
95+
anchorIndex: 0,
96+
composerOverlayHeight: 100,
97+
anchorOffset: 24,
98+
}),
99+
).toBeNull();
100+
});
61101
});
62102

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

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export function getRowBottom(state: TimelineListMeasurementState, index: number)
7777
/**
7878
* Whether the timeline's real rows extend past the viewport left above the
7979
* composer. The list's own content length includes the composer inset
80-
* spacer, so this measures from the last row instead. Unknown row geometry
81-
* or an unmeasured viewport counts as fitting.
80+
* spacer, so this measures from the last row instead. A last row that is
81+
* positioned but not yet measured counts as at least 1px tall, so a thread
82+
* reopened above its unrendered end still overflows. Otherwise unknown row
83+
* geometry or an unmeasured viewport counts as fitting.
8284
*/
8385
export function timelineContentOverflowsViewport(
8486
state: TimelineListMeasurementState | undefined,
@@ -91,7 +93,12 @@ export function timelineContentOverflowsViewport(
9193
if (typeof scrollLength !== "number" || !Number.isFinite(scrollLength) || scrollLength <= 0) {
9294
return false;
9395
}
94-
const lastBottom = getRowBottom(state, state.data.length - 1);
96+
const lastIndex = state.data.length - 1;
97+
// Not in getRowBottom: anchored-turn metrics must stay unknown until the row is measured.
98+
const lastTop = state.positionAtIndex(lastIndex);
99+
const lastBottom =
100+
getRowBottom(state, lastIndex) ??
101+
(typeof lastTop === "number" && Number.isFinite(lastTop) ? lastTop + 1 : null);
95102
if (lastBottom === null) {
96103
return false;
97104
}

0 commit comments

Comments
 (0)