-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: multiple entries with shared css and no JS #13962
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Ah #13608 missed the test cases, maybe we could add the test cases to the |
What test cases do you have in mind? |
I mean we could move this PR's test cases to |
Yeah, I found rollup@3.25.1 sharing entry chunks when I debugged code in https://github.com/vitejs/vite/pull/13608/files#diff-89bae1df62862bb7f4a03d82a1e9cbf4ac6d0c042f21fbbacb0a2238bd050042L828-L840 That's why I delayed removing inline entry chunks in the bundle after checking all htmls. Well that's weird, I remembered that I had tested the reproduction of #13436 after merging #13608 in my mac, it worked. |
See edited description at #13962 (comment) |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Same projects are currently failing in main. |
@lukastaegert just in case, our understanding is that Rollup started sharing entry points (see before and after chunks structure in the description). Is there an option we are missing to revert to the previous behavior? If not, using |
What is likely happening is that we had an issue with unnecessary empty chunks being created in situations where an entry chunk only contained re-exports. There was no easy way to fix this, so we added a post processing step that looks for suitable merge targets for such chunks. you should be able to solve this by setting output.experimentalMinChunkSize to 0. This would, however, prevent users from using this option, or it would fail if users explicitly use this option. |
Thanks for the context and explanation!
Do you have an example of how this could happen? We're returning
I thought about this option too. I was using |
No, I mean even with this option, but I am not at a computer and cannot check, probably I am wrong. If you have a test case that fails without your fix, you should check if your fix still works if you set output.experimentalMinChunkSize to a high value like 10000. |
Ah, I see. I tried it out using
Let's merge this then and we now know we could later migrate to injecting a global if we find issues with this approach. Thanks again Lukas! |
Fixes #13436
Edited Description
rollup started to share entry points chunks (I don't have an exact reference on when this happened). For the added test case, if you run it in Vite 3, you'll see the following chunks:
shared-css-no-js-{}.js
(modules:shared-css-no-js.html
)shared-css-with-js-{}.js
(modules:shared-css-with-js.html
,src/shared-css-main.js
)shared-css-theme.js
(modules:shared-css-theme.css
)With the first two chunks importing
shared-css-theme.js
In Vite 4.x, the test would result in:
shared-css-no-js-{}.js
(modules:shared-css-no-js.html
,shared-css-theme.css
)shared-css-with-js-{}.js
(modules:shared-css-with-js.html
,src/shared-css-main.js
)With the second chunk importing the first one.
This broke current assumptions in the CSS and HTML Plugin.
The fix this PR applies is to use
moduleSideEffects: 'no-treeshake'
when generating the JS entry points corresponding to each HTML entry point. This reverts to the previous structure where the entry points aren't shared. The emptyshared-css-no-js-{}.js
chunk is correctly removed as before by the HTML plugingenerateBundle
Previous Description
The issue is that the CSS chunk now contains a reference in
chunk.modules
to an HTML file, so it ends up being marked withisPureCssChunk = false
because the.html
isn't in styles. Testing with a prev version of Vite (and so a prev version of Rollup) the HTML file isn't in modules. It may be because of what is explained in #13608, that entry chunks are now shared. See related change here.I don't know if this is something we should report to Rollup, but there were references to HTML files in chunk modules before. This PR fixes the issue by checking if there is code in the module.
What is the purpose of this pull request?