Streaming server-side rendering
See original GitHub issueReact 16 introduced streaming server-side rendering, which (I think) looks like this:
import ReactDOMServer from 'react-dom/server';
app.use('*', (req, res) => {
res.write('<html><head></head><body><div id="root">');
ReactDOMServer.renderToNodeStream(<App />).pipe(res);
res.end('</div></body></html>');
})
It sends down the generated HTML as it comes along, kinda like as if you were streaming a movie that comes along one piece after another. This allows the browser to already start rendering without having to wait for the full document.
This presents challenges for styled-components since we have to inject CSS as we go along, even before we know the full rendered HTML. By the time we have the CSS generated the document head has already been streamed to the client and we can’t just inject stuff there anymore.
I have no idea how streams work, so I have no idea how our API would work or not work in a stream-based setup, but it’d be great to figure out!
Previous discussion: #386
Previous art: @threepointone with glamor-stream
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:19 (13 by maintainers)
Hmm, now that React has fragments it’s feasible to pass along styles together with the component that uses them; and since you know which component you’re passing (most of the time), you could “hold” styles for components that can’t have <style> as a sibling.
In fact, you can now pass styles either as siblings or additional children, so perhaps streaming styles can be done like this:
,
: add a <style> tag with the queued classes as a first sibling and return a fragment- For
, , and all other “intermediate” tags that can’t
have styles as children or siblings: hold the queue
- For all the rest: pass <><style/>{children}</> as children to the
component
- Then, when hydrating on the client, just do the regular thing and
hopefully the more robust React v16 hydration won’t mind that the inline
style tags disappear.
2reactions elrumordelaluzcommented, Oct 24, 2017 Read more comments on GitHub >
Top Results From Across the Web
Streaming Server-Side Rendering - Patterns.dev Like progressive hydration, streaming is another rendering mechanism that can be used to improve SSR performance. As the name suggests, streaming implies chunks ...... Read more >Streaming server-side rendering (SSR) - Shopify Developers Streaming SSR is a feature in React that allows you to load data over a network in multiple chunks. The chunks are loaded... Read more >React 18: Streaming SSR - Next.js Streaming allows you to incrementally render parts of your UI to the client. In Next.js 13, you can start using the app/ directory... Read more >React 18: Concurrency and Streaming SSR - This Dot Labs Probably one of the most impactful changes in this set is now the ability for server-side rendering or SSR to be streamed to... Read more >Streaming Server-Side Rendering | JavaScript Patterns Streaming Server-Side rendering allows us to send components down to the client as soon as they've been generated. With regular Server-Side rendering, ... Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required. Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found Previous page Next page
(Yes, <>…</> is now the official syntax for fragments 😃 )
(Now I wonder how streaming could work with @graphql - it would be cool if the stream could be paused until a promise resolves)
On Tue, Oct 31, 2017 at 7:51 AM Evan Scott notifications@github.com wrote:
Also pseudo elements like
:before
or:after
or@media
queries and othercss
specificity level.Passing props from parent styled-component to immediate child styled-component.
how to target sibling styled component on focus