Skip to content

Commit c59fd16

Browse files
authored
fix(check): key content_overlap and text_occluded collapse by pair, and bill a clipped text box once (#2801)
Combines two fixes to the layout audit: - `staticIssueKey` no longer includes `issue.text` for `content_overlap` and `text_occluded`; both builders now emit a unique selector for both ends, so the selector pair is the identity. An animating subject (count-up, typewriter, rotating word) no longer splits one held collision into transient groups. - A clipping box that is its own nearest constraint reports `clipped_text` only, instead of also reporting `text_box_overflow`. A non-clipping self-constraint still reports.
1 parent 051336c commit c59fd16

4 files changed

Lines changed: 264 additions & 11 deletions

File tree

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
439439
return false;
440440
}
441441

442-
function textOverflowIssues(element, root, rootRect, time, tolerance) {
442+
function textOverflowIssues(element, root, rootRect, time, tolerance, clippedIssue) {
443443
const textRect = textRectFor(element, true);
444444
if (!textRect) return [];
445445
const text = textContentFor(element, true);
@@ -462,8 +462,15 @@
462462
? tolerance
463463
: Math.max(tolerance, parsePx(elementStyle.fontSize) * 0.2);
464464
const containerOverflow = overflowFor(textRect, containerRect, tolerance, verticalTolerance);
465+
const billedAsClippedText =
466+
container === element &&
467+
clippedIssue != null &&
468+
containerOverflow != null &&
469+
containerOverflow.left == null &&
470+
containerOverflow.top == null;
465471
if (
466472
containerOverflow &&
473+
!billedAsClippedText &&
467474
!hasTextClipOptOut(element) &&
468475
!clippedByAncestor(element, container)
469476
) {
@@ -663,8 +670,8 @@
663670
code: "content_overlap",
664671
severity: "warning",
665672
time,
666-
selector: selectorFor(a.element),
667-
containerSelector: selectorFor(b.element),
673+
selector: uniqueSelectorFor(a.element),
674+
containerSelector: uniqueSelectorFor(b.element),
668675
text: textContentFor(a.element),
669676
message: "Two text blocks overlap and may render unreadable.",
670677
rect: a.rect,
@@ -1021,8 +1028,8 @@
10211028
code: "text_occluded",
10221029
severity: "error",
10231030
time,
1024-
selector: selectorFor(element),
1025-
containerSelector: selectorFor(occluder),
1031+
selector: uniqueSelectorFor(element),
1032+
containerSelector: uniqueSelectorFor(occluder),
10261033
text,
10271034
message: "Text is hidden beneath an opaque element.",
10281035
rect: textRect,
@@ -1444,7 +1451,7 @@
14441451
if (!hasOwnTextCandidate(element)) continue;
14451452
const clipped = clippedTextIssue(element, time, tolerance);
14461453
if (clipped) issues.push(clipped);
1447-
issues.push(...textOverflowIssues(element, root, rootRect, time, tolerance));
1454+
issues.push(...textOverflowIssues(element, root, rootRect, time, tolerance, clipped));
14481455
const occluded = occludedTextIssue(element, time, proseCoverageFloor);
14491456
if (occluded) issues.push(occluded);
14501457
const invisible = invisibleTextIssue(element, time);

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,96 @@ describe("layout-audit.browser", () => {
292292
.map((issue) => issue.code)
293293
.filter((code) => code === "clipped_text" || code === "text_box_overflow");
294294

295-
expect(textOverflowCodes()).toEqual(["clipped_text", "text_box_overflow"]);
295+
expect(textOverflowCodes()).toEqual(["clipped_text"]);
296296
document.querySelector("#overflow-optout")?.setAttribute("data-layout-allow-overflow", "");
297297
expect(textOverflowCodes()).toEqual([]);
298298
document.querySelector("#overflow-optout")?.removeAttribute("data-layout-allow-overflow");
299299
headline.setAttribute("data-layout-bleed", "true");
300300
expect(textOverflowCodes()).toEqual([]);
301301
});
302302

303+
it("still flags a clipping self-constraint whose scroll metrics round below tolerance", () => {
304+
document.body.innerHTML = `
305+
<div id="root" data-composition-id="main" data-width="640" data-height="360">
306+
<div id="headline" style="overflow: hidden">Intentional long truncated label</div>
307+
</div>
308+
`;
309+
const headline = document.querySelector("#headline");
310+
if (!(headline instanceof HTMLElement)) throw new Error("missing headline");
311+
Object.defineProperties(headline, {
312+
clientWidth: { configurable: true, value: 200 },
313+
scrollWidth: { configurable: true, value: 202 },
314+
clientHeight: { configurable: true, value: 20 },
315+
scrollHeight: { configurable: true, value: 20 },
316+
});
317+
installGeometry(
318+
{
319+
root: rect({ left: 0, top: 0, width: 640, height: 360 }),
320+
headline: rect({ left: 40, top: 60, width: 200, height: 20 }),
321+
text: rect({ left: 40, top: 60, width: 203.4, height: 20 }),
322+
},
323+
{
324+
headline: { overflow: "hidden", overflowX: "hidden", overflowY: "hidden" },
325+
},
326+
);
327+
installAuditScript();
328+
const codes = runAudit()
329+
.map((issue) => issue.code)
330+
.filter((code) => code === "clipped_text" || code === "text_box_overflow");
331+
332+
expect(codes).toEqual(["text_box_overflow"]);
333+
});
334+
335+
it("still flags a clipping self-constraint whose text runs off to the left", () => {
336+
document.body.innerHTML = `
337+
<div id="root" data-composition-id="main" data-width="640" data-height="360">
338+
<div id="headline" style="overflow: hidden">Intentional long truncated label</div>
339+
</div>
340+
`;
341+
const headline = document.querySelector("#headline");
342+
if (!(headline instanceof HTMLElement)) throw new Error("missing headline");
343+
Object.defineProperties(headline, {
344+
clientWidth: { configurable: true, value: 100 },
345+
scrollWidth: { configurable: true, value: 100 },
346+
clientHeight: { configurable: true, value: 20 },
347+
scrollHeight: { configurable: true, value: 20 },
348+
});
349+
installGeometry(
350+
{
351+
root: rect({ left: 0, top: 0, width: 640, height: 360 }),
352+
headline: rect({ left: 140, top: 60, width: 100, height: 20 }),
353+
text: rect({ left: 40, top: 60, width: 200, height: 20 }),
354+
},
355+
{
356+
headline: { overflow: "hidden", overflowX: "hidden", overflowY: "hidden" },
357+
},
358+
);
359+
installAuditScript();
360+
361+
const found = runAudit().filter((issue) => issue.code === "text_box_overflow");
362+
expect(found).toHaveLength(1);
363+
expect(found[0]?.overflow?.left).toBe(100);
364+
expect(runAudit().some((issue) => issue.code === "clipped_text")).toBe(false);
365+
});
366+
367+
it("still flags a painted, NON-clipping box that is its own nearest constraint", () => {
368+
document.body.innerHTML = `
369+
<div id="root" data-composition-id="main" data-width="640" data-height="360">
370+
<div id="bubble">Enterprise plan includes unlimited renders</div>
371+
</div>
372+
`;
373+
installGeometry({
374+
root: rect({ left: 0, top: 0, width: 640, height: 360 }),
375+
bubble: rect({ left: 40, top: 60, width: 200, height: 40 }),
376+
text: rect({ left: 40, top: 65, width: 520, height: 30 }),
377+
});
378+
installAuditScript();
379+
380+
const found = runAudit().filter((issue) => issue.code === "text_box_overflow");
381+
expect(found).toHaveLength(1);
382+
expect(found[0]?.selector).toBe("#bubble");
383+
});
384+
303385
it("does not flag glyph-ink vertical spill within the font-metric band on a non-clipping box", () => {
304386
// A painted, non-clipping caption-word-like box whose glyph ink (text rect) exceeds its snug
305387
// line-height box by a few px vertically — normal typography, nothing is clipped. (fontSize

‎packages/cli/src/utils/layoutAudit.test.ts‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ describe("layoutAudit helpers", () => {
203203
// Sample counts below (9) mirror the CLI's default grid so the "1 sample =
204204
// entrance/exit transient, 2+ adjacent samples = held" framing in the
205205
// approach doc lines up with the numbers used here.
206+
206207
describe("persistence-tiered severity (#U10)", () => {
207208
it("demotes a content_overlap seen at only one sample among several to info", () => {
208209
const collapsed = collapseStaticLayoutIssues(
@@ -255,6 +256,133 @@ describe("persistence-tiered severity (#U10)", () => {
255256
expect(collapsed[0]).toMatchObject({ severity: "warning", occurrences: 2 });
256257
});
257258

259+
it("promotes a content_overlap whose text changes every sample (count-up over a label)", () => {
260+
const collapsed = collapseStaticLayoutIssues(
261+
[
262+
{
263+
...issue("content_overlap", "warning"),
264+
time: 4.0,
265+
containerSelector: ".num",
266+
text: "$1,204",
267+
},
268+
{
269+
...issue("content_overlap", "warning"),
270+
time: 4.5,
271+
containerSelector: ".num",
272+
text: "$8,930",
273+
},
274+
],
275+
73,
276+
);
277+
278+
expect(collapsed).toHaveLength(1);
279+
expect(collapsed[0]).toMatchObject({ severity: "error", occurrences: 2 });
280+
});
281+
282+
it("keeps a text_occluded over changing text at error, not demoted per sample", () => {
283+
const collapsed = collapseStaticLayoutIssues(
284+
[
285+
{
286+
...issue("text_occluded", "error"),
287+
time: 4.0,
288+
containerSelector: ".scrim",
289+
text: "$1,204",
290+
},
291+
{
292+
...issue("text_occluded", "error"),
293+
time: 4.5,
294+
containerSelector: ".scrim",
295+
text: "$8,930",
296+
},
297+
],
298+
73,
299+
);
300+
301+
expect(collapsed).toHaveLength(1);
302+
expect(collapsed[0]).toMatchObject({ severity: "error", occurrences: 2 });
303+
});
304+
305+
it("keeps two content_overlap pairs on different containers in separate groups", () => {
306+
const collapsed = collapseStaticLayoutIssues(
307+
[
308+
{ ...issue("content_overlap", "warning"), time: 4.0, containerSelector: ".num" },
309+
{ ...issue("content_overlap", "warning"), time: 4.5, containerSelector: ".pct" },
310+
],
311+
73,
312+
);
313+
314+
expect(collapsed).toHaveLength(2);
315+
});
316+
317+
it("does not bridge two separate transients on one pair into a held collision", () => {
318+
const blip = { ...issue("content_overlap", "warning"), containerSelector: ".label" };
319+
const collapsed = collapseStaticLayoutIssues(
320+
[
321+
{ ...blip, time: 1.0 },
322+
{ ...blip, time: 1.125 },
323+
{ ...blip, time: 9.0 },
324+
{ ...blip, time: 9.125 },
325+
],
326+
73,
327+
);
328+
329+
expect(collapsed).toHaveLength(1);
330+
expect(collapsed[0]).toMatchObject({ severity: "warning", occurrences: 4 });
331+
});
332+
333+
it("promotes only when one contiguous run clears the floor, not the span between runs", () => {
334+
const blip = { ...issue("content_overlap", "warning"), containerSelector: ".label" };
335+
const held = [1.0, 1.125, 1.25, 1.375, 1.5, 1.625].map((time) => ({ ...blip, time }));
336+
const collapsed = collapseStaticLayoutIssues([...held, { ...blip, time: 9.0 }], 73);
337+
338+
expect(collapsed).toHaveLength(1);
339+
expect(collapsed[0]).toMatchObject({ severity: "error", occurrences: 7 });
340+
});
341+
342+
it("does not bridge two blips 1.5s apart, whatever grid the collapse was handed", () => {
343+
const blip = { ...issue("content_overlap", "warning"), containerSelector: ".label" };
344+
for (const sampleCount of [9, 81]) {
345+
const collapsed = collapseStaticLayoutIssues(
346+
[
347+
{ ...blip, time: 2.0 },
348+
{ ...blip, time: 3.5 },
349+
],
350+
sampleCount,
351+
);
352+
expect(collapsed[0]).toMatchObject({ severity: "warning" });
353+
}
354+
});
355+
356+
it("promotes a 625ms contiguous collision even when a tight pair sits elsewhere", () => {
357+
const blip = { ...issue("content_overlap", "warning"), containerSelector: ".label" };
358+
const held = [5.0, 5.125, 5.25, 5.375, 5.5, 5.625].map((time) => ({ ...blip, time }));
359+
const elsewhere = { ...issue("content_overlap", "warning"), containerSelector: ".other" };
360+
const collapsed = collapseStaticLayoutIssues(
361+
[
362+
...held,
363+
{ ...elsewhere, time: 2.0 },
364+
{ ...elsewhere, time: 2.05 },
365+
{ ...elsewhere, time: 2.1 },
366+
],
367+
81,
368+
);
369+
370+
const label = collapsed.find((entry) => entry.containerSelector === ".label");
371+
expect(label).toMatchObject({ severity: "error", heldMs: 625 });
372+
});
373+
374+
it("still separates two distinct text_box_overflow findings that differ only by text", () => {
375+
const collapsed = collapseStaticLayoutIssues(
376+
[
377+
{ ...issue("text_box_overflow", "warning"), time: 4.0, text: "first" },
378+
{ ...issue("text_box_overflow", "warning"), time: 4.5, text: "second" },
379+
],
380+
73,
381+
);
382+
383+
expect(collapsed).toHaveLength(2);
384+
});
385+
258386
it("promotes content_overlap whose two occurrences span exactly 500ms (at the floor)", () => {
259387
const collapsed = collapseStaticLayoutIssues(
260388
[

0 commit comments

Comments
 (0)