vite-plugin-svelte icon indicating copy to clipboard operation
vite-plugin-svelte copied to clipboard

support loading css first

Open dominikg opened this issue 1 year ago • 4 comments

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

dominikg avatar Nov 25 '24 10:11 dominikg

see #341 #1024

dominikg avatar Nov 25 '24 10:11 dominikg

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.

SystemParadox avatar Mar 12 '25 13:03 SystemParadox

.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.

dominikg avatar Mar 12 '25 13:03 dominikg

.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.

SystemParadox avatar Mar 12 '25 21:03 SystemParadox