Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 495c7e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
m1san
force-pushed
the
fix-local-class-name-boundaries
branch
from
November 18, 2026 05:04
ca33fd4 to
9ad2d2c
Compare
m1san
force-pushed
the
fix-local-class-name-boundaries
branch
from
November 18, 2026 05:11
9ad2d2c to
495c7e6
Compare
m1san
marked this pull request as ready for review
November 18, 2026 05:15
2 tasks done
This branch has not been deployed
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.
Fixes #1811
Problem
transformSelectorfinds local class names in a selector with a plain substring search. The only boundary check is "skip if preceded by.", so any local class name that is also a substring of other selector text gets a.inserted into the middle of it:ariax [aria-selected="true"].x [.aria-selected="true"]rolex [role="option"].x [.role="option"]ocusx:focus.x:f.ocushoverx:hover.x:.hoverttonx button.x bu.ttonWith the default hashed identifiers this is rare. With custom identifiers from the bundler plugins'
identifiersoption, it becomes possible. It also depends on which identifier happens to be assigned to which style, so an unrelated change, such as adding a style or reordering modules, can suddenly produce invalid CSS. In our case the result was an invalid attribute selector that failed the build at minification (lightningcss:No qualified name in attribute selector), in a stylesheet nobody had touched.Fix
The existing right-to-left replacement loop now accepts a match only if it forms a whole class token:
&&still pass, because the match to the right has already been prefixed with..[before it).:or#. If it is an identifier character, another match must end there (&&), or the word before it must be an element name (body&).This adds a few cheap checks per match, with no allocations in the common path. In a synthetic benchmark of 4,000 selectors,
transformCsstook about 0.2µs more per selector. There is no extra pass over the selector, and the fast path that skips the search is unchanged.&&,body&,:not(.x)&,&[attr],:nth-child(2n of &)and the existingdebugName_hash1/debugName_hash1doverlap case all keep working.Testing
transformCsstests for the collision cases and the glued cases. The collision test fails onmasterand passes with this change.pnpm vitest run: all tests pass.