Giter Site home page Giter Site logo

Comments (10)

freshollie avatar freshollie commented on May 1, 2024 5

For those still using the example styled-components. This can be used with the react 18 streaming example:

    const styleSheet = new ServerStyleSheet();

    // SSR render the full App
    const { pipe, abort } = renderToPipeableStream(
      styleSheet.collectStyles(
        <RemixServer
          context={remixContext}
          url={request.url}
          abortDelay={ABORT_DELAY}
        />
      ),
      {
        // use onShellReady to wait until a suspense boundary is triggered
        onShellReady() {
          responseHeaders.set("Content-Type", "text/html");
          const body = new PassThrough({
            transform: (chunk, _, done) => {
              // perform previous behaviour and replace the "__STYLES__" placeholder as it's streamed to the client
              const stringChunk = (chunk as Buffer).toString();
              done(
                undefined,
                Buffer.from(
                  stringChunk.replace("__STYLES__", styleSheet.getStyleTags())
                )
              );
            },
          });
          pipe(body);
          resolve(
            new Response(body, {
              status: didError ? 500 : responseStatusCode,
              headers: responseHeaders,
            })
          );
        },
        onShellError(err: unknown) {
          reject(err);
        },
        onError(err: unknown) {
          didError = true;
          console.error(err);
        },
      }
    );

Seems to be working so far for me!

from examples.

joglr avatar joglr commented on May 1, 2024 3

@AxelBriche I'm working on a PR to update all examples to be in line with our templates.

@kiliman styled-components has an issue about HTML streaming: styled-components/styled-components#3658

It seems they have documented how to implement a working example with streaming rendering:

https://styled-components.com/docs/advanced#streaming-rendering

However, it uses the deprecated renderToNodeStream, not sure how to use it with renderToPipeableStream

This does not also not work with a streamed response though.

from examples.

MichaelDeBoey avatar MichaelDeBoey commented on May 1, 2024 2

@AxelBriche I'm working on a PR to update all examples to be in line with our templates.

@kiliman styled-components has an issue about HTML streaming: styled-components/styled-components#3658

from examples.

machour avatar machour commented on May 1, 2024

A pull request updating the example would be more than welcome.
Would be more than glad to help if you have some spare time to take care of it!

from examples.

kiliman avatar kiliman commented on May 1, 2024

I believe the new entry.server file supports React 18 streamining, whereas most of the older examples use React 17 and renderToString.

I'm not sure how simple, if even possible, it is to update the styled-components example to the streaming API.

As you can see, styled components first renders the markup as a string, while collecting styles, then injects those styles into the markup. With streaming, the HTML is already being sent to the client while rendering, so nowhere to inject the styles.

let markup = renderToString(
sheet.collectStyles(
<RemixServer context={remixContext} url={request.url} />
)
);
const styles = sheet.getStyleTags();
markup = markup.replace("__STYLES__", styles);

from examples.

iDVB avatar iDVB commented on May 1, 2024

Any motion on this? We're wondering the exact same thing.
I guess the fallback is to use React 18 with renderToString instead?

from examples.

github-actions avatar github-actions commented on May 1, 2024

This issue has been automatically closed because we haven't received a response from the original author 🙈. This automation helps keep the issue tracker clean from issues that are unactionable. Please reach out if you have more information for us! 🙂

from examples.

joglr avatar joglr commented on May 1, 2024

I'm migrating away from styled-components, so I can use a library that supports react 18 streaming rendering 🤷‍♂️

from examples.

MichaelDeBoey avatar MichaelDeBoey commented on May 1, 2024

@freshollie We would love to get the styled-components example updated to work with React 18

from examples.

beeant avatar beeant commented on May 1, 2024

The example that @freshollie gave works, but why did he receive a thumbs down? Is there something wrong?

from examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.