React Server Components 13 🧬 Streaming with Suspense — Progressive rendering across the boundary
Streaming is the mechanism that turns a server-rendered page from a single blocking response into a sequence of chunks. The static shell arrives first, the browser paints it immediately, and the slower regions stream in as their data resolves. In the RSC model, the unit that controls this is the <Suspense> boundary: everything outside it is part of the shell, and everything inside it is a “hole” that React fills when the data is ready. The boundary is not a client-side loading spinner; it is a server-side rendering instruction that determines which HTML is sent first and which HTML is sent later .
This chapter covers the streaming pipeline across the server-client boundary: how the shell is identified, how Suspense fallbacks are sent, how the resolved content replaces the fallback, and how to structure the component tree so that the boundaries are placed for granularity rather than convenience.
Key point: The <Suspense> boundary is the unit of streaming. Everything outside the boundary is sent immediately as the shell. Everything inside the boundary is sent as a fallback, followed by the resolved content when the data is ready. The boundary must be placed as close to the dynamic data access as possible, or the entire page streams behind one fallback.
Why streaming is Suspense-aware
The shell problem. Without streaming, the server waits for every data fetch before sending any HTML. The Time to First Byte (TTFB) equals the slowest query, and the user sees a blank screen for that duration. With streaming, the server sends the static shell—the layout, the headings, the cached content—as soon as it is rendered. The TTFB drops to the time it takes to render the shell, and the First Contentful Paint (FCP) is decoupled from the data fetching time .
The boundary problem. The shell is not an arbitrary portion of the page. It is defined by the <Suspense> boundaries. React renders the tree, and when it encounters a component that suspends (because it is waiting on a Promise), it stops rendering that subtree, emits the fallback instead, and continues rendering the rest of the tree. The shell is the part that completed without suspending. The holes are the parts that suspended .
The replacement problem. When the Promise resolves, React does not re-render the entire page. It streams the completed HTML for the suspended subtree, along with an inline script that swaps the fallback for the real content. The rest of the page remains intact. This is why a mid-stream error can be caught by the nearest error.js boundary without destroying the shell: the shell has already been sent and painted .
a. The shell and the boundary placement
The shell is everything outside the <Suspense> boundaries. A page with a header, a sidebar, and a slow chart should render the header and sidebar as part of the shell, and wrap only the chart in a boundary.
// app/dashboard/page.tsx
import { Suspense } from 'react'
export default function DashboardPage() {
return (
<div>
<h1>Dashboard</h1> {/* shell */}
<Sidebar /> {/* shell */}
<Suspense fallback={<ChartSkeleton />}>
<RevenueChart /> {/* hole */}
</Suspense>
</div>
)
}
The h1 and the Sidebar are sent immediately. The RevenueChart suspends, so the ChartSkeleton is sent instead. When the chart’s data resolves, the completed HTML is streamed and the skeleton is replaced. The user sees the page structure immediately and the chart when it is ready .
The placement of the boundary determines the granularity. If the boundary wraps the entire page, the shell is empty and the user sees a full-page skeleton. If the boundary wraps only the dynamic component, the shell contains the static content and the skeleton is scoped to the hole. The Next.js documentation recommends placing the boundary close to the dynamic data access rather than relying on a high-level loading.js .
b. Multiple boundaries and parallel streaming
A page can have multiple independent <Suspense> boundaries. Each boundary streams independently, and a slow boundary does not delay a fast one. This is the mechanism that allows a dashboard to show the revenue chart before the user growth chart, even though both are fetching data.
// app/dashboard/page.tsx
export default function DashboardPage() {
return (
<div className="grid">
<Suspense fallback={<RevenueSkeleton />}>
<RevenueChart />
</Suspense>
<Suspense fallback={<GrowthSkeleton />}>
<UserGrowth />
</Suspense>
</div>
)
}
The two async components start their fetches when React renders them. The shell and both fallbacks are sent immediately. The revenue chart streams in when its fetch resolves, and the growth chart streams in when its fetch resolves, independently of each other. The Promise.all pattern is not needed; the boundaries provide the parallelism .
c. The HTTP constraint and mid-stream errors
Streaming changes the HTTP contract. Once the first chunk is sent—the shell and the fallbacks—the status code is committed to 200 OK. It cannot be changed to a 4xx or 5xx later, because the headers have already been transmitted. This is a fundamental constraint of the HTTP protocol, not a React limitation .
The implication is that a notFound() or a redirect() that fires after streaming has started cannot produce a real HTTP status code or a real Location header. Next.js handles this by injecting a <meta name="robots" content="noindex"> for notFound() and by converting the redirect to a client-side navigation. To get a real status code, the notFound() must be called before any await or <Suspense> boundary .
A mid-stream error—a component that throws after the shell has been sent—is caught by the nearest error.js boundary. The error UI replaces the failed component’s region, and the rest of the page remains intact. The status code remains 200, but the user sees an error message instead of the failed content .
Complete Example Session
// ============================================
// PART 1: THE SHELL
// ============================================
// app/products/page.tsx
export default function ProductsPage() {
return (
<div>
<h1>Products</h1>
<p>Browse our catalog below.</p>
{/* The h1 and p are the shell. */}
</div>
)
}
// ============================================
// PART 2: THE BOUNDARY
// ============================================
import { Suspense } from 'react'
<Suspense fallback={<ProductGridSkeleton />}>
<ProductGrid />
</Suspense>
// The grid is the hole.
// The skeleton is sent immediately.
// ============================================
// PART 3: THE ASYNC COMPONENT
// ============================================
async function ProductGrid() {
const products = await getProducts()
return <ul>{products.map((p) => <li key={p.id}>{p.name}</li>)}</ul>
}
// The component suspends while getProducts is pending.
// React emits the fallback and continues rendering the shell.
// ============================================
// PART 4: MULTIPLE BOUNDARIES
// ============================================
export default function DashboardPage() {
return (
<div>
<h1>Dashboard</h1>
<Suspense fallback={<ChartSkeleton />}>
<RevenueChart />
</Suspense>
<Suspense fallback={<ActivitySkeleton />}>
<RecentActivity />
</Suspense>
</div>
)
}
// Each boundary streams independently.
// A slow chart does not delay the activity feed.
// ============================================
// PART 5: THE PROGRESSIVE ENHANCEMENT
// ============================================
export default function Layout({ children }) {
return (
<html>
<body>
<Header /> {/* shell */}
{children} {/* streamed */}
<Footer /> {/* shell */}
</body>
</html>
)
}
// The layout is the shell.
// The page content streams inside it.
// ============================================
// PART 6: THE LOADING.JS SHORTHAND
// ============================================
// app/dashboard/loading.tsx
export default function Loading() {
return <DashboardSkeleton />
}
// Wraps the entire segment in one Suspense boundary.
// Use only when nothing in the segment renders without data.
// ============================================
// PART 7: THE GRANULAR BOUNDARY
// ============================================
// Prefer explicit Suspense over loading.js
<Suspense fallback={<RevenueSkeleton />}>
<RevenueChart />
</Suspense>
// The header and sidebar remain part of the shell.
// Only the chart streams behind a fallback.
// ============================================
// PART 8: THE MID-STREAM ERROR
// ============================================
// app/dashboard/error.tsx
'use client'
export default function Error({ error, retry }) {
return <button onClick={() => retry()}>Retry</button>
}
// If RevenueChart throws, the error boundary catches it.
// The shell and the other boundaries remain intact.
// ============================================
// PART 9: THE HTTP CONSTRAINT
// ============================================
// The shell is sent with 200 OK.
// A notFound() after streaming cannot produce a 404.
// Place notFound() before any await or Suspense boundary.
// ============================================
// PART 10: THE PROXY BUFFERING CHECK
// ============================================
// Nginx buffers responses by default.
// Add: proxy_buffering off;
// Or: add_header X-Accel-Buffering no;
// Streaming only helps if the proxy passes the chunks through.
The ten parts covered the shell, the boundary, the async component, multiple boundaries, progressive enhancement, the loading.js shorthand, the granular boundary, the mid-stream error, the HTTP constraint, and the proxy buffering check.
Quick Reference
The streaming pipeline
| Stage | What happens |
|---|---|
| Shell render | Static content outside boundaries is rendered |
| Suspense encounter | React emits the fallback for the suspended subtree |
| Stream send | Shell and fallbacks are sent as the first chunks |
| Promise resolve | The completed HTML for the subtree is streamed |
| Client swap | An inline script replaces the fallback with the content |
Boundary placement
| Placement | Shell size | Granularity |
|---|---|---|
| Whole page | Empty | Full-page skeleton |
Segment (loading.js) | Layout only | Segment skeleton |
| Near the data access | Maximum | Component skeleton |
HTTP constraints
| Situation | Result |
|---|---|
| Shell sent | Status code is committed to 200 |
notFound() before streaming | Real 404 |
notFound() after streaming | noindex meta, no status change |
| Error inside a boundary | Caught by error.js, status remains 200 |
Infrastructure checks
| Layer | Check |
|---|---|
| Reverse proxy | Disable buffering (X-Accel-Buffering: no) |
| CDN | Verify chunked response support |
| Compression | Verify the compressor flushes chunks |
| Client | Safari buffers until 1 KB |
Best Practices
✅ Do This:
// Place the boundary close to the dynamic component
<Suspense fallback={<ChartSkeleton />}>
<RevenueChart />
</Suspense> // ✅
// Use multiple boundaries for independent data
<Suspense fallback={<A />}><ComponentA /></Suspense>
<Suspense fallback={<B />}><ComponentB /></Suspense> // ✅
// Call notFound() before any await or boundary
if (!post) notFound() // ✅
# Disable proxy buffering for streaming
proxy_buffering off; // ✅
❌ Don’t Do This:
// Wrap the entire page in one boundary
<Suspense fallback={<FullPageSkeleton />}>
<Page />
</Suspense> // ❌
// Await the slow data in the page component
const data = await getSlowData() // ❌
// Call notFound() after streaming has started
const data = await getData()
if (!data) notFound() // ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Full-page skeleton | Boundary at the page level | Move the boundary to the dynamic component |
| Streaming does not work in production | Proxy or CDN buffers the response | Disable buffering; check the CDN |
notFound() returns 200 | Called after streaming started | Move it before the await |
| One slow component blocks another | Both inside one boundary | Use separate boundaries |
| Fallback causes layout shift | Skeleton does not match the content size | Match the skeleton dimensions |
Real-World Examples
1. Shell with a boundary
<h1>Dashboard</h1>
<Suspense fallback={<ChartSkeleton />}>
<RevenueChart />
</Suspense>
2. Multiple independent boundaries
<Suspense fallback={<RevenueSkeleton />}><RevenueChart /></Suspense>
<Suspense fallback={<GrowthSkeleton />}><UserGrowth /></Suspense>
3. Async component
async function RevenueChart() {
const data = await getRevenue()
return <Chart data={data} />
}
4. Mid-stream error boundary
// app/dashboard/error.tsx
'use client'
export default function Error({ retry }) { return <button onClick={retry}>Retry</button> }
5. Proxy buffering off
proxy_buffering off;
6. The loading.js shorthand
// app/dashboard/loading.tsx
export default function Loading() { return <Skeleton /> }
7. The notFound() placement
const post = await getPost(slug)
if (!post) notFound()
8. The shell
<Header />
{children}
<Footer />
9. The chunk check
curl -N http://localhost:3000/dashboard
10. The decision
Dynamic component? → wrap it in Suspense
Static component? → leave it in the shell
Visual
The streaming pipeline
┌─────────────────────────────────────────────────────────────┐
│ Server renders the tree │
│ │ │
│ ├── shell (outside boundaries) ──► sent immediately │
│ │ │
│ └── boundary ──► fallback sent ──► content streams │
│ │
│ Browser paints the shell, shows the fallback │
│ When the Promise resolves, the fallback is replaced │
└─────────────────────────────────────────────────────────────┘
The shell and the hole
┌─────────────────────────────────────────────────────────────┐
│ <h1>Dashboard</h1> ← shell │
│ <Sidebar /> ← shell │
│ <Suspense fallback={<Skeleton />}> │
│ <RevenueChart /> ← hole │
│ </Suspense> │
│ │
│ Shell sent first. Hole streamed when ready. │
└─────────────────────────────────────────────────────────────┘
Multiple boundaries
┌─────────────────────────────────────────────────────────────┐
│ Boundary A: RevenueChart ──► streams at t=200ms │
│ Boundary B: UserGrowth ──► streams at t=800ms │
│ │
│ The shell and both fallbacks are sent at t=0. │
│ Each boundary resolves independently. │
└─────────────────────────────────────────────────────────────┘
The HTTP constraint
┌─────────────────────────────────────────────────────────────┐
│ Shell sent ──► 200 OK committed │
│ │ │
│ ├── notFound() ──► noindex meta, status remains 200 │
│ │ │
│ ├── redirect() ──► client-side redirect │
│ │ │
│ └── error thrown ──► error.js catches, status 200 │
└─────────────────────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Streaming unit | <Suspense> boundary |
| Shell | Content outside the boundaries |
| Fallback | Content sent in place of the suspended subtree |
| Replacement | Inline script swaps fallback for content |
| Parallelism | Multiple boundaries stream independently |
| HTTP constraint | Status committed after first chunk |
| Mid-stream error | Caught by error.js, status remains 200 |
| Proxy buffering | Must be disabled for streaming |
Key takeaways:
- The
<Suspense>boundary is the unit of streaming. Everything outside the boundary is the shell and is sent immediately. Everything inside is a hole that streams when the data resolves. The boundary must be placed close to the dynamic data access for granularity . - Multiple boundaries stream in parallel. Each boundary resolves independently, so a slow component does not delay a fast one. The shell and all fallbacks are sent at the start, and each completed subtree is streamed as its Promise resolves .
- The HTTP status is committed after the first chunk. A
notFound()orredirect()that fires after streaming has started cannot produce a real status code. Place them before anyawaitor<Suspense>boundary. A mid-stream error is caught byerror.jsand the status remains200. - The proxy must not buffer the response. Nginx and some CDNs buffer by default, which defeats the purpose of streaming. Disable buffering on the proxy and verify the CDN supports chunked responses .
- The shell should contain the static content. The header, the sidebar, and the layout belong in the shell. Only the components that await data belong inside a boundary. A page that wraps everything in one boundary has an empty shell and shows a full-page skeleton .
Remember: Streaming is not about sending bytes faster. It is about sending the right bytes first. The shell is the part of the page that can render without waiting for data. The Suspense boundary is the marker that separates the shell from the holes. Place the boundaries close to the data, use multiple boundaries for independent data, and verify that the infrastructure passes the chunks through. The result is a page that paints immediately and fills in progressively.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!