Diagnose streaming and hydration failures
Stream a shell before slower content is ready
Streaming SSR lets a server deliver an initial HTML shell and later segments as Suspense boundaries resolve. It is different from downloading a client bundle in chunks. Node uses renderToPipeableStream; Web Streams runtimes use renderToReadableStream. A shell can contain a heading, navigation and a loading fallback before a delayed panel arrives. The browser may still need JavaScript for hydration and streamed boundary replacement. Buffers in proxies, compression and clients can delay visible progress. This example uses React 19 use with a request-scoped synthetic Promise, no real API.
import React,{Suspense,use} from 'react';import {renderToPipeableStream} from 'react-dom/server';function Stock({result}){return <p>Available: {use(result)} packets</p>;}export function streamGarden(req,res){ let resolveResult;const result=new Promise(resolve=>{resolveResult=resolve;}); const dataTimer=setTimeout(()=>resolveResult(3),100); let failed=false; const stream=renderToPipeableStream(<html lang="en"><head><title>Seed stock</title></head><body><main><h1>Seed stock</h1><Suspense fallback={<p role="status">Loading stock</p>}><Stock result={result}/></Suspense></main></body></html>,{ onShellReady(){res.statusCode=failed?500:200;res.setHeader('Content-Type','text/html; charset=utf-8');stream.pipe(res);}, onShellError(){clearTimeout(dataTimer);if(!res.headersSent){res.statusCode=500;res.setHeader('Content-Type','text/plain; charset=utf-8');res.end('Garden unavailable');}}, onError(error){failed=true;console.error('Synthetic stream:',error.message);} }); const deadline=setTimeout(()=>stream.abort(),2000); function cleanup(){clearTimeout(dataTimer);clearTimeout(deadline);} res.once('finish',cleanup); res.once('close',()=>{cleanup();if(!res.writableFinished)stream.abort();});}This exports an adapter for an approved loopback HTTP server; it does not start a listener. In the happy path the shell may contain Loading stock before the stock result becomes available. The final DOM should contain Available: 3 packets after boundary scripts run. A 100 ms delay is a synthetic input, not a performance guarantee. This streaming-only fixture has no client hydration bundle; it teaches delivery, not interactive React. Error before the shell can select a 500 response; errors after headers are committed cannot change the HTTP status. Abort and connection cleanup bound the fixture. Production needs an explicit CSP/nonce strategy, error policy and reviewed proxy settings.
Choose Web Streams or a completed response
import React from 'react';import {renderToReadableStream} from 'react-dom/server';export async function gardenResponse({waitForAll=false,signal}={}){ const stream=await renderToReadableStream(<html lang="en"><head><title>Garden hours</title></head><body><h1>Garden hours</h1><p>Saturday: 9–12</p></body></html>,{signal}); if(waitForAll)await stream.allReady; return new Response(stream,{headers:{'Content-Type':'text/html; charset=utf-8'}});}This adapter returns a Response in a compatible Web Streams runtime; its caller handles rejected rendering and supplies a request-scoped abort signal. It has no suspended children; waitForAll illustrates the allReady option, not a timing claim. For native Node streaming prefer the pipeable API. For static generation use the React 19 static APIs. Current documentation also lists resume and resumeToPipeableStream on the server side and resumeAndPrerender variants on the static side for continued partial prerenders; those require a compatible exact release, opaque postponed state and matching inputs. Do not assume they exist in every React 19 build. This chapter inventories them without executing them.
Diagnose mismatches before suppressing a warning
import React,{useState,useEffect} from 'react';export default function App(){ const [zone,setZone]=useState('UTC'); useEffect(()=>{setZone(Intl.DateTimeFormat().resolvedOptions().timeZone||'UTC');},[]); return <section><h2>Display preference</h2><p>Time zone: {zone}</p></section>;}This component starts with UTC on both server and client. After hydration the browser can show its actual zone; the exact value depends on the environment. A two-pass render can introduce extra work or a visible change, so use it only when necessary. Avoid reading window, localStorage or current time during initial server rendering; do not use a typeof window branch that changes the first client markup. Diagnose by comparing server HTML (before scripts), parsed DOM (invalid nesting can be corrected by the browser), first client data, locale, identifierPrefix and client build version. Test the shell, stream completion, hydration and interaction independently. suppressHydrationWarning is a narrow one-level escape hatch for unavoidable differences; it does not guarantee text repair and is not a general fix. Practice: introduce an initial snapshot mismatch in a disposable fixture, record the console evidence and fix the underlying data.