Streaming SSR (React 18+) sends HTML progressively instead of waiting for the whole page. React renders until it hits <Suspense> boundaries that are still waiting (on data or code), flushes the "shell" with the fallbacks right away, then, as each boundary resolves, streams its HTML plus a tiny inline script that swaps it into place. On the client, selective hydration hydrates each boundary independently and prioritizes the ones the user interacts with. The result is a faster TTFB/FCP, slow data no longer blocking the whole page, and earlier interactivity. APIs: renderToPipeableStream (Node streams) and renderToReadableStream (Web streams: Deno, Bun, edge runtimes, and Node 18+).
renderToString (pre-18): fetch all data, render all HTML, send it, load all JS, hydrate everything at once. The slowest piece gates every step.
Streaming:
function ProductPage() {
return (
<Layout>
<ProductInfo /> {/* in the shell */}
<Suspense fallback={<ReviewsSkeleton />}>
<Reviews /> {/* slow query, streamed later */}
</Suspense>
<Suspense fallback={<RecsSkeleton />}>
<Recommendations /> {/* streamed when ready */}
</Suspense>
</Layout>
);
}
const { pipe, abort } = renderToPipeableStream(<App />, {
bootstrapScripts: ['/client.js'],
onShellReady() {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
pipe(res);
},
onShellError() {
res.statusCode = 500;
res.send('<h1>Something went wrong</h1>');
},
onAllReady() { /* use this instead of onShellReady for crawlers or static generation */ },
onError(err) { console.error(err); },
});
setTimeout(() => abort(), 10_000); // give up on slow boundaries; the client renders them instead
<div hidden id="S:1">…reviews HTML…</div><script>$RC("B:1","S:1")</script>, which moves the content into place. This works before React's JS has even loaded.hydrateRoot hydrates boundaries as their code and HTML arrive. Clicking an unhydrated boundary bumps its priority, and React replays the event after hydrating.onAllReady to send complete HTML at once.proxy_buffering, and some serverless platforms).<title>, <meta> and <link> rendered anywhere into <head>, and supports stylesheet precedence and resource preloading (preload, preinit), which helps streamed content load styles in time.prerender + resume) to serve a static shell from a CDN and stream the dynamic parts.Frameworks combine RSC with streaming. Async Server Components suspend naturally, so await in a component plus a Suspense boundary above it is all you need to stream that region.
renderToPipeableStream vs renderToReadableStream, and onShellReady vs onAllReady.Spotted a mistake or a rights concern? Report an issue