Repository navigation
fix: escaped pseudo tokens in class names are not pseudo-elements - #551
Merged
Merged
Conversation
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.
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.
Tailwind serializes
md:after:h-0.5as.md\:after\:h-0\.5::after. The pseudo regexes instyleScan.jsread the escaped\:afterinside the class name as a pseudo-element, andstripPseudoleft.md\\:h-0\.5, an invalid selector that poisoned every joined gate:svgGeometrySelwas built with a rawjoin(',')and never validated, sosvgGeometryReaches()threw oneSyntaxErrorper SVG element and its catch answeredtruefor all of them (59k errors, +3.9 s on a 3,094-node diagram, Patch snapdom 3.7.0 to keep escaped pseudo-element names in class selectors math280h/diagrams#146 and Styles are incorrect when using the component library #147).null, so every node was probed. A silent cost on any Tailwind page using these variants.PSEUDO_ELEMENT_SEL_REflagged these rules as pseudo rules and inflatedpseudoProps.TRAILING_PSEUDO_REin the shadow-DOM scoper had the same blind spot: a rule ending in an escaped\:afterbecame:not(*).Changes
(?<!\\)lookbehind before::?inPSEUDO_ELEMENT_SEL_RE,PSEUDO_STRIP, everyPSEUDO_KINDSregex and the single-colon branch ofTRAILING_PSEUDO_RE.svgGeometrySelgoes throughjoinGate, 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__/module.styleScan.test.js: a Tailwind-shaped sheet with.md\:after\:h-0\.5::after,.hover\:before\:x::before, a legacy:aftervariant,::first-letterandcircle{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/:afterand leaves.md\:afteralone. All three are red on the previous source.Measurements (chromium,
toCanvas, mean of 10)cssHeavyScenariocontrol (10k rules, no escaped classes)The control is within noise (±35% rme on both).
Notes
(?<!\\)is a parse-timeSyntaxErrorin Safari and iOS before 16.4, at module scope. There is no previous lookbehind insrc/and the build targets es2020. If that floor matters, the alternative is a(^|[^\\])group with$1in the replace and anm.indexadjustment in the scoper.__shadowPseudotest on raw shadow CSS inclone.js,SHARE_UNSAFE_REinstyleScan.js(.focus\:ringjoins the share gate), and/:host\b/inrewriteShadowCSS(theoretical).npm run check, the non-visual suite (2021 passing; the burst/diff memo tests that fail in that container fail identically onmain). Firefox, WebKit and the visual demos still need a localtest:fullbefore release.Generated by Claude Code