Skip to content

Commit aa34cff

Browse files
vanceingallsclaude
andauthored
fix(core): a scrolled list keeps its offset when blur moves the root (#7190)
* fix(core): a scrolled list keeps its offset when blur moves the root Chrome resets a scrolled container's offset when the root leaves or enters the document, so the first blurred frame of a fresh page or render worker drew the list at offset 0. Offsets are read at move time and put back before the re-seek, so a container that became scrollable after the scan is covered too. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test(engine): scroll-list is an ordinary outside case, not a pinned known bug The scroll offset now survives the root's move, so the three engine differential cases and the multi-worker render case expect blur on to equal blur off, and the measured constants for the old symptom go. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * chore(core): drop the scroll-offset comment, the comment-share ratchet may only fall Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 4ba47aa commit aa34cff

5 files changed

Lines changed: 56 additions & 32 deletions

File tree

‎packages/core/src/runtime/captureMotionBlur/index.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,55 @@ describe("wrapping", () => {
637637
expect(events).toEqual(["quiet:begin", "quiet:end:plain", "seek:0.5:true"]);
638638
});
639639

640+
it("keeps the offset of a scrolled container when the root moves in and out of the canvas", () => {
641+
installHtmlInCanvas();
642+
const { root, h } = movingHost();
643+
const list = document.createElement("div");
644+
const inner = document.createElement("div");
645+
list.append(inner);
646+
root.append(list);
647+
const offsets = new Map<HTMLElement, [number, number]>([
648+
[root, [0, 0]],
649+
[list, [0, 0]],
650+
[inner, [0, 0]],
651+
]);
652+
for (const [el] of offsets) {
653+
Object.defineProperties(el, {
654+
scrollLeft: {
655+
get: () => offsets.get(el)?.[0],
656+
set: (v: number) => offsets.set(el, [v, offsets.get(el)?.[1] ?? 0]),
657+
configurable: true,
658+
},
659+
scrollTop: {
660+
get: () => offsets.get(el)?.[1],
661+
set: (v: number) => offsets.set(el, [offsets.get(el)?.[0] ?? 0, v]),
662+
configurable: true,
663+
},
664+
});
665+
}
666+
const reset = () => {
667+
for (const el of offsets.keys()) offsets.set(el, [0, 0]);
668+
};
669+
initCaptureMotionBlur({
670+
...h,
671+
ignoreMutations: (write) => {
672+
write();
673+
reset();
674+
},
675+
});
676+
offsets.set(list, [12, 300]);
677+
offsets.set(inner, [0, 40]);
678+
void paintCaptureMotionBlur(0.5, PLAY);
679+
expect(root.parentElement?.tagName).toBe("CANVAS");
680+
expect(offsets.get(list)).toEqual([12, 300]);
681+
expect(offsets.get(inner)).toEqual([0, 40]);
682+
offsets.set(root, [0, 7]);
683+
expect(paintCaptureMotionBlur(0.5)).toBeNull();
684+
expect(root.parentElement).toBe(document.body);
685+
expect(offsets.get(list)).toEqual([12, 300]);
686+
expect(offsets.get(root)).toEqual([0, 7]);
687+
});
688+
640689
it("does not re-seek when there was nothing to unwrap", () => {
641690
installHtmlInCanvas();
642691
const { h } = movingHost();

‎packages/core/src/runtime/captureMotionBlur/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,14 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI
203203
let rendering = false;
204204

205205
function moveRootThenResync(move: () => void): void {
206+
const scrolled = [root, ...root.querySelectorAll<HTMLElement>("*")]
207+
.filter((el) => el.scrollLeft !== 0 || el.scrollTop !== 0)
208+
.map((el) => ({ el, left: el.scrollLeft, top: el.scrollTop }));
206209
(host.ignoreMutations ?? ((write: () => void) => write()))(move);
210+
for (const { el, left, top } of scrolled) {
211+
el.scrollLeft = left;
212+
el.scrollTop = top;
213+
}
207214
host.seek(host.now(), true);
208215
}
209216

‎packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export const MEASURED_RENDER_NOISE = 0;
99
export const MEASURED_RENDER_REWIND_MUTATION = 97.02;
1010

1111
// Worst-tile MAE of each pinned known bug, where it was pinned. A pin passes only within half to double of it.
12-
export const MEASURED_SCROLL_LOSS_FRESH_PAINT = 24.65;
1312
export const MEASURED_LABEL_EARLY_FRESH_PAINT = 54.3;
14-
export const MEASURED_SCROLL_LOSS_RENDER = 18.82;
1513
export const MEASURED_LABEL_EARLY_RENDER = 53.87;
1614

1715
export const MEASURED_INSIDE_NOISE = 10.993;

‎packages/engine/src/services/captureMotionBlur.differential.browser.test.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { FIXTURES, type BlurFixture } from "./__fixtures__/motionBlur/fixtures.j
2121
import {
2222
INVARIANTS,
2323
MEASURED_LABEL_EARLY_FRESH_PAINT,
24-
MEASURED_SCROLL_LOSS_FRESH_PAINT,
2524
} from "./__fixtures__/motionBlur/thresholds.js";
2625

2726
const FPS = 30;
@@ -38,11 +37,6 @@ interface KnownBug {
3837
measuredMae: number;
3938
}
4039

41-
const SCROLL_LOSS: KnownBug = {
42-
reason: "scroll-list loses its scroll offset on a fresh first paint",
43-
regionId: "list",
44-
measuredMae: MEASURED_SCROLL_LOSS_FRESH_PAINT,
45-
};
4640
const LABEL_EARLY: KnownBug = {
4741
reason: "callbacks shows its label B before the call that sets it",
4842
regionId: "label",
@@ -51,9 +45,6 @@ const LABEL_EARLY: KnownBug = {
5145

5246
/** Cases where blur on really differs from blur off today. They pin the symptom and fail once it is fixed. */
5347
const KNOWN_REAL_DIFFERENCES = new Map<string, KnownBug>([
54-
["outside:scroll-list@1", SCROLL_LOSS],
55-
["outside:[email protected]", SCROLL_LOSS],
56-
["outside:[email protected]", SCROLL_LOSS],
5748
["outside:[email protected]", LABEL_EARLY],
5849
["outside:[email protected]", LABEL_EARLY],
5950
["outside:[email protected]", LABEL_EARLY],

‎packages/producer/src/services/render/blurDifferential.integration.test.ts‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
import {
2727
INVARIANTS,
2828
MEASURED_LABEL_EARLY_RENDER,
29-
MEASURED_SCROLL_LOSS_RENDER,
3029
RENDER_OUTSIDE_MAX_MAE,
3130
} from "../../../../engine/src/services/__fixtures__/motionBlur/thresholds.js";
3231
import { createRenderJob, executeRenderJob } from "../renderOrchestrator.js";
@@ -81,14 +80,6 @@ function cssPx(f: BlurFixture, id: string, property: string): number {
8180
return Number(px);
8281
}
8382

84-
/** The element's box from its inline left, top, width and height. */
85-
const boxFromMarkup = (f: BlurFixture, id: string): Rect => ({
86-
x: cssPx(f, id, "left"),
87-
y: cssPx(f, id, "top"),
88-
width: cssPx(f, id, "width"),
89-
height: cssPx(f, id, "height"),
90-
});
91-
9283
/** 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. */
9384
function glyphFromMarkup(f: BlurFixture, id: string): Rect {
9485
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 {
10293
* appear and fails once it is fixed; the others only bound it, because it is a race.
10394
*/
10495
const KNOWN_REAL_DIFFERENCES = new Map<string, KnownBug>([
105-
[
106-
"scroll-list",
107-
{
108-
title:
109-
"scroll-list: any loss after a worker's first wrap stays inside #list (KNOWN BUG, flip lives in the engine differential)",
110-
reason: "scroll-list loses its scroll offset after a worker's first wrap",
111-
regionId: "list",
112-
region: (f) => boxFromMarkup(f, "list"),
113-
frames: (n) => n >= 28,
114-
measuredMae: MEASURED_SCROLL_LOSS_RENDER,
115-
},
116-
],
11796
[
11897
"callbacks",
11998
{

0 commit comments

Comments
 (0)