Progressive server streaming
Send the initial document structure quickly while Suspense-delayed sections continue arriving.
React 19+ · Function
Renders a React tree as HTML into a pipeable Node.js Stream. Use onShellReady for progressive streaming or onAllReady when the complete output must be ready first.
Call renderToPipeableStream with the complete React document and optional callbacks, then pipe the returned output into a Writable Node.js stream. Start in onShellReady for progressive streaming, use onAllReady for crawlers or static generation, and abort when rendering should stop.
const { pipe, abort } = renderToPipeableStream(reactNode, options?)| Name | Type | Description |
|---|---|---|
reactNode | ReactNode | The React node to render as HTML; it should represent the entire document. |
options | object | Optional configuration object containing callbacks, bootstrap scripts, namespace settings, and other rendering options. |
An object containing pipe, which writes HTML to a Writable Node.js Stream, and abort, which stops server rendering and allows the remaining UI to render on the client.
import { renderToPipeableStream } from 'react-dom/server';
export function handleRequest(request, response) {
const { pipe, abort } = renderToPipeableStream(<App />, {
bootstrapScripts: ['/main.js'],
onShellReady() {
response.statusCode = 200;
response.setHeader('content-type', 'text/html');
pipe(response);
},
onShellError(error) {
console.error(error);
response.statusCode = 500;
response.end('Server error');
},
});
request.on('close', abort);
}
function App() {
return <html><body><h1>Hello</h1></body></html>;
}Creates a Node.js streaming response, starts piping when the shell is ready, and aborts rendering if the request closes.
Send the initial document structure quickly while Suspense-delayed sections continue arriving.
Produce a complete HTML response before handing it to a crawler or static-generation pipeline.
Stop work when the client disconnects and let the browser finish the remaining UI.
It renders a React tree as HTML into a pipeable Node.js Stream. The returned pipe method writes to a Writable Node.js Stream, while abort stops server rendering and lets the rest render on the client.
Follow-up: When should streaming begin? Start in onShellReady for normal progressive responses; use onAllReady when the consumer needs the complete output, such as a crawler.
The first argument is the React node representing the document to render. The optional options object configures bootstrap scripts, callbacks, namespaces, and other server-rendering behavior.
Follow-up: What must the root node contain? It should represent the entire document, including the root html element.
This API targets Node.js Streams. For Deno and modern edge runtimes that use Web Streams, the corresponding API is renderToReadableStream.
Follow-up: Why not use renderToString for progressive loading? It returns a string immediately and does not stream content as it becomes available.
renderToReadableStreamhydrateRootSuspenserenderToStringonShellReadyonAllReady