Nested Boundaries for Progressive Fallbacks
What you'll learn: How to layer multiple error boundaries at different depths to display increasingly specific fallback UI as errors occur deeper in your component tree.
The Layered Safety Net Concept
Think of nested error boundaries like safety nets at a circus: there's a big net at the bottom catching anyone who falls, but smaller nets at various heights catch performers before they fall all the way down. Each net provides a more specific, contextual response to the failure.
In React, you can place error boundaries at multiple levels—wrapping your entire app, specific routes, individual features, and even risky components. When an error occurs, the nearest parent boundary catches it and shows its fallback, while the rest of the app continues working.
How Progressive Fallbacks Work
// App-level: Very generic fallback
<AppErrorBoundary fallback={<FullPageError />}>
<Header />
{/* Route-level: Contextual to the page */}
<RouteErrorBoundary fallback={<PageError />}>
{/* Feature-level: Specific to the feature */}
<FeatureErrorBoundary fallback={<FeatureUnavailable />}>
<UserDashboard />
</FeatureErrorBoundary>
</RouteErrorBoundary>
<Footer />
</AppErrorBoundary>
If UserDashboard throws an error, only the FeatureErrorBoundary catches it—showing <FeatureUnavailable /> while keeping the header, footer, and rest of the page working. The outer boundaries never activate.
If the RouteErrorBoundary itself crashes, then the AppErrorBoundary catches it as a last resort.
Why This Matters
This strategy provides graceful degradation: users see the most helpful, contextualized error message possible, and the smallest possible portion of your UI breaks. A broken widget doesn't take down the entire page.
Key Takeaway: Stack error boundaries at multiple levels—app, route, feature, component—so errors are caught by the nearest, most specific boundary, providing progressive fallbacks that preserve as much working UI as possible.