feat: add top-level ErrorBoundary component#1698
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
0fa7ae0 to
b8f873e
Compare
6b11c41 to
fe1d7b6
Compare
2f5f3a3 to
bedeb6d
Compare
fe1d7b6 to
8a682a5
Compare
| // Fallback: no error boundary (just render children) | ||
| // In the future, this could check for other error reporting services | ||
| return <>{children}</>; |
There was a problem hiding this comment.
We can use ErrorBoundary from react-error-boundary package (which is already in). You may read more in https://kentcdodds.com/blog/use-react-error-boundary-to-handle-errors-in-react or start from https://www.npmjs.com/package/react-error-boundary
8a682a5 to
f544686
Compare
bedeb6d to
2b4b0cd
Compare
f544686 to
5d61c09
Compare
2b4b0cd to
7e226d9
Compare
5d61c09 to
9dafa4a
Compare
7e226d9 to
9322f42
Compare
|
Note: I am actively working on implementing a refactor to simplify the contents of this PR |
9dafa4a to
8415728
Compare
9322f42 to
43d5e44
Compare
89f0750 to
8d037cb
Compare
15c6748 to
61c8e8c
Compare
2902339 to
ed1e34c
Compare
7c245df to
70faa8f
Compare
ed1e34c to
6e0d9af
Compare
70faa8f to
962f3c9
Compare
6e0d9af to
58105fb
Compare
src/components/shared/ErrorPage.tsx
Outdated
|
|
||
| const handleRefresh = () => { | ||
| reset?.(); | ||
| resetFn?.(); |
There was a problem hiding this comment.
I mentioned this in the other PR, but maybe we just add a default value to reset so we don't have to conditionally render this function call?
| export const ErrorBoundary = ({ children }: ErrorBoundaryProps) => { | ||
| if (isBugsnagEnabled()) { | ||
| const BugsnagBoundary = | ||
| Bugsnag.getPlugin("react")!.createErrorBoundary(React); |
There was a problem hiding this comment.
The non-null assertion (!) here could cause a runtime crash if the React plugin isn't properly initialized. We should avoid non-null assertions and add explicit null checks instead.
const reactPlugin = Bugsnag.getPlugin("react");
if (!reactPlugin) {
console.error("Bugsnag React plugin not initialized");
return (
<ReactErrorBoundary FallbackComponent={ErrorPage}>
{children}
</ReactErrorBoundary>
);
}
const BugsnagBoundary = reactPlugin.createErrorBoundary(React);This gracefully falls back to the standard ReactErrorBoundary if Bugsnag's plugin fails to load, rather than crashing the entire app.
There was a problem hiding this comment.
Added the safety check and fallback to react error boundary
58105fb to
d007c8f
Compare
962f3c9 to
5301a3c
Compare
5301a3c to
cebab76
Compare
d007c8f to
eff2df2
Compare
22efe5e to
fbedc98
Compare
eff2df2 to
323067b
Compare
323067b to
4d002ca
Compare
fbedc98 to
1df39d6
Compare
Add decoupled ErrorBoundary component that determines which error reporting service to use. Currently supports Bugsnag, but designed to be extensible for other services. Integrate into app root.
4d002ca to
4e110c2
Compare
Merge activity
|

Description
Added a new
ErrorBoundarycomponent that wraps the entire application to catch and handle React errors. The component integrates with Bugsnag for error reporting when enabled, with a fallback option for when Bugsnag is not available. The implementation includes a custom error handler UI component and has been integrated at the root level of the application.Type of Change
Checklist
Test Instructions