-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Compiler render_ssr does not respect css option #3604
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
Comments
The documentation for the
Perhaps this could be clarified to say that it only applies to the client-side code. But it has nothing to do with whether the |
It is not about a compiler's output. The compiler always emits both js and css. const css = {code: "...", map: "..."} // <----- this
const Component = create_ssr_component(($$result, ...) => {
$$result.css.add(css); // <---- and this
return '...';
}); is in const App = require('./compiled-app')
const { html, css, head } = App.render({ answer: 42 }); // css should be null |
Playing around in the REPL, it looks like when you're generating SSR, the only effect that turning on I'm not sure why the |
SSR doesn't really work with custom elements full-stop. (Part of the reason I never use them, and recommend that other people don't use them either.) If there's anything that needs to change there, it's that this... svelte.compile(text, {
customElement: true,
generate: 'ssr'
}); ...should result in an error being thrown. To be clear, the Is the concern here that extra work is being done unnecessarily, or is the presence of a non-null |
If I build bundles for DOM and SSR from the same source, I extract CSS as an asset and inject it as a link in HTML.
Yep |
Closing for now unless this is considered an issue that requires fixing. |
My use case is the same as @JohnGurin:
For my project, I also unfortunately have to do some regex parsing of the SSR output before using it to create static HTML because I'm trying to do everything in v8. The Should this just be omitted in SSR by default? It's possible I'm reading @Rich-Harris's comment wrong:
At the very least it would be great if passing |
@Conduitry Why can't you remove the css from the server bundle? I have a bundle size of 5 megabytes only due to css. I think if you do not include css in the server bundle, it will speed up the build and reduce the size of the js files on the server. |
FWIW, I thought setting Use case: Makes trying to ascertain whether JS has changed between builds harder when implementing live reload vs hot CSS injection. (I can check if CSS has changed by comparing the CSS returned from the compiler but I can’t compare if the JS has changed between builds without removing the generated superfluous CSS which I don’t use anyway as I inject the CSS into a style tag in my template.) Update: In case it helps someone else, I don’t know how robust this is but currently I’m transforming the JS with the following regular expressions to remove the effects of the CSS for the purpose of being able to isolate JS and CSS changes between builds: output.js.code
.replace(/const css = \{.*?};/s, '')
.replace('$$result.css.add(css);', '')
.replace(/svelte-.*?"\}/g, '') (You also have to replace the new CSS hash with the old one if you’re using it to inject CSS on changes like I am.) |
svelte 3.12.1
https://svelte.dev/examples#styling
svelte/src/compiler/compile/render_ssr/index.ts
Lines 24 to 26 in 07a4eb4
A possible fix:
The text was updated successfully, but these errors were encountered: