fix(rule-utils): anchor the part- variant regex - #5313
Merged
Merged
Conversation
PartClassesRE had no ^ anchor while the handler slices the matcher from index 0, so a match found after a leading variant produced a corrupted matcher and the utility was dropped. dark:part-[button]:text-red emitted no CSS at all, while hover:part-[button]:text-red worked.
✅ Deploy Preview for unocss ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
commit: |
zyyv
approved these changes
Sep 7, 2026
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 bug
part-[...]stops working as soon as it is combined with a variant that UnoCSS resolves after it.hover:part-[button]:text-redworks, butdark:part-[button]:text-redproduces no CSS at all. The utility is silently dropped, with no warning.Also affected:
rtl:,*:,scope-[...]:,group-data-[...]:,@container, and the[&...]:variables variant.Reproduce
Root cause
PartClassesREinpackages-presets/rule-utils/src/pseudo.tsis not anchored, but its handler builds the next matcher withinput.slice(match[1].length), which assumes the match starts at index 0. Fordark:part-[button]:text-redthe regex matches at index 5 and the slice yieldston]:text-red, so no rule ever matches it. The variants that do work only work because they are ordered beforevariantPartClassesand get consumed first.Anchoring the regex lets those later variants take their turn, after which
part-matches at index 0 as it already does today.Test
packages-presets/rule-utils/test/pseudo.test.tsgainspart classes after another variant: it registerscreatePartClasses()followed by adarkvariant and asserts thatdark:part-[button]:foo-1is matched and emits.dark .dark\:part-\[button\]\:foo-1::part(button){color:foo-1;}. Without the anchorresult.matchedis an empty set and no CSS is produced.The existing
part classestest is unchanged and still passes, as does the rest of the suite.