Explain it simply
Streaming in plain language
Imagine ordering rice and three dishes at a restaurant. If one dish needs another twenty minutes on the stove, it is better to serve what is ready and bring the last dish when it is done than to hold everything back. Streaming does the same: it sends the ready parts of a page at once and fills in the slow part when it arrives.
In Next.js you put the slow part inside <Suspense> and give it a fallback, the UI to show while waiting. The rest of the page then stops waiting for it.
Problem → Why → Solution
The problem: one analytics call keeps the whole dashboard blank
On a dashboard the user profile loads in 100 ms but the analytics query takes 3 seconds. The page below returns only after both awaits finish, so the server cannot send any HTML and the user stares at an empty screen for 3 seconds. The profile could be shown right away, but everything waits for analytics.
export default async function DashboardPage() {
const profile = await getProfile(); // about 100 ms
const analytics = await getAnalytics(); // about 3 s: nothing is sent until here
return (
<main>
<h1>Hello, {profile.name}</h1>
<AnalyticsChart data={analytics} />
</main>
);
}Why this matters
While a Server Component is awaiting, the part of the page it belongs to cannot render. Without a Suspense boundary, that 'part' is the entire route. Move the slow data into its own component inside a Suspense boundary, and only that small area has to wait.
Core concept: send the shell first, fill boundaries later
<Suspense fallback={...}> tells React 'while the components inside are not finished, show the fallback'. When the server renders, everything outside the boundary plus the fallback is sent immediately as the first chunk of HTML, the shell. When the data for the async component inside arrives, its HTML is sent as another chunk over the same connection and the browser swaps it in where the fallback was.
The most important rule for streaming is that the slow await must live in a component inside the boundary. If the parent page does await getAnalytics() itself and then returns <Suspense>, the parent is the one waiting and not even the shell can be sent. So split out a small async component that loads the slow data, and keep the parent free of that await.
Lesson 10's loading.tsx is really a Suspense boundary around the whole page. It suits loading UI for an entire page, but when the heading and profile should appear at once and only one chart should wait, a hand-placed <Suspense> is more precise. Sibling boundaries do not wait for each other: each appears as soon as its own data arrives.
| Tool | Boundary size | Use it for |
|---|---|---|
| loading.tsx | The whole route segment | A page that waits on data as a whole |
| <Suspense> | Any component you choose | One slow section inside a page |
Write the fallback as a skeleton the same size as the incoming content rather than a one-line 'Loading…'. If the sizes differ, everything below jumps when the content arrives, which hurts the Cumulative Layout Shift (CLS) score. Boundaries can also be nested: an outer fallback covers a whole panel, and an inner one lets part of that panel appear before the rest.
- Outside + fallbacks form the shell
- The shell is sent immediately
- Data inside a boundary resolves
- Its HTML chunk replaces the fallback
Every await outside a boundary delays the shell.
General pattern
async function SlowPart() {
const data = await loadSlowData(); // the await lives inside the boundary
return <Result data={data} />;
}
export default function Page() {
return (
<Layout>
<FastPart />
<Suspense fallback={<SameSizeSkeleton />}><SlowPart /></Suspense>
</Layout>
);
}Put the slow data in its own async component and wrap it in Suspense, imported from react. The page component itself never awaits that data.
Worked example: streaming the note list
The import line at the top brings in getSlowNotes. Treat getSlowNotes as a slow database query. The page heading appears at once, and only the note list has to wait.
import { Suspense } from "react";
import { getSlowNotes } from "@/lib/notes";
async function SlowNotes() {
const notes = await getSlowNotes();
return notes.map((note) => <article key={note.id}>{note.title}</article>);
}
export default function NotesPage() {
return (
<main>
<h1>Notes</h1>
<Suspense fallback={<p>Loading the note list…</p>}>
<SlowNotes />
</Suspense>
</main>
);
}Code breakdown
- The slow component
async function SlowNotes() {Loading the slow data is moved into its own small component, so it can be placed inside a boundary.
- Await inside the boundary
const notes = await getSlowNotes();This await sits inside SlowNotes, so only SlowNotes waits. NotesPage has no await at all and is not even async.
- Sent in the shell
<h1>Notes</h1>Outside the boundary, so it goes out immediately in the first HTML chunk together with the fallback.
- The boundary
<Suspense fallback={<p>Loading the note list…</p>}>Shows the fallback until SlowNotes finishes, then the note list replaces it. In production, swap this line for a skeleton the size of the list.
The "Notes" heading and the "Loading the note list…" fallback appear immediately. When getSlowNotes finishes, the note titles (for example Routing and Caching) appear as <article> elements in place of the fallback.What travels over the wire
To make streaming visible, this example was run in Node with React's renderToPipeableStream, using a fake getSlowNotes that waits 300 ms. The first chunk holds the heading and the fallback, wrapped in marker comments. Only after 300 ms does a second chunk arrive with the articles in a hidden div plus a small script that swaps them in for the fallback. Real Next.js output is longer because it also carries RSC data, but the idea is the same.
Two chunks of one response (simplified)
---------------------------------------
t = 0 ms <main><h1>Notes</h1>
<!--$?--><template id="B:0"></template>
<p>Loading the note list…</p><!--/$--></main>
t = 300 ms <div hidden id="S:0">
<article>Routing</article><article>Caching</article>
</div>
<script>/* move S:0 into B:0, drop the fallback */</script>Status codes and crawlers
Once the shell is sent the HTTP status is fixed at 200, so calling notFound() inside a boundary shows a 404 UI but cannot change the status (Next.js adds a noindex tag). For certain bots that cannot run JavaScript, Next.js does not stream and instead waits to send the complete page.
In real projects
In real projects
Streaming pays off most on pages whose data sources have different speeds. An e-commerce product page shows the name, price and photo at once and streams recommendations and reviews from separate boundaries, so the user sees what they need to buy first.
- Analytics dashboards give each chart its own Suspense boundary, so fast charts never wait for the slowest one, and a failing chart can get its own error boundary too.
- Design systems ship ready-made skeletons sized like cards, table rows and charts, which are reused as fallbacks.
- When self-hosting, a reverse proxy such as nginx can buffer the response and defeat streaming, so teams check the Next.js self-hosting guide to turn buffering off (lesson 27).
Common mistakes
Common mistakes with streaming
Awaiting the data outside Suspense
Writing const notes = await getSlowNotes(); in the page and returning <Suspense><NoteList notes={notes} /></Suspense> leaves nothing for the boundary to wait on, so the fallback never shows and the whole page waits. Move the await into a component inside the boundary.
A mismatched fallback that makes the layout jump
A one-line fallback 20px tall followed by a 600px list pushes the footer and buttons down suddenly, and users click the wrong thing. Give the fallback a min-height or a matching number of skeleton rows so it is close to the content's size.
Putting every slow part in one boundary
Wrapping three charts in a single Suspense means all three appear together only after the slowest finishes. Give unrelated sections their own boundaries.
Best practices
Best practices
- Draw boundaries from the user's point of view: things that should appear together share one boundary, things that can appear separately get their own.
- Keep the heading, navigation and the page's main information in the shell, and stream only the extras.
- Check your fallbacks yourself by throttling the network in DevTools or toggling Suspense in React DevTools.
Mini challenge
Mini challenge: profile now, activity streamed
Write the /me page. The profile (fast) shows at once, and the activity list (2 seconds) streams in with Suspense. The fallback must be a skeleton the same size as three activity rows.
- The page component does not await getActivity()
- ActivityList is an async Server Component inside Suspense
- ActivitySkeleton shows three rows, each 48px tall
- The profile name is part of the shell
import { Suspense } from "react";
import { getProfile, getActivity } from "@/lib/me"; // getActivity takes ~2 s
// TODO: async component that awaits getActivity() and renders a <ul>
async function ActivityList() {}
// TODO: three grey rows, 48px each, so nothing jumps when the list arrives
function ActivitySkeleton() {}
export default async function MePage() {
const profile = await getProfile(); // fast, fine to await here
// TODO: render the name, then ActivityList inside Suspense with the skeleton
}Expected: Opening the page shows the profile name and three grey rows immediately. After about 2 seconds the activity list takes the rows' place, and the content below does not jump.
Show hint
getProfile is fast, so awaiting it in the page delays the shell by only about 100 ms. Call getActivity only inside ActivityList. Array.from({ length: 3 }) is a handy way to create the skeleton rows.
Show solution
import { Suspense } from "react";
import { getProfile, getActivity } from "@/lib/me";
async function ActivityList() {
const items = await getActivity(); // only this component waits
return (
<ul>
{items.map((item) => (
<li key={item.id} style={{ height: 48 }}>{item.text}</li>
))}
</ul>
);
}
function ActivitySkeleton() {
return (
<ul aria-busy="true">
{Array.from({ length: 3 }, (_, i) => (
<li key={i} style={{ height: 48, background: "#e5e7eb", marginBottom: 4 }} />
))}
</ul>
);
}
export default async function MePage() {
const profile = await getProfile();
return (
<main>
<h1>{profile.name}</h1>
<Suspense fallback={<ActivitySkeleton />}>
<ActivityList />
</Suspense>
</main>
);
}Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- UI outside Suspense boundaries plus their fallbacks is sent at once as the shell; content inside is streamed in later.
- Keep the slow await in an async component inside the boundary; awaiting in the parent defeats streaming.
- loading.tsx covers a whole page, <Suspense> covers one section, and sibling boundaries appear independently.
- Make fallbacks skeletons the size of the content to avoid layout shift.
Next.js — Fetching Data — Next.js
Next.js — Fetching Data — Next.js