fix(webui): preserve semantic history anchors

This commit is contained in:
Xubin Ren
2026-08-27 10:45:40 +08:00
parent 6a3f53a917
commit d7d03b25ef
3 changed files with 27 additions and 8 deletions
+11 -1
View File
@@ -1521,8 +1521,18 @@ describe("ThreadViewport", () => {
dispatchUserScroll(scroller);
});
const replacement = anchor.cloneNode(true) as HTMLElement;
anchor.replaceWith(replacement);
anchorDocumentTop += 180;
scrollHeight += 180;
Object.defineProperty(replacement, "getBoundingClientRect", {
configurable: true,
value: () => DOMRect.fromRect({
y: anchorDocumentTop - scroller.scrollTop,
width: 800,
height: 40,
}),
});
const content = screen.getByTestId("thread-message-region").firstElementChild;
const observer = resizeObserver.observers.find((candidate) =>
content ? candidate.elements.includes(content) : false,
@@ -1533,7 +1543,7 @@ describe("ThreadViewport", () => {
});
expect(scroller.scrollTop).toBe(260);
expect(anchor.getBoundingClientRect().top).toBe(120);
expect(replacement.getBoundingClientRect().top).toBe(120);
} finally {
resizeObserver.restore();
}