Suspense boundaries and reveal behavior
<Suspense> lets React temporarily show a fallback while part of a render is not ready.
The important mental model is not βSuspense is a spinner component.β It is:
A Suspense boundary is a reveal boundary. It coordinates when a subtree may become visible.
import { Suspense } from 'react';
export default function Page() {
return (
<Suspense fallback={<PageSkeleton />}>
<PageContent />
</Suspense>
);
}
What can suspend?β
Stable Suspense can participate in work such as:
- a component loaded with
lazy; - a Promise read with
use; - Suspense-enabled framework data sources;
- stylesheet loading React coordinates;
- streaming server-rendered content that has not reached the client yet.
Suspense does not automatically detect ordinary fetching started in an Effect or event handler.
useEffect(() => {
fetch('/api/products').then(/* ... */);
}, []);
That is ordinary explicit loading-state code, not Suspense-driven rendering.
The closest boundary handles suspensionβ
<Suspense fallback={<PageSkeleton />}>
<Header />
<Suspense fallback={<ResultsSkeleton />}>
<SearchResults />
</Suspense>
</Suspense>
ResultsSkeleton.If the inner fallback itself suspends, React continues upward to the next Suspense boundary.
Reveal order is UX architectureβ
A single large boundary coordinates one reveal. Nested boundaries allow staged reveal.
Wait for the whole region, then reveal it together.
Shell β biography β albums β recommendations can reveal in meaningful stages.
Do not wrap every component in Suspense. A boundary should correspond to a loading state the user understands.
First-mount suspension and stateβ
If a tree suspends before its first successful mount, React retries later; state from the incomplete render attempt is not preserved as mounted state.
This is one reason rendering must remain pure.
Already visible content may suspend againβ
If an already revealed region suspends during an urgent update, React may need to replace it with the boundary fallback.
Visible results β fallback/skeleton β fresh results.
Visible results stay useful β pending/stale feedback β fresh results.
useTransition and useDeferredValue help express when old content is still useful while the next render prepares.
Layout Effects and hidden Suspense contentβ
If React hides already visible content because it suspended again, layout Effects in that hidden subtree are cleaned up. When the content becomes visible again, layout Effects run again.
useLayoutEffect(() => {
const rect = ref.current.getBoundingClientRect();
// measure currently visible committed layout
}, []);
Suspense and Effects solve different problemsβ
When is this subtree ready to be shown?
Which external system must be synchronized with committed UI/state?
Suspense and Error Boundariesβ
Suspense handles not ready yet. Error Boundaries handle failed rendering/resource work.
A rejected lazy import or failed resource should surface to an appropriate error boundary rather than being treated as loading forever.
Suspense does not define cachingβ
Suspense coordinates rendering when work is not ready. It does not decide cache lifetime, request deduplication, staleness, retries, or mutation invalidation. Those belong to the framework or data layer.
Suspense and server renderingβ
Suspense is also part of streaming SSR and hydration architecture.
The SSR section covers the server APIs in detail.
Boundary placement decisionβ
Common mistakesβ
Giant root spinnerβ
<Suspense fallback={<FullScreenSpinner />}>
<EntireApplication />
</Suspense>
A root boundary can be a last resort, but relying only on it makes unrelated regions disappear together.
Expecting Effect fetching to suspendβ
function Products() {
const [products, setProducts] = useState(null);
useEffect(() => {
fetchProducts().then(setProducts);
}, []);
if (!products) return <Spinner />;
return <ProductList products={products} />;
}
This is explicit loading-state code. That is validβjust know which model you are using.
Destructive fallback replacementβ
If a small nested region suspends, avoid replacing a useful whole page with a spinner. Prefer stable shells, localized skeletons, or stale-but-useful content when correct.
Debugging Suspenseβ
When a fallback appears unexpectedly, inspect:
- Which child suspended?
- Which boundary is closest?
- Was the update urgent or a Transition?
- Is the Promise/resource identity stable?
- Did a key reset the subtree?
- Was a lazy component declared inside another component?
- Can the fallback itself suspend?
Production design principleβ
Good Suspense architecture tends to produce stable shells, localized skeletons, progressive reveal, visible navigation feedback, stale-but-useful content when appropriate, and separate error recovery.
Exerciseβ
Build a dashboard with profile, notifications, sales chart, and recent activity. Start with one Suspense boundary, then redesign it with nested boundaries and explain each boundary from the user's perspective.
Interview questionsβ
Beginner: What does <Suspense> render while its children are not ready?
Intermediate: What kinds of work activate Suspense, and why does fetching inside useEffect not automatically do so?
Senior: How would you place Suspense boundaries for a route with navigation, cached content, streaming server data, and independently slow panels?
Summaryβ
Referencesβ
- https://react.dev/reference/react/Suspense
- https://react.dev/reference/react/use
- https://react.dev/reference/react/lazy
Nextβ
Next, learn how lazy combines code splitting with Suspense.