Skip to main content

Streaming SSR with React DOM server APIs

Streaming SSR lets React send useful HTML progressively instead of waiting for the entire server tree to finish before sending the first byte.

The streaming pipelineโ€‹

Streaming SSR separates shell readiness from complete page readiness
1Request arrives
2React renders server tree
3Shell becomes ready
4Server starts sending HTML
5Suspense regions finish later
6Completed HTML streams into boundaries
7Client hydrates interactive regions

The benefit is progressive delivery, not faster databases or APIs.

Server API familiesโ€‹

Choose the stream family for the runtime
EDGE / WEB STREAM RUNTIMESWeb Streams

renderToReadableStream
Produces a Web ReadableStream.

NODE RUNTIMENode.js Streams

renderToPipeableStream
Produces a Node pipeable stream interface.

Node also exposes Web Stream compatibility APIs, but the dedicated Node server APIs are the intended performance path for Node environments.

renderToPipeableStreamโ€‹

import { renderToPipeableStream } from 'react-dom/server';

function handleRequest(req, res) {
let didError = false;

const { pipe, abort } = renderToPipeableStream(<App />, {
bootstrapScripts: ['/main.js'],

onShellReady() {
res.statusCode = didError ? 500 : 200;
res.setHeader('content-type', 'text/html');
pipe(res);
},

onShellError(error) {
console.error(error);
res.statusCode = 500;
res.end('<h1>Server error</h1>');
},

onError(error) {
didError = true;
console.error(error);
},
});

setTimeout(() => abort(), 10000);
}

This single example exposes the major production boundaries: shell readiness, status/header timing, fatal shell failure, observability, and abort policy.

What is the shell?โ€‹

function App() {
return (
<html>
<body>
<Header />
<Suspense fallback={<FeedSkeleton />}>
<Feed />
</Suspense>
</body>
</html>
);
}

If Feed suspends, React can still produce document structure, header, fallback UI, and bootstrap resources.

The shell is the useful page React can send before slow boundaries finish
Ready shell
Document ยท navigation ยท stable layout ยท fallbacks ยท bootstrap resources
Pending boundary
Slow data/code continues rendering behind its Suspense boundary

onShellReady vs onAllReadyโ€‹

These callbacks represent different delivery strategies
PROGRESSIVE USER PATHonShellReady

Start streaming when the shell is usable.
Better time-to-first-content, later boundaries continue arriving.

WAIT-FOR-COMPLETE PATHonAllReady

Wait until all rendering completes before piping.
Useful for special complete-output cases, but removes most progressive benefit.

Once bytes are sent, HTTP status and headers may already be committed. Decide required status/headers before starting the stream.

Shell failure vs later boundary failureโ€‹

Failure timing changes what the server can still control
Before shell is sent
onShellError can return a completely different server response and status.
After streaming starts
Response may already be committed; later region errors need boundary/recovery architecture rather than a new HTTP response.

Use onError for logging, tracing, request IDs, and status decisions that are still possible before the shell is emitted.

Suspense enables progressive HTMLโ€‹

<Suspense fallback={<ProfileSkeleton />}>
<Profile />
</Suspense>
Suspense turns server readiness into user-visible regions
Shell contains fallback
Server emits completed boundary HTML
Completed profile replaces fallback

Non-streaming vs streaming waterfallโ€‹

Streaming overlaps delivery with unfinished server work
Traditional blocking SSR

Fetch everything โ†’ render everything โ†’ send HTML โ†’ load JS โ†’ hydrate

Streaming SSR

Render shell โ†’ send shell โ†’ continue server work โ†’ stream completed regions โ†’ hydrate progressively

Streaming changes when useful output arrives. It does not make a five-second query complete in one second.

Avoid server waterfallsโ€‹

Bad architecture serializes independent work:

Sequential discovery wastes server time
1Load A
2Then load B
3Then load C
4Only then render

When dependencies allow, start independent work early and let meaningful Suspense regions resolve independently.

Parallel work gives streaming something useful to coordinate
Start A
Start B
Start C
Boundaries complete progressively

Abort and request lifetimeโ€‹

const { abort } = renderToPipeableStream(<App />, options);

setTimeout(() => {
abort();
}, 10000);

A render should not consume server resources indefinitely.

Request lifetime should bound server work lifetime
HTTP request
Server render + data work
Abort unnecessary unfinished work

Connect client disconnect/cancellation to rendering and data work where the runtime/framework supports it.

renderToReadableStreamโ€‹

Web Stream runtimes use the Promise-based API:

import { renderToReadableStream } from 'react-dom/server';

const stream = await renderToReadableStream(<App />, {
bootstrapScripts: ['/main.js'],
});

return new Response(stream, {
headers: {
'content-type': 'text/html',
},
});

The server runtime decides how that stream becomes an HTTP response.

Bootstrap scripts and hydrationโ€‹

Server HTML is not automatically interactive.

renderToPipeableStream(<App />, {
bootstrapScripts: ['/main.js'],
});

A real framework/bundler usually owns hashed asset URLs. Avoid hardcoding generated production filenames.

Streaming and hydration are separate but coordinated stages
Streaming
Server progressively delivers HTML.
Hydration
Client React connects behavior to delivered HTML.

A page can stream excellent HTML and still need JavaScript for interactive Client Components.

Status-code trade-offโ€‹

When should the server start streaming?
Need more render certainty before committing status/headersWait longer, accepting slower first byte
Shell is valid and early delivery mattersStart at shell readiness
Later regions can fail independentlyUse Suspense/error recovery inside the committed response
Special complete-output consumerConsider waiting for all-ready behavior

Framework conventions often make not-found/error/status behavior safer than hand-rolling this logic.

SSR and Server Components are different axesโ€‹

A framework may combine RSC, SSR, streaming, and hydration
1Server Components produce server component output
2React composes Client Component boundaries
3SSR turns the result into HTML
4Suspense streams progressive regions
5Client Components hydrate

SSR asks how output reaches the browser as HTML. Server Components ask where component code executes and what crosses boundaries.

Legacy string APIsโ€‹

renderToString still exists for compatibility/non-streaming cases, but modern Suspense-heavy applications generally benefit from framework-supported streaming or the current streaming APIs.

renderToStaticMarkup is for non-interactive HTML and is covered with static rendering.

Production checklistโ€‹

  • identify a meaningful shell;
  • place slow independent UI behind meaningful Suspense boundaries;
  • start independent data work in parallel where possible;
  • decide status/headers before piping;
  • log server-render errors;
  • maintain a shell-level failure response;
  • define abort/disconnect policy;
  • let build tooling own generated asset URLs;
  • measure server latency, TTFB, LCP, and hydration cost separately.

Exerciseโ€‹

Design an SSR dashboard with an immediate navigation shell, independently streaming profile/chart/activity regions, one failing region, and a ten-second abort budget.

Explain which output can be sent first, which work can run in parallel, and which failures can still change the HTTP response.

Interview questionsโ€‹

Junior: What does streaming SSR improve compared with returning one final HTML string?

Mid-level: What is the difference between onShellReady and onAllReady?

Senior: How do Suspense placement, HTTP status timing, server waterfalls, abort policy, and hydration interact in a production streaming route?

Summaryโ€‹

Streaming SSR is progressive delivery architecture
1Render useful shell
2Commit status + start stream
3Continue slow work
4Stream completed boundaries
5Hydrate interactive regions

Referencesโ€‹