-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Initial render does not include stitches SSR styles #8392
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
Candidly, I would avoid this technique. It involves runtime overhead, and because it uses You can get it to work, by moving the <!-- src/routes/other/+page.svelte -->
<script>
import { css } from '@stc';
const blah = css({
color: 'yellow'
});
</script>
<h1 class={blah()}>Other page</h1> ...and notice that when you run the app, if you visit I'm sure there's a way to change that behaviour — a reset function or something — but the fact that this footgun exists in the first place is a bit alarming. I don't know why the |
Thanks for looking at this and suggesting this workaround - it does lead to the result that I was looking for. In regards to the essential "snowballing" of these styles and the inability to have the CSS cached due to the use of the style tag - interesting insights; I am evaluating svelte for the first time and just trying to work things out, so given this information I may end up re-evaluating my preference to use stitches and determine if there is another solution that would yield better results for svelte (or if the stitches team have any extra information on this). |
I upgraded to SvelteKit 2 and now I'm facing the same issue. I wasn't able to get your workaround working @Rich-Harris , but I did find another work around, since you suggested using I copy-pasted the output of The one issue I found was that using background images doesn't work because the suffixes like |
Describe the bug
Context
Stitches is a CSS-in-JS solution that requires that users of the library call a method called
getCssText()
and inject it into thehead
of their project for SSR, such that all styles are present on the first render.The Problem
I am currently injecting the styles into the
svelte:head
component like so (the funny additions are due to an open bug):However, the problem is that for some reason, svelte kit does ?? (I am assuming) on the first render such that the styles I have written are not present on the first SSR run of the page (check reproduction).
First render:
All renders afterwards (note the class declaration visible that sets the
color
to green):This issue also extends to prerendering. If I set
prerender
to true and export that in the root layout, the missing stitches styles are never injected.Reproduction
/
withcurl
orxh
or your HTTP utility of choice, and observe that the style tag that is injected does not have thecolor: green
declaration.
4. Make another request after the previous one and observe that the style tag now includes the missing `color: green` declaration, as does every subsequent request after the initial render.Logs
No response
System Info
The text was updated successfully, but these errors were encountered: