Allow vite to refer to inlined CSS#8351
Conversation
🦋 Changeset detectedLatest commit: 443f15d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I'm hoping there's a better way. Ideally vite would not attain references to files we might later delete. Alternatively, it could not throw an error when preloading fails as it is not critical. I will try to look around their codebase to find something useful. If I don't, I'll mark this ready to review on monday. |
1e5cd88 to
5929ad3
Compare
|
I haven't had time to look into fixing it on the vite side, but the compromise is small - small css files included in the server bundle. And the unnecessary requests vite makes is a minor annoyance. It does not affect performance. |
5929ad3 to
2daf995
Compare
bluwy
left a comment
There was a problem hiding this comment.
I'm ok with this fix for now. If you'd like to look further, I think there's maybe a couple ways for a direct fix:
- Use
modulePreload.resolveDependenciesto filter out the removed CSS. A bit tricky to bridge this config option togenerateBundlein plugin-css. - Filter out the deps here that does not exist in the
bundle. Could be a better fix.
2daf995 to
443f15d
Compare
|
@bluwy I will try to look into 2 later this week, but I am skeptic because vite's built-in hooks run before app hooks IIRC, so I expect it to have already created the preload script by the time. Either way, not blocking. Will merge after node 18 tests pass. |
|
@lilnasy thanks for looking into it.
Vite handles that through plugins, so as long as we order ours right before Vite's, I think it could work. You can check out the plugin ordering at here and here. Not urgent of course, feel free to look if you're interested! |
Changes
Closes #8329
Inlined CSS chunks are not deleted anymore, because when using dynamic imports with
import.meta.glob(), vite tries to preload them.Testing
Added a fixture.
Docs
Does not affect usage.