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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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.

@@ -50,7 +50,8 @@ function parseToSvelteRequest(id, filename, rawQuery, root, timestamp, ssr) {
query,
timestamp,
ssr,
raw
raw,
inline: !!query.inline
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw and direct are handled above, is inline distinct to warrant its own flag? query is returned above too so the consumer could also use query.inline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to use svelteRequest.query.inline instead. I initially saw raw and was trying to map the same pattern here.

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