From e1ca490d73ac6b0cbcb2202267c2201f6c4b0151 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sat, 24 Oct 2026 23:49:53 +0800 Subject: [PATCH] fix(webui): retain reading anchors through lazy Markdown layout --- webui/browser/history-boundary.spec.ts | 29 +++++++++++++++++++ .../src/components/thread/ThreadViewport.tsx | 8 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/webui/browser/history-boundary.spec.ts b/webui/browser/history-boundary.spec.ts index 0553d0d74..c379a341a 100644 --- a/webui/browser/history-boundary.spec.ts +++ b/webui/browser/history-boundary.spec.ts @@ -491,6 +491,35 @@ test("reduced-motion failure keeps its functional 48px slot and retry until natu 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((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 }) => { const history = await installHistory(page); history.useFastResponse(true); diff --git a/webui/src/components/thread/ThreadViewport.tsx b/webui/src/components/thread/ThreadViewport.tsx index 1fdd921ac..60ac120d3 100644 --- a/webui/src/components/thread/ThreadViewport.tsx +++ b/webui/src/components/thread/ThreadViewport.tsx @@ -88,6 +88,7 @@ export const HISTORY_WINDOW_INCREMENT = 120; interface HistoryScrollAnchor { key: string; offsetTop: number; + scrollTop: number; } const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]"; @@ -458,6 +459,7 @@ export const ThreadViewport = forwardRef