Skip to content

Write HTML. Render video. Built for agents.

fix(cli): check's overlap audit skips scenes the runtime hid (#5758)

Miguel Ángel066ca7e20a16
diff --git a/packages/cli/src/commands/layout-audit.browser.js b/packages/cli/src/commands/layout-audit.browser.js
index 9ba3269eb3..235733f938 100644
--- a/packages/cli/src/commands/layout-audit.browser.js
+++ b/packages/cli/src/commands/layout-audit.browser.js
@@ -704,9 +704,24 @@
return colorAlpha(getComputedStyle(element).color) >= 0.35;
}
+ const RUNTIME_HIDDEN_CLIP = '[data-hf-clip-hidden][style*="visibility: hidden"]';
+
+ // Core's timedClipHide rule hides these clips' whole subtrees: skipping them bounds work by what is on screen.
+ function elementsOnScreenScenes(root) {
+ const elements = [];
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
+ acceptNode: (element) =>
+ element.matches(RUNTIME_HIDDEN_CLIP) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT,
+ });
+ for (let element = walker.nextNode(); element; element = walker.nextNode()) {
+ elements.push(element);
+ }
+ return elements;
+ }
+
function collectSolidTextBlocks(root) {
const blocks = [];
- for (const element of Array.from(root.querySelectorAll("*"))) {
+ for (const element of elementsOnScreenScenes(root)) {
if (!isSolidTextBlock(element)) continue;
const rects = visibleTextClientRects(element, true);
const rect = unionRects(rects);
diff --git a/packages/cli/src/commands/layout-audit.browser.test.ts b/packages/cli/src/commands/layout-audit.browser.test.ts
index a30d4e31ce..7184a7787f 100644
--- a/packages/cli/src/commands/layout-audit.browser.test.ts
+++ b/packages/cli/src/commands/layout-audit.browser.test.ts
@@ -2360,6 +2360,32 @@ describe("layout-audit.browser content overlap", () => {
});
});
+ it("never reads inside a scene the runtime hid", () => {
+ document.body.innerHTML = `
+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">
+ <div id="host" data-hf-clip-hidden style="visibility: hidden"><div id="a">Later scene line</div></div>
+ <div id="b">Current scene line</div>
+ </div>
+ `;
+ installOverlapStyles(
+ { a: "rgb(0, 0, 0)", b: "rgb(0, 0, 0)" },
+ { a: "none", b: "none" },
+ {},
+ { host: "hidden", a: "visible", b: "visible" },
+ );
+ installOverlapGeometry({
+ a: [rect({ left: 100, top: 100, width: 400, height: 100 })],
+ b: [rect({ left: 300, top: 120, width: 400, height: 100 })],
+ });
+ installAuditScript();
+
+ const audit = (window as unknown as { __hyperframesOverlapAudit: OverlapAudit })
+ .__hyperframesOverlapAudit;
+ expect(audit({ time: 1 })).toEqual([]);
+ const read = vi.mocked(window.getComputedStyle).mock.calls.map(([element]) => element.id);
+ expect(read).not.toContain("a");
+ });
+
// A typewriter span clipped to nothing (clip-path: inset(0 100% 0 0)) keeps a
// normal box but paints zero pixels; overlapping it must not flag the visible
// block beneath. The clipped element is unreachable by elementFromPoint, which
@@ -3726,6 +3752,8 @@ interface AuditIssue {
coveredFraction?: number;
}
+type OverlapAudit = (options: { time: number }) => AuditIssue[];
+
function runAudit(options?: { proseCoverageFloor?: number }): AuditIssue[] {
const audit = (
window as unknown as {