solid-styled-components
solid-styled-components copied to clipboard
What is the proper usage of extractCss in an async context?
extractCss is a synchronous (and global) API -- what's the proper usage of this function when rendering asynchronously or streaming?
Over at https://github.com/knpwrs/solid-ssr/blob/main/src/entry.server.tsx#L7-L15= I have code which essentially amounts to:
const renderPromise = renderToStringAsync(() => <App />));
const css = extractCss();
const html = await renderPromise;
Should I expect this to work properly? My concern is that extractCss() appears to work in a global synchronous context, so how can I be sure that I am extracting the css from any particular asynchronous render?
The same question applies for streaming.
Would something like how emotion handles it be appropriate? See here: https://emotion.sh/docs/ssr#api=
Basically, they offer two methods:
- Render inline
<style>elements as siblings to your components, no css extraction required. It's very easy to imagine how this would work in a streaming context. - Wrapping your app in a cache provider which holds on to an object that you can extract CSS from.