Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

React 19+ · Function

renderToPipeableStream

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.

How it works

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.

Syntax

const { pipe, abort } = renderToPipeableStream(reactNode, options?)

Parameters

NameTypeDescription
reactNodeReactNodeThe React node to render as HTML; it should represent the entire document.
optionsobjectOptional configuration object containing callbacks, bootstrap scripts, namespace settings, and other rendering options.

Returns

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.

Key points

  • Use it for server-rendering React HTML directly into a Node.js stream.
  • Destructure pipe and abort from the returned result.
  • The shell callback indicates that the initial page structure is ready to send.
  • Use onAllReady when output should wait until every rendered boundary is ready.
  • Provide client script paths when the streamed document needs browser-side startup code.
  • The namespace option defaults to HTML and can be changed for SVG or MathML roots.

Common mistakes

  • Use renderToReadableStream instead in environments that provide Web Streams rather than Node.js Streams.
  • Render the complete document from the root component, not only the application content.
  • Choosing the wrong callback changes whether incomplete Suspense content can stream progressively.

Example: Stream a complete document from Node.js

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.

When to use it

Progressive server streaming

Send the initial document structure quickly while Suspense-delayed sections continue arriving.

Crawler and static generation output

Produce a complete HTML response before handing it to a crawler or static-generation pipeline.

Request cancellation

Stop work when the client disconnects and let the browser finish the remaining UI.

Interview questions

QWhat does renderToPipeableStream return?

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.

QWhat are the function's inputs?

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.

QWhich environments should use this function?

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.

  • renderToReadableStream
  • hydrateRoot
  • Suspense
  • renderToString
  • onShellReady
  • onAllReady

Source: renderToPipeableStream – React. Checked 2026-10-15.