React Streaming & Suspense: Architecture, Lifecycle, and Selective Hydration
Streaming & Suspense: Stream component chunks progressively over HTTP to improve initial page speed.
In traditional Server-Side Rendering (SSR), page generation operates as an all-or-nothing pipeline. The server works in strict lockstep: it must resolve 100% of the backend data before it can generate a single byte of HTML, stream that document to the client, or begin hydrating interactive elements.
```text
[ Classic SSR Waterfall ]
1. Database queries (blocks until the slowest query returns) ────┐
2. Render full HTML document on the server ├── High TTFB barrier
3. Flush complete HTML payload to browser │
4. Browser downloads client JavaScript bundle │
5. Hydrate the entire component tree at once ──────────────────┘
```
If an analytical dashboard requires three lightning-fast database queries (50ms) alongside a sluggish third-party reporting endpoint (2,500ms), the entire HTTP response stalls for 2.5 seconds. The user stares at a blank screen or a native browser spinner while Time to First Byte (TTFB) and First Contentful Paint (FCP) suffer.
Streaming SSR with <Suspense> eliminates this bottleneck. Instead of waiting on the slowest operation, the server slices the HTML into progressive segments and streams them over a persistent HTTP connection using chunked transfer encoding (Transfer-Encoding: chunked).
## 1. Under the Hood: Streaming Mechanics
Modern React pairs platform-level streaming APIs (renderToPipeableStream in Node.js, renderToReadableStream on Edge runtimes) with declarative <Suspense> boundaries.
```text
CLIENT BROWSER NODE / EDGE RUNTIME
│ │
│ ──── 1. HTTP GET Request ──────────────────────────────> │
│ │ (Executes Root Layout & shell)
│ <─── 2. Initial HTML Stream (TTFB < 50ms) ────────────── │
│ • , CSS stylesheets, Layout, Navbar │
│ • Fallbacks (Skeletons) │ (Slow async queries run in background)
│ │
[ Paint: Instant FCP / Layout Shell ] │
│ │
│ │ (Slow query resolves!)
│ <─── 3. Streaming Segment ────────────────────────────── │
│ • Hidden holding resolved HTML │
│ • Inline
Tags:#react#suspense#streaming#hydration
