Skip to content

fix(rules): design tokens no longer make every control unconfirmed; a show over hidden is unconfirmed beside an unread sheet #938 - #942

Merged
nc9 merged 1 commit into
mainfrom
fix/938-root-custom-props-and-hidden-intent
Oct 20, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/938-root-custom-props-and-hidden-intent

Conversation

@nc9

@nc9 nc9 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Closes #938.

Problem

Since #921 the a11y checks that skip hidden controls read <style> blocks. That caused two regressions.

  1. Design tokens poisoned the reader. A :root block of custom properties whose names or values mention display, next to a calc() or var(), made every element "unknown". Examples are --font-display: swap and the "Display" typography preset in WordPress global styles. Every unnamed control went from fail to <check>-unconfirmed. Two causes: readDeclarations read the whole block as unreadable, and :root was indexed as "could match any element".
  2. A show beat an unread hide. A <style> rule that shows a hidden control was applied even when the page loads an external sheet. The usual case is Bootstrap's [hidden]{display:none!important}, which keeps the control hidden. The control became a false FAIL; v0.0.117 skipped it.

Fix

  • Declaration reader (packages/rules/src/shared/page-styles.ts): scanDeclarations cuts a block into declarations the way the CSS tokenizer does. It respects strings, comments, (, [ and { blocks, and unquoted url(…).
    • Only a display, visibility or all declaration can hide. Custom properties and every other property are skipped whatever their values hold.
    • display and visibility declarations are still read strictly.
    • These make the block unknown, as before: an escape outside a string (it can spell a name or a url( token; codex found the u\72l( case), a string cut by a newline, or a property name that is not a plain identifier and mentions either property.
    • mayAnimate now comes from declaration names, so a custom property that mentions animation no longer marks <html> as animated.
  • :root narrows a rule's subject to <html>.
  • Shows over the UA hide (static-hidden.ts): a <style> rule or a plain inline style that shows an element the user-agent stylesheet hides (hidden, a closed <dialog>, a popover) is "unknown" on a page with an unread stylesheet. Only an inline display … !important settles it, since no sheet rule outranks it. With every sheet read, the show is still settled, as Chromium renders it.
  • Also: a11y/aria-command-name's solution text said "A element"; it now says "An element". button-name uses the shared UNCONFIRMED_CHECK_SUFFIX (follow-up from the fix(rules): an unconfirmed control resolves the prior fail it replaced #935 #936 review).

Acceptance criteria

  • A <style> rule whose declarations are all custom properties no longer makes any element's display or visibility unknown. Covered by static-hidden.test.ts: "a :root block of custom properties leaves every element settled" and the inline-reader cases.

  • :root (and html) as a subject applies to <html> only. Covered by parseSelector(":root") (subject tag html) and "a child that sets visibility itself is settled". html was already a decided tag selector.

  • With the repro, a11y/button-name reports button-name fail, not unconfirmed. Covered by a11y-root-custom-properties-938.test.ts, which runs the repro through all seven rules (8 checks).

  • github.blog no longer reports its unnamed controls as unconfirmed because of its :root global styles. On a 20-page quick offline audit, A/B on the same HOME:

    • before: 0 fail and 20 pages unconfirmed for button-name, aria-buttons, aria-command-name and aria-hidden-focus;
    • after: 19 to 20 fail and 1 unconfirmed.

    The one page left is the homepage. There, WordPress core's undecidable show-only rules (.wp-block-image>a{display:inline-block}, the lightbox button{display:flex}) still make links and buttons unknown. Filed as a11y: an undecidable <style> rule that can only show an element makes every element it could match unconfirmed #940.

  • A <style> rule that would show a control hidden by hidden, a closed <dialog> or a popover does not turn a skip into a fail on a page that loads an external stylesheet; the control is unconfirmed. Covered for hidden, closed dialog, popover, a plain inline show, an inline !important show, and no external sheet.

  • Regression tests cover the custom-property :root block, a WordPress-style presets block (synthetic github.blog shape) and the external-stylesheet [hidden] case.

Tests

  • 23 of the new tests fail on the pre-fix code, run in a scratch worktree.
  • 17 new rows in static-hidden-chromium.json, rendered in chrome-headless-shell 1248. Each matches the new verdict, or the verdict is safer ("unknown" where Chromium hides). Examples:
    • external [hidden]{display:none!important} plus a <style> show renders hidden;
    • an inline !important show renders shown;
    • the escaped url( row renders shown.
  • Local results: rules suite 7009 pass, tsgo clean. Codex flagged one P2 (escaped url); it is fixed, and the re-check found no P1/P2.

squirrel skill impact

None. No flag, output format or report field changes. docs/rules/a11y/button-name.mdx and aria-hidden-focus.mdx are updated.

… show over hidden is unconfirmed beside an unread sheet #938

A :root block of custom properties whose names or values mention display
(--font-display, WordPress's Display preset) beside a calc() or var() made
every element unknown, so unnamed controls warned where they should fail.
The declaration reader now cuts a block into declarations the way a
browser's tokenizer does; only display, visibility and all can hide, so
custom properties and other properties are skipped whatever they hold. An
escape outside a string, or a string a newline cuts, still makes the block
unknown. :root narrows a rule's subject to <html>.

A <style> rule or plain inline style that shows an element the browser
hides by default (hidden, a closed dialog, a popover) is now unknown on a
page with an unread stylesheet, where [hidden]{display:none!important}
keeps it hidden. An inline display !important still settles it.

Also fixes "A element" in a11y/aria-command-name's solution text.

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 19, 2026

Copy link
Copy Markdown

Reviewed the diff (declaration-level CSS scanning in page-styles.ts, the :root → html mapping, the [hidden] unconfirmed guard in static-hidden.ts, docs and tests). I found nothing that should block merge.

  • (nit) packages/rules/src/shared/page-styles.ts: splitDeclarationBlock returns null on any backslash outside a string, so a block with an escape anywhere (even in an unrelated property) goes to "unknown" for the whole rule. This is conservative and safe, and it matches the previous behaviour. A short comment on that tradeoff would help.
  • (nit) parseSelector: *:root may leave tag as * rather than html, which only widens the match. A one-line test for it would be cheap.
  • (nit) button-name.ts now uses UNCONFIRMED_CHECK_SUFFIX. Other rules still hard-code -unconfirmed, so consider migrating them for consistency.

Test coverage is good. It covers the issue repro, the WordPress global-styles shape and the Bootstrap [hidden] case across 7 rules, plus a regression check that a real display:none stays unconfirmed. I didn't run the tests myself.

@nc9

nc9 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Review triage. None of these needs a code change:

  • (nit) escape makes the whole block unknown: this is intended, and the splitDeclarationBlock doc comment says why. An escape outside a string can spell a property name or a url( token, and a url( token ends at its first ). Codex found exactly that false-"hidden" path (display:none;--x:u\72l(();display:block, which Chromium renders shown; there is a fixture row for it). Before this PR any backslash anywhere made the block unknown; now only one outside a string does.
  • (nit) *:root: * sets no tag, so the subject becomes html. parseSelector("*:root") gives { tag: "html" }, and div:root keeps div.
  • (nit) other rules hard-coding -unconfirmed: none left. Every other rule emits the row through unconfirmedRow (static-hidden), and aria-hidden-focus already used the constant. button-name was the last literal.

The one red check on the first run, CLI tests, was an unrelated docs/scripts/check-links.test.ts ordering flake, filed as #943. The test passed on main at ec92c5e. I reran only that job.

@nc9
nc9 merged commit 88b6520 into main Oct 20, 2026
25 of 26 checks passed
@nc9
nc9 deleted the fix/938-root-custom-props-and-hidden-intent branch October 20, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a11y: a :root custom-property block makes every control on the page unconfirmed (since #921)

1 participant