fix(webui): apply latest offscreen visibility notification (NAN-333)

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-22 15:08:29 +08:00
1 parent be43d2a5f8
commit 872a83340d
2 files changed
+10 -2

No files matched your search

@@ -612,7 +612,8 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
useEffect(() => {
const element = elementRef.current;
if (!element || !deferOffscreenRender || interacted || typeof IntersectionObserver === "undefined") return;
const observer = new IntersectionObserver(([entry]) => {
const observer = new IntersectionObserver((entries) => {
const entry = entries[entries.length - 1];
if (!entry) return;
if (!entry.isIntersecting) {
const height = element.getBoundingClientRect().height;
+8 -1
View File
@@ -226,7 +226,7 @@ describe("ThreadMessages", () => {
expect(screen.getByText("latest answer").closest(".thread-render-unit")).toBeNull();
});
it("recycles offscreen historical content while preserving its measured space", () => {
it("recycles historical content using the latest intersection in each batch", () => {
let notify: (entries: Array<{ isIntersecting: boolean }>) => void = () => {};
vi.stubGlobal("IntersectionObserver", class {
constructor(callback: typeof notify) { notify = callback; }
@@ -243,8 +243,15 @@ describe("ThreadMessages", () => {
act(() => notify([{ isIntersecting: false }]));
expect(unit.style.height).toBe("240px");
expect(unit.childElementCount).toBe(0);
act(() => notify([{ isIntersecting: false }, { isIntersecting: true }]));
expect(screen.getByText("historical answer")).toBeVisible();
expect(unit.style.height).toBe("");
act(() => notify([{ isIntersecting: true }, { isIntersecting: false }]));
expect(unit.style.height).toBe("240px");
expect(unit.childElementCount).toBe(0);
act(() => notify([{ isIntersecting: true }]));
expect(screen.getByText("historical answer")).toBeVisible();
expect(unit.style.height).toBe("");
expect(view.container).toHaveTextContent("old question");
});