Nov 15, 2026
One bad widget shouldn't kill your dashboard
A dashboard is a dozen small apps sharing one page. A sales chart, a stock table, an alerts feed, a revenue card — each one fetches its own data and renders its own slice. And in React, one of them throwing during render takes the whole page down with it. Not just the broken chart. The sidebar, the header, the eleven widgets that were fine. The user gets a white screen and a console error, and the fix for their problem is "reload and hope the bad data is gone."
That is the default, and it is a choice. React has had the tool to stop it since version 16: the error boundary. A boundary is a component that catches errors thrown while its children render, and shows a fallback instead of letting the error unmount the tree. The catch is the shape of it — it has to be a class component. There is still no hook version of this. Two lifecycle methods do the work: getDerivedStateFromError runs during render and returns the state that switches to the fallback, and componentDidCatch runs after, with the error and a component stack, which is where logging belongs.
import { Component, type ReactNode } from "react";
type Props = { children: ReactNode };
type State = { hasError: boolean };
export class WidgetBoundary extends Component<Props, State> {
state: State = { hasError: false };
static getDerivedStateFromError(): State {
return { hasError: true };
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
// Log it. A fallback nobody monitors is a bug you stopped seeing.
console.error("Widget failed:", error, info.componentStack);
}
reset = () => this.setState({ hasError: false });
render() {
if (this.state.hasError) {
return (
<div>
<p>This widget couldn't load.</p>
<button onClick={this.reset}>Try again</button>
</div>
);
}
return this.props.children;
}
}
If you would rather not write a class, the react-error-boundary package wraps the same mechanism in a function-component API. Either way, the placement is the whole point:
<DashboardGrid>
<WidgetBoundary>
<SalesChart />
</WidgetBoundary>
<WidgetBoundary>
<StockTable />
</WidgetBoundary>
<WidgetBoundary>
<AlertsFeed />
</WidgetBoundary>
</DashboardGrid>
One boundary at the top of the page is barely better than none — the fallback replaces the whole page either way. A boundary around each widget shrinks the blast radius to the widget that actually broke. The sales chart can fail while the stock table keeps working, and the user can retry just the chart.
Next.js App Router gives you the same idea as a file convention. An error.tsx in a route segment wraps that segment in a boundary. It has to be a Client Component, it receives an error and a reset, and reset re-renders the segment without a full page reload:
// app/dashboard/error.tsx
"use client";
export default function DashboardError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
return (
<div>
<h2>This section couldn't load.</h2>
<button onClick={reset}>Try again</button>
</div>
);
}
Two things to know about it. It does not catch errors thrown by the layout.tsx in its own segment — the boundary sits inside that layout, so the layout's errors bubble to the parent segment's error.tsx, or to global-error.tsx for the root layout. And global-error.tsx is the last resort: it replaces the whole root layout, so it has to render its own <html> and <body>, and it only fires in production — in development you get the error overlay instead. In production, Next.js also strips the server error message and hands the browser a digest, so the log on the server is where the real error lives.
And the honest limits, because a boundary that feels like safety can quietly become a hiding place. It only catches errors during render — in the children, in their lifecycle methods and constructors. It does not catch errors in event handlers, in setTimeout or promise callbacks, or during server rendering. A button that throws in onClick needs an ordinary try/catch, boundary or not. It cannot catch its own errors either — if the fallback throws, the error goes to the boundary above it. And retrying a deterministic error just fails again: a chart that crashes on a null value will crash the same way on reset until the data or the code changes. The boundary buys the user a working page while you fix the real bug; it is not the fix.
The rule I use now: every widget that fetches its own data gets its own boundary, the fallback always says what broke in plain words and offers a retry, and every catch is logged somewhere a human will see it. The question to ask about any dashboard is simple: if one widget throws, what does the user still see? If the answer is "nothing", the boundary is missing, and the next bad row of data will take the whole page down with it.