Skip to content

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

Open

Description

@knpwrs

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions