renderToPipeableStream for Node.js
You'll learn how to use React's renderToPipeableStream API to stream server-rendered HTML progressively in Node.js environments.
The Core Streaming API
renderToPipeableStream is React's official API for streaming SSR in Node.js servers. Unlike renderToString which blocks until your entire app renders, this API lets you start sending HTML to the browser immediately and continue sending chunks as components finish rendering.
Think of it like a restaurant streaming dishes to your table as they're ready, rather than waiting for the entire multi-course meal to finish cooking.
The Basic Pattern
import { renderToPipeableStream } from 'react-dom/server';
app.get('/', (req, res) => {
const { pipe } = renderToPipeableStream(<App />, {
onShellReady() {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
pipe(res);
}
});
});
The function returns an object with a pipe method. When onShellReady fires, React has rendered the initial "shell" of your app (everything outside Suspense boundaries), and you can immediately start streaming that HTML to the client.
Why This Matters
This API enables progressive rendering: users see content faster because you don't wait for slow data fetches. Components wrapped in Suspense boundaries can finish rendering later, and their HTML gets streamed in as follow-up chunks.
The browser receives HTML incrementally, parses it as it arrives, and shows users a progressively complete page—dramatically improving perceived performance.
Key Takeaway: renderToPipeableStream is React's modern Node.js SSR API that enables streaming HTML to clients progressively, starting with the shell and filling in Suspense boundaries as they resolve.