Capítulo 106 de 116
renderToPipeableStream(reactNode, options) renders a React tree to a Node.js stream, sending HTML to the client incrementally as pieces of the tree resolve — the Node-specific server-rendering entry point that pairs with Suspense for streaming SSR.
.pipe(res) method built for Node's HTTP response stream model — this API is specifically for Node server environments, distinct from renderToReadableStream (Ch 107), which targets the Web Streams API used by edge/non-Node runtimes.Suspense boundary streams to the client first (the shell); content inside a Suspense boundary streams in later, in place, once its data resolves — the client sees the page shell immediately rather than waiting on the slowest data to render anything.options: onShellReady (fires once the initial synchronous shell is ready to stream — the point at which it's typically safe to start piping to the response), onAllReady (fires once everything, including all Suspense-boundary content, has resolved — useful for non-streaming consumers like crawlers/static generation that need the complete HTML in one shot), onError (custom error logging for rendering failures).onShellReady vs. onAllReady is a real trade-off: streaming from onShellReady gives the fastest Time to First Byte but requires the client to handle progressively-arriving content; waiting for onAllReady (common for bots/crawlers that can't process streaming HTML) trades speed for a single complete response.const { pipe } = renderToPipeableStream(<App />, {
onShellReady() {
response.setHeader('Content-Type', 'text/html');
pipe(response);
},
});
renderToPipeableStream in Node.js server environments; use renderToReadableStream (Ch 107) for Web Streams-based runtimes (edge functions, Deno, etc.).onShellReady is the streaming-optimized choice for browsers; onAllReady is the safer choice for crawlers/bots that need complete HTML.