fix(webui): apply latest offscreen visibility notification (NAN-333)
This commit is contained in:
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(() => {
|
useEffect(() => {
|
||||||
const element = elementRef.current;
|
const element = elementRef.current;
|
||||||
if (!element || !deferOffscreenRender || interacted || typeof IntersectionObserver === "undefined") return;
|
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) return;
|
||||||
if (!entry.isIntersecting) {
|
if (!entry.isIntersecting) {
|
||||||
const height = element.getBoundingClientRect().height;
|
const height = element.getBoundingClientRect().height;
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ describe("ThreadMessages", () => {
|
|||||||
expect(screen.getByText("latest answer").closest(".thread-render-unit")).toBeNull();
|
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 = () => {};
|
let notify: (entries: Array<{ isIntersecting: boolean }>) => void = () => {};
|
||||||
vi.stubGlobal("IntersectionObserver", class {
|
vi.stubGlobal("IntersectionObserver", class {
|
||||||
constructor(callback: typeof notify) { notify = callback; }
|
constructor(callback: typeof notify) { notify = callback; }
|
||||||
@@ -243,8 +243,15 @@ describe("ThreadMessages", () => {
|
|||||||
act(() => notify([{ isIntersecting: false }]));
|
act(() => notify([{ isIntersecting: false }]));
|
||||||
expect(unit.style.height).toBe("240px");
|
expect(unit.style.height).toBe("240px");
|
||||||
expect(unit.childElementCount).toBe(0);
|
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 }]));
|
act(() => notify([{ isIntersecting: true }]));
|
||||||
expect(screen.getByText("historical answer")).toBeVisible();
|
expect(screen.getByText("historical answer")).toBeVisible();
|
||||||
|
expect(unit.style.height).toBe("");
|
||||||
expect(view.container).toHaveTextContent("old question");
|
expect(view.container).toHaveTextContent("old question");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user