-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: reenable server CSS output through a compiler option #12294
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
Conversation
There are various use cases where this continues to be necessary/nice to have: - rendering OG cards - rendering emails - basically anything where you use `render` manually and want to quickly stitch together the CSS without setting up an elaborate tooling chain
🦋 Changeset detectedLatest commit: a334755 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
what about a |
|
Recapping discussion elsewhere: this ought to be something we can configure via This does make it tricky to put everything in a single namespace though, because Honestly, I prefer the enum approach. I have to wonder if we can just use the existing <svelte:options css="injected" />
<h1>hello!</h1>
<style>
h1 {
color: red;
}
</style>...becomes this... import * as $ from "svelte/internal/server";
var $$css = ['bt9zrl', `
h1.svelte-bt9zrl {
color: red;
}
`];
export default function App($$payload) {
$$payload.css.add($$css);
$$payload.out += `<h1 class="svelte-bt9zrl">hello!</h1>`;
}...yielding output like this... rendered = render(App);
/*
{
head: '<style data-svelte="bt9zrl">h1 {...}</style>',
body: '<!--[--><h1 class="svelte-bt9zrl">hello</h1><!--]-->'
}
*/...and the CSR output looks like this... import * as $ from "svelte/internal/client";
var $$css = ['bt9zrl', `
h1.svelte-bt9zrl {
color: red;
}
`];
var root = $.template(`<h1 class="svelte-bt9zrl">hello!</h1>`);
export default function App($$anchor) {
$.append_styles($css);
var h1 = root();
$.append($$anchor, h1);
}...where Feels like that would capture everyone's use case and make everything a lot more turnkey (e.g. avoiding the FOUC that you currently face if you use |
|
where would append_styles append the styles for custom element output? how would this work with css hmr during dev? (style node already exists on update) For externalized css vite helps nicely with it but here we'd be on our own |
the shadow root, as it does today
we can update the HMR code to replace the |
|
sounds like a plan 🌈 can we cache the fact that style was added already so creating multiple instances doesn't end up doing extra work? And want happens when the last instance is destroyed, does that remove the style node too? |
yes!
we could. it would be a departure from how things work today but it's possible — we just wrap everything in an effect and remove on teardown (if a counter reaches 0). It would create a discrepancy between injected/external that might confuse people — we sometimes get issues like 'why are my |
|
opened #12374 |
|
merged #12374, closing |
There are various use cases where this continues to be necessary/nice to have:
rendermanually and want to quickly stitch together the CSS without setting up an elaborate tooling chainIt's not necessary in the common case though, which is why it's behind a compiler flag.
The compiler option name is subject to bikeshedding. I wanted it to begin with
cssso that all the CSS-related options share the same prefix.One alternative I thought of was to enhance the
csssomehow to incorporate:injected-on-server['external', 'injected']Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.Tests and linting
pnpm testand lint the project withpnpm lint