-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
(fix #21456): ensure css-only entries are marked as isEntry #21506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4952905
fix(manifest): mark CSS entry assets as isEntry when using array inpu…
DsChauhan08 ed32793
fix: ensure isEntry: true for CSS-only import entries (fix #21456)
DsChauhan08 26d04ee
fix(vite): ensure css-only entries are marked as isEntry
DsChauhan08 a7e6994
Merge pull request #1 from DsChauhan08/fix/manifest-css-entry
DsChauhan08 476c37e
Merge branch 'vitejs:main' into main
DsChauhan08 97a9ba5
Merge branch 'vitejs:main' into main
DsChauhan08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
11 changes: 11 additions & 0 deletions
11
playground/manifest-css-entry/__tests__/manifest-css-entry.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { describe, expect, test } from 'vitest' | ||
| import { isBuild, readManifest } from '~utils' | ||
|
|
||
| describe.runIf(isBuild)('manifest-css-entry', () => { | ||
| test('import-only css entry should have isEntry: true', () => { | ||
| const manifest = readManifest() | ||
| const mainCssEntry = manifest['frontend/entrypoints/main.css'] | ||
| expect(mainCssEntry).toBeDefined() | ||
| expect(mainCssEntry.isEntry).toBe(true) | ||
| }) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @import './styles/theme.css'; | ||
| @import './styles/main.css'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log('main.js') |
4 changes: 4 additions & 0 deletions
4
playground/manifest-css-entry/frontend/entrypoints/styles/main.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* styles/main.css */ | ||
| body { | ||
| color: red; | ||
| } |
4 changes: 4 additions & 0 deletions
4
playground/manifest-css-entry/frontend/entrypoints/styles/theme.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* styles/theme.css */ | ||
| :root { | ||
| --primary: blue; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { defineConfig } from 'vite' | ||
| import path from 'node:path' | ||
|
|
||
| export default defineConfig({ | ||
| build: { | ||
| manifest: true, | ||
| rollupOptions: { | ||
| input: [ | ||
| path.resolve(__dirname, 'frontend/entrypoints/main.css'), | ||
| path.resolve(__dirname, 'frontend/entrypoints/main.js'), | ||
| path.resolve(__dirname, 'frontend/entrypoints/styles/main.css'), | ||
| path.resolve(__dirname, 'frontend/entrypoints/styles/theme.css'), | ||
| ], | ||
| }, | ||
| }, | ||
| }) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you explain why this happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens because with array-based input, Rollup can treat CSS-only inputs as “assets” rather than JS entry chunks.
the manifest entry is emitted without isEntry: true, so pure CSS inputs don’t show up as entries. The writeBundle hook patches the manifest after generation to ensure all inputs (including CSS-only) are marked as entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this happen?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With array-based input, the CSS entry files that contain only @import statements get processed into "pure CSS chunks" (chunks with no JS exports). When the CSS post-plugin emits these as assets and registers them in cssEntriesMap, the key used is chunk.name. However, for array-based input, the name derivation may not produce a key that matches the manifest entry key (which is derived from src). With object-based input, the explicit key name is used consistently throughout, so the lookup succeeds. This patch ensures any input file present in the manifest gets marked as an entry regardless of the chunk naming.
i could have tried fixing using Ensure the cssEntriesMap key is derived consistently between the CSS plugin and manifest plugin Or normalize input arrays to objects early in the build process to ensure consistent naming
but for the moment being the way i fixed seemed the best, maybe if other cases arise we could test the other fixes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding to that : The root cause is a mismatch in how CSS entry chunks are keyed between the CSS plugin and the manifest plugin.
When a CSS entry file contains only @import statements (no actual CSS rules), it becomes a "pure CSS chunk" (isPureCssChunk = true). In the cssPostPlugin, when this chunk is emitted as an asset, it gets registered in cssEntriesMap using chunk.name as the key:
cssEntriesMap.get(this.environment)!.set(chunk.name, referenceId)Later, the manifest plugin tries to look up entries using entryCssAssetFileNames.get(chunk.fileName) to get the name and mark entries with isEntry: true.
The issue is that with array-based input, the chunk.name for pure CSS chunks may not be derived the same way as with object-based input:
Object input { 'main-css': 'src/main.css' } → chunk.name = 'main-css' (explicit)
Array input ['src/main.css'] → chunk.name is derived from the file path, but for import-only CSS files, this derivation can differ from what the manifest expects
This is why the lookup in createAsset() fails to find a matching name, so isEntry never gets set.
Two possible approaches:
1.Patch the manifest (current approach) - after manifest generation, check if any src matches an input file and mark it as isEntry
2. Fix the root cause - ensure cssEntriesMap uses a consistent key that matches how manifest entries are keyed (e.g., use the normalized source path instead of chunk.name)
Would you prefer I investigate option 2 for a more fundamental fix, or is the patching approach acceptable for this regression?