vite-plugin-svelte
vite-plugin-svelte copied to clipboard
support loading css first
Describe the problem
Currently css is cached and returned as a virtual module when .svelte files are imported as js module.
But with vite ?direct or ?inline query urls, it is possible that the first request is not for the js module but the css.
Describe the proposed solution
In case the cache is empty when css is requested, compile.
Alternatives considered
keep current behavior, styles might not be needed before the js module
Importance
nice to have
see #341 #1024
We're seeing a lot of issues with this, where the .svelte file gets loaded from browser cache but the CSS doesn't, so you get a garbage <style> injected with the full file content instead of the CSS.
I'm still trying to work out if our particular issue is because something is being cached when it shouldn't be, but the current behaviour is really confusing - at the very least if the CSS isn't available it should 404 or something and show a clear error somewhere instead of returning garbage.
.svelte files never end up in the browser cache. do you mean js modules compiled from .svelte files? please file a separate issue with a reproduction for this.
.svelte files never end up in the browser cache. do you mean js modules compiled from .svelte files? please file a separate issue with a reproduction for this.
Yes. I've opened https://github.com/vitejs/vite/issues/19632 because I think it's a general vite issue. But it would have helped a lot with debugging this if vite-plugin-svelte had given a clear error instead of silently returning garbage.