Skip to content

fix: escaped pseudo tokens in class names are not pseudo-elements - #551

Merged
tinchox5 merged 1 commit into
mainfrom
fix/escaped-pseudo
Nov 2, 2026
Merged

tinchox5 merged 1 commit into
mainfrom
fix/escaped-pseudo

Conversation

@tinchox5

@tinchox5 tinchox5 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Tailwind serializes md:after:h-0.5 as .md\:after\:h-0\.5::after. The pseudo regexes in styleScan.js read the escaped \:after inside the class name as a pseudo-element, and stripPseudo left .md\\:h-0\.5, an invalid selector that poisoned every joined gate:

Changes

  • A (?<!\\) lookbehind before ::? in PSEUDO_ELEMENT_SEL_RE, PSEUDO_STRIP, every PSEUDO_KINDS regex and the single-colon branch of TRAILING_PSEUDO_RE.
  • svgGeometrySel goes through joinGate, validated once; an unparsable part degrades to no gate (per-property gate alone) instead of one exception per element. One probe element shared by the three gates.
  • Tests in __tests__/module.styleScan.test.js: a Tailwind-shaped sheet with .md\:after\:h-0\.5::after, .hover\:before\:x::before, a legacy :after variant, ::first-letter and circle{r:5px} over an SVG (gate parses and matches the circles; pseudo gates are strings and match the classed elements); real pseudos still stripped; shadow scoping drops a trailing real ::after/:after and leaves .md\:after alone. All three are red on the previous source.

Measurements (chromium, toCanvas, mean of 10)

scene before after
Tailwind sheet with escaped variants over a 3,000-node SVG 3,389 ms 881 ms
cssHeavyScenario control (10k rules, no escaped classes) 252 ms 222 ms

The control is within noise (±35% rme on both).

Notes

  • (?<!\\) is a parse-time SyntaxError in Safari and iOS before 16.4, at module scope. There is no previous lookbehind in src/ and the build targets es2020. If that floor matters, the alternative is a (^|[^\\]) group with $1 in the replace and an m.index adjustment in the scoper.
  • Other regexes that match pseudo names without looking at the backslash, all conservative (cost, not fidelity): the __shadowPseudo test on raw shadow CSS in clone.js, SHARE_UNSAFE_RE in styleScan.js (.focus\:ring joins the share gate), and /:host\b/ in rewriteShadowCSS (theoretical).
  • Verified on chromium: npm run check, the non-visual suite (2021 passing; the burst/diff memo tests that fail in that container fail identically on main). Firefox, WebKit and the visual demos still need a local test:full before release.

Generated by Claude Code

Tailwind serializes `md:after:h-0.5` as `.md\:after\:h-0\.5::after`. The
pseudo regexes in styleScan.js read the escaped `\:after` inside the class
name as a pseudo, and stripPseudo left `.md\\:h-0\.5`, an invalid selector
that poisoned every joined gate: the before/after/first-letter gates fell to
null (every node probed) and svgGeometrySel, joined raw and never validated,
threw one SyntaxError per SVG element (59k errors, +3.9 s on a 3,094-node
diagram, math280h/diagrams#146).

- A `(?<!\\)` lookbehind before `::?` in PSEUDO_ELEMENT_SEL_RE, PSEUDO_STRIP,
  every PSEUDO_KINDS regex and the single-colon branch of TRAILING_PSEUDO_RE
  (the shadow-DOM scoper no longer turns a `.md\:after` rule into `:not(*)`).
- svgGeometrySel goes through joinGate, validated once; an unparsable part
  degrades to no gate instead of one exception per element.

Measured on chromium, toCanvas mean of 10: a Tailwind-shaped sheet with
escaped variants over a 3,000-node SVG 3,389 -> 881 ms; the cssHeavy control
scene unchanged within noise (252 -> 222 ms, +-35% rme).

Pinned by __tests__/module.styleScan.test.js, red on the previous source.
@tinchox5
tinchox5 merged commit 5f18c1f into main Nov 2, 2026
@tinchox5
tinchox5 deleted the fix/escaped-pseudo branch November 16, 2026 19:41
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.

2 participants