Astro Info
Astro v7.3.5
Vite v8.3.1
Node v24.19.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations injected
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
An integration adds a script with injectScript('page', ...). That script imports a module, and the module imports a CSS file. After astro build, the JS is there but the CSS file is not. The class names ship with no styles.
The same import from a <script> in a page keeps its CSS.
It works in 5.16.11 and breaks in 5.16.12. It's still broken in 7.3.5. Static and dynamic imports both break.
I think the cause is the orphan cleanup in plugin-css.ts, added in #14607. It deletes a stylesheet when no page uses it and no chunk has it in viteMetadata.importedAssets. Vite records CSS for a JS chunk in viteMetadata.importedCss, which the check doesn't read, so the stylesheet is treated as unused.
What's the expected result?
The CSS file is written to dist/ and loads with the chunk that imports it, like it did in 5.16.11.
Link to Minimal Reproducible Example
https://github.com/KayleeWilliams/astro-injected-script-css
Run npm install && npm run build. No .css file is written to dist/_astro/. Run npm run preview and click both buttons. The injected one should be red and is black.
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
An integration adds a script with
injectScript('page', ...). That script imports a module, and the module imports a CSS file. Afterastro build, the JS is there but the CSS file is not. The class names ship with no styles.The same import from a
<script>in a page keeps its CSS.It works in 5.16.11 and breaks in 5.16.12. It's still broken in 7.3.5. Static and dynamic imports both break.
I think the cause is the orphan cleanup in
plugin-css.ts, added in #14607. It deletes a stylesheet when no page uses it and no chunk has it inviteMetadata.importedAssets. Vite records CSS for a JS chunk inviteMetadata.importedCss, which the check doesn't read, so the stylesheet is treated as unused.What's the expected result?
The CSS file is written to
dist/and loads with the chunk that imports it, like it did in 5.16.11.Link to Minimal Reproducible Example
https://github.com/KayleeWilliams/astro-injected-script-css
Run
npm install && npm run build. No.cssfile is written todist/_astro/. Runnpm run previewand click both buttons. The injected one should be red and is black.Participation