Data & Streaming · 9 min read · Intermediate
Streaming with Suspense, loading.tsx & error.tsx
Show instant skeletons and isolate slow widgets or runtime failures with React Suspense, loading.tsx, and error.tsx.
What you'll learn
- Add route-level skeleton UI with loading.tsx
- Stream slow sub-panels independently with <Suspense fallback={...}>
- Recover gracefully from errors using a 'use client' error.tsx boundary
Overview
Show instant skeletons and isolate slow widgets or runtime failures with React Suspense, loading.tsx, and error.tsx.
Next.js App Router unifies server rendering, streaming, type-safe mutations, and edge-ready caching inside a single React + TypeScript codebase.
Production Code Example
// app/dashboard/page.tsx
import { Suspense } from 'react';
import { SlowStats } from './SlowStats';
export default function DashboardPage() {
return (
<section>
<h1>Dashboard</h1>
<Suspense fallback={<p>Loading metrics...</p>}>
<SlowStats />
</Suspense>
</section>
);
}
Key Takeaways
- Add route-level skeleton UI with loading.tsx
- Stream slow sub-panels independently with
<Suspense>fallbacks - Recover gracefully from errors using a ‘use client’ error.tsx boundary
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why must `error.tsx` in the Next.js App Router include `'use client'` at the top?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.