Repository navigation
feat(rules): hidden-only-at-some-widths reason for controls a width-only media query hides #988 - #1012
Conversation
|
Review of #1012 (width-only @media reason). I read the full diff but did not run the tests; the Chromium-verified fixture table is a strong design here. No critical or high findings. The change stays conservative: it only produces unknown or hidden, and hidden only when the ranges cover every width.
Test coverage is good: 56 new tests, 25 Chromium-rendered rows, and the invariant "never hidden where Chromium shows". CI checks were still pending when I looked. |
…nly media query hides #988 Signed-off-by: Nik Cubrilovic <[email protected]>
…escribe, docs #988 Signed-off-by: Nik Cubrilovic <[email protected]>
97d6a3d to
4fff8b8
Compare
|
Reviewed the diff (media-widths parser, page-styles/cascade changes, static-hidden verdicts, rule messages, docs, fixtures and tests). I found no blocking problems.
Test coverage is strong: unit tests for the width parser, cascade and ancestor-union cases, and the Chromium-verified fixtures with per-width expectations. The changelog and rule docs are updated. |
Closes #988
Choice recorded (Nik decided option 2): keep
<check>-unconfirmed, with a distinct reason, rather than report a fail with a width qualifier. Reason: no new false-fail risk if the width analysis is wrong, and the cause is distinguishable from undecidable CSS. The reason ishidden-only-at-some-widths; each item's label says where it shows ("shown below 990px") and carriesmeta: { reason, shown }; when every unconfirmed item has this reason the row message readsN button(s) without accessible names hidden only at some widths by a media query (unconfirmed). The message carries no px, so one defect keeps one identity across pages.What changed
shared/media-widths.ts(new): reads a plain width-only@mediaprelude into viewport-width ranges:min-width,max-width,width(colon and range syntax, one or two comparisons), px/em/rem (1em = 16px),and, comma lists, optionalonly,screen/all. Anything else (not, orientation, height,prefers-*,hover, resolution,calc(),vw,or, nested feature groups) is null and keeps today's unknown.content/hidden-text.tsparseRules: each conditional rule now carries its enclosing at-rule preludes (at).shared/page-styles.ts: a plaindisplay: noneon plain (single-compound) selectors, inside width-only@mediaonly, in a sheet that is notmedia/title/svg/@namespace, is kept with its widths. The cascade collects the widths where it outranks the decidable rules instead of answering unknown. A decided hide, an unrelated undecided rule, a case-only match, or avisibilityhide still gives the generic unknown.@supports/@layer/@containeraround it is not a plain@mediachain, so it is generic unknown.shared/static-hidden.ts: widths accumulate down the tree (an ancestor and the element can each hide a part). If the union covers every width the element is hidden (no fail, no new reason); a gap of up to 0.02px counts as covered (themin-width: N/max-width: N - 0.02pxidiom), a whole-pixel gap or a single excluded point does not. Otherwise the element is unknown with reasonwidth. An external stylesheet (incomplete sheet) or a tree a browser may rebuild keeps the generic unknown.button-name,aria-hidden-focusand the sharedsortUnnamedControls/unconfirmedRowuse the new label/meta/message.CHROMIUM table: 25
width: ...rows added tofixtures/static-hidden-chromium.json, rendered in chrome-headless-shell 1248 at 320, 600, 989, 990, 991 and 1200px (one iframe per width, so the media queries see that width);chromiumis "shown" when any width shows it,widthshas each. Covers complementary ranges (colon, comma, range syntax, em), a 1px gap, the>/<point gap, comma bands, nesting, show-rule pairs, specificity both ways, ancestor/element splits,hidden, inline,!important, orientation,not, print,@supports. The existing invariant (never "hidden" where Chromium shows) covers them viachromium;static-hidden-width-media-988.test.tsadds: hidden at every sampled width is never "shown", the width reason only where Chromium shows it at some width (the whole-pixel-gap row is the listed exception: whole-pixel viewports never land in it), and the complementary rows must answer "hidden". Note whole-pixel iframe widths snap, so the 989.98 side of the idiom is by convention, not measured; that is the documented tolerance.Tests:
static-hidden-width-media-988.test.ts56,static-hidden.test.tsplus the audit-engine canonical golden 344, and the other page-styles/a11y hidden tests (select-name, button-name, 671, 938, 940, 951, 978, 984, 989, 991, aria-hidden-focus, hidden-text, input-zoom) all pass.tsgo --noEmitclean in packages/rules;tangly check --strictpasses.Docs: "What squirrel can see" in
button-nameandaria-hidden-focusdescribes the width-media behaviour and the reporting, and still says hide-until-JavaScript classes on unrendered pages stay unconfirmed and a rendered crawl settles them. CHANGELOG bullet added. Agent skill: no change needed.Review finding (DoS) and fix: deeply nested
@mediamade rule parsing quadratic (depth x rules):"@media all{" x14000 + ".a{display:none}" x4900 + "}" x14000(240 KB, under the size and rule bounds) took about 25 s, in one synchronous loop the rule time budget cannot interrupt. Cause:parseRulescopied the whole at-rule stack per rule andreadAtRuleWidthsre-parsed every level per rule. Fix: the at-rule chain is kept only up to depth 8 (MAX_AT_DEPTH; real themes nest 1 to 3), a deeper rule stays generic unknown, and the copy is bounded at O(8). Regression tests (3000 deep x 1000 rules, and the 14000 x 4900 case) assert under 500 ms and the generic unknown result; nesting of 7 plus the inner query is still read, 8 plus it is not.Also from review: a query pair that can never both match (
(min-width:990px) and (max-width:989px)) hides nothing, so the element reads as shown (a prior unconfirmed can now fail, as in Chromium; tested, CHANGELOG notes it);describeShownWidths([])is safe; the 0.02px tolerance trade-off is in the docs.Related, pre-existing and not fixed here: #1013 (CSS nesting such as
b{@media (min-width:0){display:none}}reads as shown on main while Chromium hides it).