Skip to content

Commit 066ca7e

Browse files
fix(cli): check's overlap audit skips scenes the runtime hid (#5758)
1 parent 4cf0e3a commit 066ca7e

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,24 @@
704704
return colorAlpha(getComputedStyle(element).color) >= 0.35;
705705
}
706706

707+
const RUNTIME_HIDDEN_CLIP = '[data-hf-clip-hidden][style*="visibility: hidden"]';
708+
709+
// Core's timedClipHide rule hides these clips' whole subtrees: skipping them bounds work by what is on screen.
710+
function elementsOnScreenScenes(root) {
711+
const elements = [];
712+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
713+
acceptNode: (element) =>
714+
element.matches(RUNTIME_HIDDEN_CLIP) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT,
715+
});
716+
for (let element = walker.nextNode(); element; element = walker.nextNode()) {
717+
elements.push(element);
718+
}
719+
return elements;
720+
}
721+
707722
function collectSolidTextBlocks(root) {
708723
const blocks = [];
709-
for (const element of Array.from(root.querySelectorAll("*"))) {
724+
for (const element of elementsOnScreenScenes(root)) {
710725
if (!isSolidTextBlock(element)) continue;
711726
const rects = visibleTextClientRects(element, true);
712727
const rect = unionRects(rects);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,32 @@ describe("layout-audit.browser content overlap", () => {
23602360
});
23612361
});
23622362

2363+
it("never reads inside a scene the runtime hid", () => {
2364+
document.body.innerHTML = `
2365+
<div id="root" data-composition-id="main" data-width="1920" data-height="1080">
2366+
<div id="host" data-hf-clip-hidden style="visibility: hidden"><div id="a">Later scene line</div></div>
2367+
<div id="b">Current scene line</div>
2368+
</div>
2369+
`;
2370+
installOverlapStyles(
2371+
{ a: "rgb(0, 0, 0)", b: "rgb(0, 0, 0)" },
2372+
{ a: "none", b: "none" },
2373+
{},
2374+
{ host: "hidden", a: "visible", b: "visible" },
2375+
);
2376+
installOverlapGeometry({
2377+
a: [rect({ left: 100, top: 100, width: 400, height: 100 })],
2378+
b: [rect({ left: 300, top: 120, width: 400, height: 100 })],
2379+
});
2380+
installAuditScript();
2381+
2382+
const audit = (window as unknown as { __hyperframesOverlapAudit: OverlapAudit })
2383+
.__hyperframesOverlapAudit;
2384+
expect(audit({ time: 1 })).toEqual([]);
2385+
const read = vi.mocked(window.getComputedStyle).mock.calls.map(([element]) => element.id);
2386+
expect(read).not.toContain("a");
2387+
});
2388+
23632389
// A typewriter span clipped to nothing (clip-path: inset(0 100% 0 0)) keeps a
23642390
// normal box but paints zero pixels; overlapping it must not flag the visible
23652391
// block beneath. The clipped element is unreachable by elementFromPoint, which
@@ -3726,6 +3752,8 @@ interface AuditIssue {
37263752
coveredFraction?: number;
37273753
}
37283754

3755+
type OverlapAudit = (options: { time: number }) => AuditIssue[];
3756+
37293757
function runAudit(options?: { proseCoverageFloor?: number }): AuditIssue[] {
37303758
const audit = (
37313759
window as unknown as {

0 commit comments

Comments
 (0)