feat(lint): add text_truncated check for content clipped by overflow-hidden containers - #2767
Closed
xuanruli wants to merge 2 commits into
Closed
feat(lint): add text_truncated check for content clipped by overflow-hidden containers#2767xuanruli wants to merge 2 commits into
xuanruli wants to merge 2 commits into
Conversation
…hidden containers The bbox-based overflow detectors miss text truncated by an overflow:hidden ancestor — getBoundingClientRect returns the already-clipped box, so the bbox comparison sees no spill and the lost content is invisible. scrollWidth > clientWidth (or scrollHeight > clientHeight) exposes it: the content box is larger than the visible box and a clipping element hides the difference. Adds a browser-side detector (textTruncationIssues) that flags text-bearing elements whose content overflows their box while a clipping element (self or an ancestor below the composition root) swallows the overflow. Reports the innermost box per nesting chain, respects data-layout-allow-overflow and a new data-layout-allow-truncation opt-out, and defers self-clipping own-text to the existing clipped_text check. Wired through the union type, parser allowlist and persistence tiering as a warning. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The gap
The layout audit's overflow detectors compare bounding boxes:
overflowFor(subject, container, …)fires only when a subject's bbox extends beyond its container's. But when text is clipped by anoverflow:hiddenancestor (with or withouttext-overflow:ellipsis),getBoundingClientRectreturns the already-clipped box, constrained to the container. The bbox comparison sees no spill, so the lost content is invisible to every existing check — noscrollWidth/clientWidth-based truncation detection existed.The fix
A new browser-side detector (
textTruncationIssuesinlayout-audit.browser.js) flags text-bearing elements wherescrollWidth > clientWidth(horizontal) orscrollHeight > clientHeight(vertical) and a clipping element — the element itself or an ancestor below the composition root — actually hides that overflow (clipsOverflow). It:clipped_textcheck (no double-report)data-layout-allow-overflow/data-layout-bleedand adds an explicitdata-layout-allow-truncationopt-outtext_truncatedat warning severity (matches thetext_box_overflowposture — a clipped label is a real defect but not render-breaking), with a snippet, selector, container selector and fix hintWired through the same path as the sibling layout findings: browser detector →
checkBrowser.tsparser allowlist →LayoutIssueCodeunion + persistence tiering inlayoutAudit.ts→checkPipeline.Eval
Ran the built CLI (
check <sample> --json) against the 4 rendered discovery samples the current check misses, plus clean controls:text_truncatedfires?w3/fuzz000div.satellite-val(content width 144px > visible 126px)w6/fuzz007.task-bar(content width 418px > visible 346px)w3/fuzz007div.quad-title(content height 35px > visible 31px) — vertical truncationw2/fuzz0083 of 4 fire, and vertical truncation is covered (
w3/fuzz007). The kanban miss is honest: its DONE column has nooverflow:hiddenand no height cap — it grows and its bottom card is cut by the canvas root edge. That is a bbox-extends-past-canvas defect (canvas_overflow's mechanism), notscrollWidth > clientWidthcontent-box truncation; no element there has content overflowing its own clipped box. Forcing it would duplicatecanvas_overflowand risk false positives, so it is intentionally out of scope for this check.Clean controls — no false positives:
w1/fuzz003,w5/fuzz000,w5/fuzz002all reporttext_truncated: 0.Tests
Added to
layout-audit.browser.test.ts: positive horizontal + vertical truncation under a clipping ancestor, negatives for text that fits and for overflow into a non-clipping container (visible, not lost), a no-double-report guard vsclipped_text, and opt-out guards fordata-layout-allow-truncationanddata-layout-allow-overflow. Full file: 78 tests pass;tsc --noEmitclean.🤖 Generated with Claude Code