fix(css): stabilize CSS module scoped name hash across queries (fix #22957) - #23371
Open
santusht06 wants to merge 2 commits into
Open
fix(css): stabilize CSS module scoped name hash across queries (fix #22957)#23371santusht06 wants to merge 2 commits into
santusht06 wants to merge 2 commits into
Conversation
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.
Description
Fixes #22957.
When CSS Modules are imported with queries (e.g.
?inlineor?inline&usedas used by Nuxt's SSR styles feature), PostCSS'sgeneric-namesand LightningCSS derive the CSS module hash from the file path passed to their transform options.Previously,
runPostCSSpassedfrom: removeDirectQuery(id)to PostCSS. While general PostCSS plugins intentionally inspect query parameters inatRule.source.input.from,postcss-modulesdelegates string patterns togeneric-nameswhich hashes the full path containing queries like?inlineor?inline&used. Consequently, importing the same CSS module file normally vs with a query generated mismatched scoped class names within the same build (e.g._SGzINF8rvs_ZhC-jWQM), breaking SSR inlining and hydration.Solution
compilePostCSS, wrapgenerateScopedName(both string patterns and custom functions) socleanUrl(filename)is passed to the scoping generator while preservingsource.input.fromfor user PostCSS plugins.compileLightningCSS, passcleanUrl(filename)for CSS module entries.packages/vite/src/node/__tests__/plugins/css.spec.tsensuring scoped class names remain identical across?direct,?inline, and?inline&usedqueries for both PostCSS and LightningCSS.Validation
pnpm vitest run packages/vite/src/node/__tests__/plugins/css.spec.ts(50/50 passed)pnpm run test-serve css(137/137 passed)pnpm run test-build css(149/149 passed)pnpm run typecheck(0 errors)pnpm run lint(0 errors)?inlineimports now produce matching scoped names).