Skip to content
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

feat: support ?inline query on svelte style virtual modules #1024

Merged
merged 5 commits into from
Nov 25, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Nov 15, 2024

In Vite 6, importing CSS in SSR now no longer return a default export of the transformed CSS file, you'd need to use ?inline instead. This was already pushed for in Vite 5 but we forgot to remove support in SSR.

That means frameworks who do CSS crawling to prevent FOUC will now have to use ?inline to get the transformed CSS, which most already did. However, there's a quirk where v-p-s always strips out the ?inline here:

if (svelteRequest.query.type === 'style' && !svelteRequest.raw) {
// return cssId with root prefix so postcss pipeline of vite finds the directory correctly
// see https://github.com/sveltejs/vite-plugin-svelte/issues/14
log.debug(
`resolveId resolved virtual css module ${svelteRequest.cssId}`,
undefined,
'resolve'
);
return svelteRequest.cssId;
}

This was fine for Vite 5 as mentioned above, Vite still supported default exports of CSS files in SSR, but with Vite 6 it is now empty. For v-p-s to properly support ?inline, it needs to leave the query as is, similar to ?raw handling.


In practice, this isn't a breaking change, however due to some unintended reliance of the old behaviour, the SvelteKit tests here will fail due to HMR (added a workaround here for now). I sent a PR upstream to fix this sveltejs/kit#13007 and if we want to play it safe for now, we can merge this only in the next major.

With this merged, it should unblock Vite 6 support for CSS FOUC for both SvelteKit and Astro.

@dominikg dominikg merged commit 973ba75 into main Nov 25, 2024
6 checks passed
@dominikg dominikg deleted the inline-svelte-css branch November 25, 2024 10:20
This was referenced Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants