Skip to content

Commit b6f2bec

Browse files
vanceingallsclaude
andauthored
fix(core): a mover holding a fixed child stays sharp in the filter tier (#7292)
* fix(core): a mover holding a fixed child stays sharp in the filter tier Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(core): a fixed-child mover is skipped only on frames it is not already a containing block Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent f54b222 commit b6f2bec

5 files changed

Lines changed: 95 additions & 10 deletions

File tree

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { swallow } from "../diagnostics";
99
import { scanMovers, whileCallbacksMuted } from "./discover";
1010
import { planFilter, type FilterPlan } from "./filterPlan";
11-
import { readMoverFrames, shutterTimes } from "./frames";
11+
import { CONTENT_NODE_LIMIT, readMoverFrames, shutterTimes } from "./frames";
1212
import { createPoseReader } from "./pose";
1313
import type { CaptureMotionBlurHost, Config, Report, Tier } from "./tier";
1414

@@ -94,6 +94,31 @@ function aim(layer: Layer, plan: FilterPlan): void {
9494
layer.filter.setAttribute("height", h.toFixed(1));
9595
}
9696

97+
function holdsFixedChild(el: HTMLElement): boolean {
98+
const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT);
99+
for (let n = 0; n < CONTENT_NODE_LIMIT && walker.nextNode(); n++) {
100+
if (getComputedStyle(walker.currentNode as Element).position === "fixed") return true;
101+
}
102+
return false;
103+
}
104+
105+
const CONTAINING_BLOCK_PROPERTIES = [
106+
"transform",
107+
"translate",
108+
"rotate",
109+
"scale",
110+
"perspective",
111+
] as const;
112+
113+
function makesContainingBlock(el: HTMLElement): boolean {
114+
const style = getComputedStyle(el);
115+
return (
116+
CONTAINING_BLOCK_PROPERTIES.some((p) => (style[p] || "none") !== "none") ||
117+
/transform|perspective|filter/.test(style.willChange ?? "") ||
118+
/paint|layout|strict|content/.test(style.contain ?? "")
119+
);
120+
}
121+
97122
const strip = (el: HTMLElement): string => el.style.filter.replace(OWN, "").trim();
98123

99124
export function createFilterTier(
@@ -109,6 +134,7 @@ export function createFilterTier(
109134
const readSeek = (t: number): void => host.seek(t, !readEvents);
110135
let defs: SVGSVGElement | null = null;
111136
let movers: HTMLElement[] = [];
137+
let fixedHolders = new Set<HTMLElement>();
112138
let pads = new Map<HTMLElement, number>();
113139
let reader: ReturnType<typeof createPoseReader> | null = null;
114140
let scanned: unknown;
@@ -136,6 +162,7 @@ export function createFilterTier(
136162
});
137163
readEvents = found.readEvents;
138164
movers = found.movers;
165+
fixedHolders = new Set(movers.filter(holdsFixedChild));
139166
pads = found.pads;
140167
reader = createPoseReader(root, found.dynamic);
141168
scanMs = Math.round(performance.now() - s0);
@@ -201,6 +228,7 @@ export function createFilterTier(
201228
const plans: Array<[HTMLElement, FilterPlan]> = [];
202229
read.els.forEach((el, i) => {
203230
const frame = read.frames[i];
231+
if (fixedHolders.has(el) && !makesContainingBlock(el)) return;
204232
const plan = frame && planFilter(frame, pads.get(el) ?? 0, width);
205233
if (plan) plans.push([el, plan]);
206234
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
translate,
1212
} from "./pose";
1313

14-
const CONTENT_NODE_LIMIT = 256;
14+
export const CONTENT_NODE_LIMIT = 256;
1515

1616
type Box = [number, number, number, number];
1717
type PoseReader = ReturnType<typeof createPoseReader>;

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,71 @@ describe("filter fallback", () => {
21052105
expect(el.style.filter).toBe("drop-shadow(0px 0px 4px red)");
21062106
});
21072107

2108+
describe("a mover holding a fixed child", () => {
2109+
/** A mover that slides through `left`, 300 px over the composition, holding a fixed badge. */
2110+
function leftMoverWithBadge(root: HTMLElement) {
2111+
const el = root.appendChild(document.createElement("div"));
2112+
el.id = "card";
2113+
const badge = el.appendChild(document.createElement("div"));
2114+
badge.style.position = "fixed";
2115+
const left = () => parseFloat(el.style.left) || 0;
2116+
for (const [k, v] of Object.entries({ offsetWidth: 10, offsetHeight: 10, offsetTop: 0 })) {
2117+
Object.defineProperty(el, k, { value: v, configurable: true });
2118+
}
2119+
Object.defineProperty(el, "offsetParent", { value: root, configurable: true });
2120+
Object.defineProperty(el, "offsetLeft", { get: left, configurable: true });
2121+
el.getBoundingClientRect = () =>
2122+
({
2123+
left: left(),
2124+
top: 0,
2125+
right: left() + 10,
2126+
bottom: 10,
2127+
width: 10,
2128+
height: 10,
2129+
}) as DOMRect;
2130+
return el;
2131+
}
2132+
2133+
it("stays sharp when it moves through left, while the other movers blur", () => {
2134+
const { root, el: other, h } = movingHost();
2135+
const card = leftMoverWithBadge(root);
2136+
const slide = h.seek;
2137+
h.seek = vi.fn((t: number, quiet: boolean) => {
2138+
slide(t, quiet);
2139+
card.style.left = `${300 * t}px`;
2140+
});
2141+
initCaptureMotionBlur(h);
2142+
void paintCaptureMotionBlur(0.5, PLAY);
2143+
expect(win.__hfMotionBlur?.report().moverNames).toEqual(["div#slider", "div#card"]);
2144+
expect(card.style.filter).toBe("");
2145+
expect(other.style.filter).toMatch(/url\("?#hf-mb-\d+"?\)/);
2146+
});
2147+
2148+
it("still blurs when a transform already made it the containing block", () => {
2149+
const { el, h } = movingHost();
2150+
el.append(Object.assign(document.createElement("div"), { style: "position: fixed" }));
2151+
initCaptureMotionBlur(h);
2152+
void paintCaptureMotionBlur(0.5, PLAY);
2153+
expect(el.style.filter).toMatch(/url\("?#hf-mb-0"?\)/);
2154+
});
2155+
2156+
it("blurs on the frames where a transform is set, and not on those where it is none", () => {
2157+
const { root, h } = movingHost();
2158+
const card = leftMoverWithBadge(root);
2159+
const slide = h.seek;
2160+
h.seek = vi.fn((t: number, quiet: boolean) => {
2161+
slide(t, quiet);
2162+
card.style.left = `${300 * t}px`;
2163+
card.style.transform = t >= 0.5 ? "matrix(1, 0, 0, 1, 0, 0)" : "";
2164+
});
2165+
initCaptureMotionBlur(h);
2166+
void paintCaptureMotionBlur(0.3, PLAY);
2167+
expect(card.style.filter).toBe("");
2168+
void paintCaptureMotionBlur(0.7, PLAY);
2169+
expect(card.style.filter).toMatch(/url\("?#hf-mb-\d+"?\)/);
2170+
});
2171+
});
2172+
21082173
it("reads poses with callbacks off when callbacks move no mover in the filter tier too", () => {
21092174
const { h } = movingHost({
21102175
"data-motion-blur": "on",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const SWEEP_SYMPTOMS = {
5656
D_FILTER: 107.66,
5757
E: 27.6,
5858
F_CAPTURE: 40.62,
59-
F_FILTER: 126.54,
6059
H: 135.67,
6160
J: 25.79,
6261
K: MEASURED_ORACLE_SMALLEST_SYMPTOM,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ const CASES: readonly SweepCase[] = [
158158
tier: "filter",
159159
frame: 11,
160160
check: "outside",
161-
bug: {
162-
finding: "F",
163-
reason:
164-
"the blur filter makes the mover a containing block, so its fixed child jumps into it",
165-
regions: [rect(10, 10, 60, 30), trail(152)],
166-
measuredMae: S.F_FILTER,
167-
},
168161
},
169162
{
170163
fixture: "body-child-selector",

0 commit comments

Comments
 (0)