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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

* chore(core): drop the scroll-offset comment, the comment-share ratchet may only fall

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-11-05 04:59:44 +00:00
committed by GitHub
co-authored by Claude Sonnet 5.5
parent 4ba47aaa12
commit aa34cffe4b
5 changed files with 56 additions and 32 deletions
@@ -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<HTMLElement, [number, number]>([
[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();
@@ -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<HTMLElement>("*")]
.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);
}
@@ -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;
@@ -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<string, KnownBug>([
["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],
@@ -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<string, KnownBug>([
[
"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",
{