Skip to content

Commit a2bf37b

Browse files
cursoragentn3ps
andcommitted
fix: add RouteErrorBoundary for data router error handling
The data router catches render errors internally instead of letting them reach the React class component error boundary. Add an errorElement on the root route that renders the same ErrorPage component and reports to Sentry, so intentional page crashes (developer options, E2E tests) still show the custom error page. Co-authored-by: Francis Nepomuceno <n3ps@users.noreply.github.com>
1 parent e9c3ee2 commit a2bf37b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ui/pages/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Outlet,
77
RouterProvider,
88
createHashRouter,
9+
useRouteError,
910
} from 'react-router-dom';
1011
import { QueryClientProvider } from '@tanstack/react-query';
1112
import { captureException } from '../../shared/lib/sentry';
@@ -25,6 +26,20 @@ import ErrorPage from './error-page/error-page.component';
2526

2627
import Routes, { routeConfig } from './routes';
2728

29+
/**
30+
* Error boundary for the data router. When a route component throws,
31+
* createHashRouter catches it internally instead of letting it reach the
32+
* React class component boundary. This renders the same ErrorPage used by
33+
* the class boundary, and reports to Sentry.
34+
*/
35+
function RouteErrorBoundary() {
36+
const error = useRouteError();
37+
38+
captureException(error);
39+
40+
return <ErrorPage error={error} />;
41+
}
42+
2843
/**
2944
* Root layout route element containing all context providers.
3045
* Renders <Outlet /> which is replaced by the matched child route (<Routes />).
@@ -63,6 +78,7 @@ const router = createHashRouter([
6378
children: [
6479
{
6580
element: <Routes />,
81+
errorElement: <RouteErrorBoundary />,
6682
children: routeConfig,
6783
},
6884
],

0 commit comments

Comments
 (0)