Skip to content

Commit 5a95211

Browse files
authored
fix(cli): apply the canvas/video pixel-hash carve-out to img (#3865)
## What `check`'s sweep_static guard false-positives on a composition that swaps between equal-size, equal-position opaque `<img>` elements — a common authoring pattern for revealing frame N of a still sequence from a paused GSAP cursor. The render itself is correct; only `check`'s verdict is wrong. ## Why The sweep guard fingerprints every visible element's box + opacity + font-variation-settings per seeked sample. That's deliberately blind to pixel-only motion (a canvas repainting, a video playing) with no element moving, so an existing carve-out downsamples each visible `canvas`/`video` to 8x8 and folds its pixels into the fingerprint specifically to catch that class of motion. That carve-out's element selector (`root.querySelectorAll("canvas, video")`) never included `img`. An img src/visibility swap between equal-size opaque images moves zero geometry and zero opacity, so it stays outside both the base fingerprint and the pixel-hash carve-out — the whole-run fingerprint reads byte-identical across every sample and `sweep_static` fires on an animating composition. ## How Widened the selector to `canvas, video, img`. No other change was needed: `mediaPixelHash` already handles `img` correctly — `drawImage` accepts any `CanvasImageSource`, and its width/height detection already falls back to the element's bounding rect the same way it does for `canvas`/`video`. **Scope note:** this repo has an open PR (#3707) touching the same function (`collectLayoutGeometry` in this same file) for a different, unrelated bug (text/counter fingerprinting). This change is deliberately isolated to the `canvas, video` → `canvas, video, img` selector line and a new comment above it — verified against #3707's current diff that neither touches this exact loop, so the two PRs shouldn't conflict regardless of merge order. ## Testing Added a test mirroring the existing "changes the sweep fingerprint when visible video pixels advance" test, using an `<img>` element instead of `<video>` with the same pixel-mock approach. - `bunx tsc --noEmit` in `packages/cli` — clean - `bunx oxlint` / `bunx oxfmt --write` on changed files — clean, no changes needed - Full CLI suite (excluding known-broken browser-launch tests unrelated to this change): 217 test files / 3023 tests passing One local-environment caveat, disclosed for transparency: `layout-audit.browser.test.ts` (the file the new test lives in) can't execute in my local sandbox — it fails identically with or without this change (`No such built-in module: node:`, a happy-dom + Vite externalization issue affecting every test file in this repo that imports Node builtins at the top under `@vitest-environment happy-dom`, not specific to this change). I verified the new test's logic and mocking approach are structurally identical to the existing, CI-passing video test it's modeled on, and will confirm via this PR's CI run rather than a local one. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 9c84277 commit 5a95211

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎packages/cli/src/commands/layout-audit.browser.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,13 @@
16891689
axes && axes !== "normal" ? axes : ""
16901690
}`;
16911691
});
1692-
for (const media of root.querySelectorAll("canvas, video")) {
1692+
// img shares the same pixel-only-motion blind spot as canvas/video: an
1693+
// equal-size, equal-position opaque src/visibility swap moves no
1694+
// geometry and no opacity. mediaPixelHash already handles it generically
1695+
// (drawImage accepts any CanvasImageSource; width/height fall back to
1696+
// rect.width/height same as canvas/video), so only the element selector
1697+
// needed widening.
1698+
for (const media of root.querySelectorAll("canvas, video, img")) {
16931699
if (!isVisibleElement(media)) continue;
16941700
parts.push(`p:${mediaPixelHash(media)}`);
16951701
}

‎packages/cli/src/commands/layout-audit.browser.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ describe("layout-audit.browser", () => {
6363
expect(after).not.toBe(before);
6464
});
6565

66+
// PRINFRA-666: an equal-size, equal-position opaque <img> src/visibility
67+
// swap (the authoring pattern for a paused-GSAP-cursor-driven "reveal
68+
// frame N of a still sequence" composition) moves no geometry and no
69+
// opacity, so it was invisible to the fingerprint and false-positived
70+
// sweep_static — mediaPixelHash already existed for exactly this pixel-only
71+
// motion class, it just wasn't applied to img.
72+
it("changes the sweep fingerprint when a same-size opaque img is swapped", () => {
73+
document.body.innerHTML = `
74+
<div id="root" data-composition-id="main" data-width="640" data-height="360">
75+
<img id="frame" />
76+
</div>
77+
`;
78+
installGeometry({
79+
root: rect({ left: 0, top: 0, width: 640, height: 360 }),
80+
frame: rect({ left: 0, top: 0, width: 640, height: 360 }),
81+
});
82+
83+
let pixelValue = 20;
84+
const getContextSpy = vi.spyOn(HTMLCanvasElement.prototype, "getContext") as unknown as {
85+
mockReturnValue(value: CanvasRenderingContext2D): void;
86+
};
87+
getContextSpy.mockReturnValue({
88+
drawImage() {},
89+
getImageData() {
90+
return { data: new Uint8ClampedArray(8 * 8 * 4).fill(pixelValue) };
91+
},
92+
} as unknown as CanvasRenderingContext2D);
93+
94+
installAuditScript();
95+
const collect = (window as unknown as { __hyperframesLayoutGeometry: () => string })
96+
.__hyperframesLayoutGeometry;
97+
const before = collect();
98+
pixelValue = 220;
99+
const after = collect();
100+
101+
expect(after).not.toBe(before);
102+
});
103+
66104
// Opacity-reveal fixture (CLI feedback digest 2026-07-14): code-typing style
67105
// scenes reveal pre-laid-out characters via opacity only — no geometry ever
68106
// moves. The sweep fingerprint must treat that as motion, both while a glyph

0 commit comments

Comments
 (0)