Summary
Send HTML shell early, stream completed segments as async data resolves — improves TTFB vs buffer-all SSR. Suspense boundaries map to stream chunks. Reverse proxies must not buffer entire response. Error mid-stream needs fallback HTML and status handling.
Code example
import { renderToReadableStream } from 'react-dom/server';
const stream = await renderToReadableStream(<App />, {
bootstrapScripts: ['/client.js'],
});
return new Response(stream, {
headers: { 'Content-Type': 'text/html' },
});
Key points
- Send HTML shell early, stream completed segments as async data resolves — improves TTFB vs buffer-all SSR.
- Suspense boundaries map to stream chunks.
- Reverse proxies must not buffer entire response.
- Error mid-stream needs fallback HTML and status handling.