fix(css): use unique key for cssEntriesMap to prevent same-basename collision#22039
Draft
teee32 wants to merge 4 commits intovitejs:mainfrom
Draft
fix(css): use unique key for cssEntriesMap to prevent same-basename collision#22039teee32 wants to merge 4 commits intovitejs:mainfrom
teee32 wants to merge 4 commits intovitejs:mainfrom
Conversation
…ollision When multiple CSS-only entry points in different directories share the same basename, `cssEntriesMap` used `chunk.name` as the Map key, causing the second entry to overwrite the first. This led to incorrect CSS cross-linking in the build manifest and spurious style loading at runtime. Use `originalFileName` (the normalized relative path from `getChunkOriginalFileName`) instead of `chunk.name` as the Map key, which is always unique per entry. Falls back to `chunk.name` when `facadeModuleId` is unavailable. Fixes vitejs#22013 Co-Authored-By: Codex <noreply@openai.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9b38d08 to
166adde
Compare
Member
|
I've updated the test to ensure |
This was referenced Apr 10, 2026
Member
|
(I'll merge this once the next rolldown release is out) |
shulaoda
added a commit
to rolldown/rolldown
that referenced
this pull request
Apr 16, 2026
…CSS entries (#9059) see vitejs/vite#22039 for the reason Co-authored-by: dalaoshu <165626830+shulaoda@users.noreply.github.com>
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.
Problem
When two or more CSS-only entry points in different directories share the same basename (e.g.
store/skins/style.scssandstore3/skins/style.scss), Vite's CSS post-processing incorrectly cross-links them in the build manifest. This causes both stylesheets to be loaded at runtime when only one was requested, leading to unintended style overrides.Reported in #22013.
Root Cause
cssEntriesMapinpackages/vite/src/node/plugins/css.tsuseschunk.nameas the Map key. When entries share a basename, they share achunk.name, so the secondset()overwrites the first. Later ingenerateBundle, the lookup returns the wrongreferenceId, causing one entry's CSS file to be transferred as a dependency of the other.Change
Replace
chunk.namewithoriginalFileName(the normalized root-relative path produced bygetChunkOriginalFileName, which is already computed in the same scope) as the Map key. This is always unique for distinct entry chunks. Falls back tochunk.namewhenfacadeModuleIdis unavailable.The same key strategy is applied on both the write path (
renderChunk) and the read path (generateBundle).Why This Fix
originalFileNameis derived fromchunk.facadeModuleIdviagetChunkOriginalFileName, the same function used by the manifest plugin to identify chunks — so the key is consistent with existing naming conventions.css.ts) and does not alter the module type or any public API.cssEntriesMapis also consumed bymanifest.ts, where the key is passed to Rolldown'snativeManifestPluginas the CSS entryname. Changing from basename to relative path makes CSS entry naming consistent with JS chunk naming in the manifest.Risk
?? chunk.namepreserves existing behavior whenfacadeModuleIdis absent.namefield for CSS entries changes from basename to relative path, which is consistent with how JS chunks are already named.Validation
a/index.css,b/index.css) sharing the basenameindex.cssin different directories, each with a distinct asset. The test verifies the manifest does not cross-link their assets.Closes #22013
Co-Authored-By: Codex noreply@openai.com
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com