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

What is the proper usage of extractCss in an async context? #32

Open
knpwrs opened this issue Jun 26, 2022 · 0 comments
Open

What is the proper usage of extractCss in an async context? #32

knpwrs opened this issue Jun 26, 2022 · 0 comments

Comments

@knpwrs
Copy link

knpwrs commented Jun 26, 2022

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:

  1. 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.
  2. Wrapping your app in a cache provider which holds on to an object that you can extract CSS from.
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

No branches or pull requests

1 participant