fix(webui): retain reading anchors through lazy Markdown layout
This commit is contained in:
1 parent
b15bd455e3
commit
e1ca490d73
2 files changed
+36
-1
No files matched your search
@@ -491,6 +491,35 @@ test("reduced-motion failure keeps its functional 48px slot and retry until natu
|
|||||||
await expect(exhausted).toHaveCount(0);
|
await expect(exhausted).toHaveCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("keeps the reading anchor when lazy Markdown loads after a fast prepend", async ({ page }) => {
|
||||||
|
let releaseMarkdown = () => {};
|
||||||
|
const ready = new Promise<void>((resolve) => { releaseMarkdown = resolve; });
|
||||||
|
await page.route("**/MarkdownTextRenderer.tsx*", async (route) => {
|
||||||
|
await ready;
|
||||||
|
await route.continue();
|
||||||
|
});
|
||||||
|
const history = await installHistory(page);
|
||||||
|
history.useFastResponse(true);
|
||||||
|
await page.clock.install({ time: new Date("2026-01-01T00:00:00Z") });
|
||||||
|
const { body, header } = await openSettledHistory(page);
|
||||||
|
await positionAtTop(body);
|
||||||
|
await body.hover();
|
||||||
|
await page.clock.pauseAt(new Date("2026-01-01T01:00:00Z"));
|
||||||
|
await page.mouse.wheel(0, -120);
|
||||||
|
await expect.poll(() => history.reads.length).toBe(1);
|
||||||
|
await expect(header).toHaveAttribute("data-state", "loading");
|
||||||
|
const readingTop = await anchorTop(body, "Question 40");
|
||||||
|
history.releaseFastResponse();
|
||||||
|
await expect(body.getByText("Question 28", { exact: true })).toBeAttached();
|
||||||
|
await expectAnchorCoordinate(body, "Question 40", readingTop);
|
||||||
|
|
||||||
|
releaseMarkdown();
|
||||||
|
await page.clock.resume();
|
||||||
|
await expect(body.locator('[data-thread-display-unit="a40"] p')).toHaveCount(8);
|
||||||
|
await stableLayout(body);
|
||||||
|
await expectAnchorCoordinate(body, "Question 40", readingTop);
|
||||||
|
});
|
||||||
|
|
||||||
for (const elapsedMs of [0, 80]) test(`fast responses reclaim completed slots and keep the next boundary loading${elapsedMs ? " during spring travel" : ""}`, async ({ page }) => {
|
for (const elapsedMs of [0, 80]) test(`fast responses reclaim completed slots and keep the next boundary loading${elapsedMs ? " during spring travel" : ""}`, async ({ page }) => {
|
||||||
const history = await installHistory(page);
|
const history = await installHistory(page);
|
||||||
history.useFastResponse(true);
|
history.useFastResponse(true);
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export const HISTORY_WINDOW_INCREMENT = 120;
|
|||||||
interface HistoryScrollAnchor {
|
interface HistoryScrollAnchor {
|
||||||
key: string;
|
key: string;
|
||||||
offsetTop: number;
|
offsetTop: number;
|
||||||
|
scrollTop: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]";
|
const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]";
|
||||||
@@ -458,6 +459,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
}
|
}
|
||||||
historyScrollAnchorRef.current = {
|
historyScrollAnchorRef.current = {
|
||||||
key,
|
key,
|
||||||
|
scrollTop: scroller.scrollTop,
|
||||||
// Normalize out the reveal lease, even when reading above its inline slot.
|
// Normalize out the reveal lease, even when reading above its inline slot.
|
||||||
offsetTop: element.getBoundingClientRect().top - viewport.top
|
offsetTop: element.getBoundingClientRect().top - viewport.top
|
||||||
- (historySlotRef.current ? HISTORY_HOLD_PX : 0),
|
- (historySlotRef.current ? HISTORY_HOLD_PX : 0),
|
||||||
@@ -487,6 +489,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
const maxScrollTop = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|
const maxScrollTop = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|
||||||
const nextTop = Math.min(maxScrollTop, Math.max(0, scroller.scrollTop + delta));
|
const nextTop = Math.min(maxScrollTop, Math.max(0, scroller.scrollTop + delta));
|
||||||
threadMotionRef.current?.jumpTo(nextTop);
|
threadMotionRef.current?.jumpTo(nextTop);
|
||||||
|
anchor.scrollTop = scroller.scrollTop;
|
||||||
return true;
|
return true;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -910,7 +913,10 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
current === logicallyAtBottom ? current : logicallyAtBottom,
|
current === logicallyAtBottom ? current : logicallyAtBottom,
|
||||||
);
|
);
|
||||||
if (owner === "user") {
|
if (owner === "user") {
|
||||||
captureHistoryScrollAnchor();
|
// Restoring the anchor also emits scroll. Keep that reading position
|
||||||
|
// through lazy content resizing instead of selecting a prepended row.
|
||||||
|
const anchor = historyScrollAnchorRef.current;
|
||||||
|
if (!anchor || el.scrollTop !== anchor.scrollTop) captureHistoryScrollAnchor();
|
||||||
if (allowHistoryLoad) maybeLoadEarlierFromScroll();
|
if (allowHistoryLoad) maybeLoadEarlierFromScroll();
|
||||||
if (allowHistoryLoad && distance < HISTORY_PREFETCH_MIN_PX
|
if (allowHistoryLoad && distance < HISTORY_PREFETCH_MIN_PX
|
||||||
&& historyWindow?.hasMoreAfter && !navigation?.loading && !navigation?.error) navigation?.newer();
|
&& historyWindow?.hasMoreAfter && !navigation?.loading && !navigation?.error) navigation?.newer();
|
||||||
|
|||||||
Reference in new issue
Block a user