Performance: Nested error boundaries
Nested error boundaries affect the rendering flow during error handling and recovery, impacting interaction responsiveness and visual stability.
export function RootErrorBoundary() {
return <div>Root error fallback UI.</div>;
}
export function DashboardErrorBoundary() {
return <div>Dashboard error fallback UI.</div>;
}
// Nested error boundaries isolate errors to specific UI partsexport function ErrorBoundary() {
return <div>Something went wrong.</div>;
}
// Single global error boundary wrapping entire app| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single global error boundary | Re-renders entire app DOM subtree | Triggers full page reflow | High paint cost due to large repaint area | [X] Bad |
| Nested error boundaries | Re-renders only affected UI subtree | Triggers localized reflow | Lower paint cost with smaller repaint area | [OK] Good |
export function ErrorBoundary() { return <div>Outer Error</div> }
export function InnerErrorBoundary() { return <div>Inner Error</div> }
function InnerComponent() { throw new Error('fail') }
export default function App() {
return (
<ErrorBoundary>
<InnerErrorBoundary>
<InnerComponent />
</InnerErrorBoundary>
</ErrorBoundary>
)
}export function ErrorBoundary() {
return <div>Outer Error</div>
}
export function ErrorBoundary() {
return <div>Inner Error</div>
}Pass the test and this pattern moves unknown