diff --git a/packages/core/src/runtime/captureMotionBlur/index.test.ts b/packages/core/src/runtime/captureMotionBlur/index.test.ts index ee62e308b1..b053ec3b2a 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.test.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.test.ts @@ -637,6 +637,55 @@ describe("wrapping", () => { expect(events).toEqual(["quiet:begin", "quiet:end:plain", "seek:0.5:true"]); }); + it("keeps the offset of a scrolled container when the root moves in and out of the canvas", () => { + installHtmlInCanvas(); + const { root, h } = movingHost(); + const list = document.createElement("div"); + const inner = document.createElement("div"); + list.append(inner); + root.append(list); + const offsets = new Map([ + [root, [0, 0]], + [list, [0, 0]], + [inner, [0, 0]], + ]); + for (const [el] of offsets) { + Object.defineProperties(el, { + scrollLeft: { + get: () => offsets.get(el)?.[0], + set: (v: number) => offsets.set(el, [v, offsets.get(el)?.[1] ?? 0]), + configurable: true, + }, + scrollTop: { + get: () => offsets.get(el)?.[1], + set: (v: number) => offsets.set(el, [offsets.get(el)?.[0] ?? 0, v]), + configurable: true, + }, + }); + } + const reset = () => { + for (const el of offsets.keys()) offsets.set(el, [0, 0]); + }; + initCaptureMotionBlur({ + ...h, + ignoreMutations: (write) => { + write(); + reset(); + }, + }); + offsets.set(list, [12, 300]); + offsets.set(inner, [0, 40]); + void paintCaptureMotionBlur(0.5, PLAY); + expect(root.parentElement?.tagName).toBe("CANVAS"); + expect(offsets.get(list)).toEqual([12, 300]); + expect(offsets.get(inner)).toEqual([0, 40]); + offsets.set(root, [0, 7]); + expect(paintCaptureMotionBlur(0.5)).toBeNull(); + expect(root.parentElement).toBe(document.body); + expect(offsets.get(list)).toEqual([12, 300]); + expect(offsets.get(root)).toEqual([0, 7]); + }); + it("does not re-seek when there was nothing to unwrap", () => { installHtmlInCanvas(); const { h } = movingHost(); diff --git a/packages/core/src/runtime/captureMotionBlur/index.ts b/packages/core/src/runtime/captureMotionBlur/index.ts index e7fbd10b44..10924f1c87 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.ts @@ -203,7 +203,14 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI let rendering = false; function moveRootThenResync(move: () => void): void { + const scrolled = [root, ...root.querySelectorAll("*")] + .filter((el) => el.scrollLeft !== 0 || el.scrollTop !== 0) + .map((el) => ({ el, left: el.scrollLeft, top: el.scrollTop })); (host.ignoreMutations ?? ((write: () => void) => write()))(move); + for (const { el, left, top } of scrolled) { + el.scrollLeft = left; + el.scrollTop = top; + } host.seek(host.now(), true); } diff --git a/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts b/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts index 32879e31b4..a64e573c6b 100644 --- a/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts +++ b/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts @@ -9,9 +9,7 @@ export const MEASURED_RENDER_NOISE = 0; export const MEASURED_RENDER_REWIND_MUTATION = 97.02; // Worst-tile MAE of each pinned known bug, where it was pinned. A pin passes only within half to double of it. -export const MEASURED_SCROLL_LOSS_FRESH_PAINT = 24.65; export const MEASURED_LABEL_EARLY_FRESH_PAINT = 54.3; -export const MEASURED_SCROLL_LOSS_RENDER = 18.82; export const MEASURED_LABEL_EARLY_RENDER = 53.87; export const MEASURED_INSIDE_NOISE = 10.993; diff --git a/packages/engine/src/services/captureMotionBlur.differential.browser.test.ts b/packages/engine/src/services/captureMotionBlur.differential.browser.test.ts index e9fdbecca7..5fcb34c62b 100644 --- a/packages/engine/src/services/captureMotionBlur.differential.browser.test.ts +++ b/packages/engine/src/services/captureMotionBlur.differential.browser.test.ts @@ -21,7 +21,6 @@ import { FIXTURES, type BlurFixture } from "./__fixtures__/motionBlur/fixtures.j import { INVARIANTS, MEASURED_LABEL_EARLY_FRESH_PAINT, - MEASURED_SCROLL_LOSS_FRESH_PAINT, } from "./__fixtures__/motionBlur/thresholds.js"; const FPS = 30; @@ -38,11 +37,6 @@ interface KnownBug { measuredMae: number; } -const SCROLL_LOSS: KnownBug = { - reason: "scroll-list loses its scroll offset on a fresh first paint", - regionId: "list", - measuredMae: MEASURED_SCROLL_LOSS_FRESH_PAINT, -}; const LABEL_EARLY: KnownBug = { reason: "callbacks shows its label B before the call that sets it", regionId: "label", @@ -51,9 +45,6 @@ const LABEL_EARLY: KnownBug = { /** Cases where blur on really differs from blur off today. They pin the symptom and fail once it is fixed. */ const KNOWN_REAL_DIFFERENCES = new Map([ - ["outside:scroll-list@1", SCROLL_LOSS], - ["outside:scroll-list@1.2", SCROLL_LOSS], - ["outside:scroll-list@1.5", SCROLL_LOSS], ["outside:callbacks@0.2", LABEL_EARLY], ["outside:callbacks@0.3", LABEL_EARLY], ["outside:callbacks@0.4", LABEL_EARLY], diff --git a/packages/producer/src/services/render/blurDifferential.integration.test.ts b/packages/producer/src/services/render/blurDifferential.integration.test.ts index a2fec2d245..cc658bb8bc 100644 --- a/packages/producer/src/services/render/blurDifferential.integration.test.ts +++ b/packages/producer/src/services/render/blurDifferential.integration.test.ts @@ -26,7 +26,6 @@ import { import { INVARIANTS, MEASURED_LABEL_EARLY_RENDER, - MEASURED_SCROLL_LOSS_RENDER, RENDER_OUTSIDE_MAX_MAE, } from "../../../../engine/src/services/__fixtures__/motionBlur/thresholds.js"; import { createRenderJob, executeRenderJob } from "../renderOrchestrator.js"; @@ -81,14 +80,6 @@ function cssPx(f: BlurFixture, id: string, property: string): number { return Number(px); } -/** The element's box from its inline left, top, width and height. */ -const boxFromMarkup = (f: BlurFixture, id: string): Rect => ({ - x: cssPx(f, id, "left"), - y: cssPx(f, id, "top"), - width: cssPx(f, id, "width"), - height: cssPx(f, id, "height"), -}); - /** One glyph of the element's text: left and top from its inline style; a monospace advance is 0.6 em, a line 1.2 em. */ function glyphFromMarkup(f: BlurFixture, id: string): Rect { const size = Number(/font:\s*\d+\s+([\d.]+)px/.exec(markupOf(f, id))?.[1]); @@ -102,18 +93,6 @@ function glyphFromMarkup(f: BlurFixture, id: string): Rect { * appear and fails once it is fixed; the others only bound it, because it is a race. */ const KNOWN_REAL_DIFFERENCES = new Map([ - [ - "scroll-list", - { - title: - "scroll-list: any loss after a worker's first wrap stays inside #list (KNOWN BUG, flip lives in the engine differential)", - reason: "scroll-list loses its scroll offset after a worker's first wrap", - regionId: "list", - region: (f) => boxFromMarkup(f, "list"), - frames: (n) => n >= 28, - measuredMae: MEASURED_SCROLL_LOSS_RENDER, - }, - ], [ "callbacks", {