Skip to content

Commit 3e05280

Browse files
committed
Add options to disable or configure ErrorBoundary.
1 parent 7442128 commit 3e05280

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

packages/react/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export * from '@sentry/browser';
22

33
export { init } from './sdk';
44
export { Profiler, withProfiler, useProfiler } from './profiler';
5-
export type { FallbackRender } from './errorboundary';
5+
export type { ErrorBoundaryProps, FallbackRender } from './errorboundary';
66
export { ErrorBoundary, withErrorBoundary } from './errorboundary';
77
export { createReduxEnhancer } from './redux';
88
export { reactRouterV3Instrumentation } from './reactrouterv3';

packages/remix/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ function App() {
9090
);
9191
}
9292

93-
export default withSentryRouteTracing(App);
93+
export default withSentryRouteTracing(App, {
94+
wrapWithErrorBoundary: false // default: true
95+
errorBoundaryOptions: {
96+
fallback: <p>An error has occurred</p>
97+
} // optional
98+
});
9499
```
95100

96101
To set context information or send manual events, use the exported functions of `@sentry/remix`.

packages/remix/src/performance/client.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ErrorBoundaryProps } from '@sentry/react';
12
import { withErrorBoundary } from '@sentry/react';
23
import { Transaction, TransactionContext } from '@sentry/types';
34
import { getGlobalObject, logger } from '@sentry/utils';
@@ -81,14 +82,23 @@ export function remixRouterInstrumentation(useEffect: UseEffect, useLocation: Us
8182
* Wraps a remix `root` (see: https://remix.run/docs/en/v1/guides/migrating-react-router-app#creating-the-root-route)
8283
* To enable pageload/navigation tracing on every route.
8384
*/
84-
export function withSentryRouteTracing<P extends Record<string, unknown>, R extends React.FC<P>>(OrigApp: R): R {
85+
export function withSentryRouteTracing<P extends Record<string, unknown>, R extends React.FC<P>>(
86+
OrigApp: R,
87+
options: {
88+
wrapWithErrorBoundary?: boolean;
89+
errorBoundaryOptions?: ErrorBoundaryProps;
90+
} = {
91+
wrapWithErrorBoundary: true,
92+
errorBoundaryOptions: {},
93+
},
94+
): R {
8595
// Early return when any of the required functions is not available.
8696
if (!_useEffect || !_useLocation || !_useMatches || !_customStartTransaction) {
8797
__DEBUG_BUILD__ && logger.warn('Remix SDK was unable to wrap your root because of one or more missing parameters.');
8898

8999
// @ts-ignore Setting more specific React Component typing for `R` generic above
90100
// will break advanced type inference done by react router params
91-
return withErrorBoundary(OrigApp);
101+
return OrigApp;
92102
// Note: Error boundary doesn't depend on any of these functions, so we can return the wrapped component.
93103
}
94104

@@ -135,7 +145,13 @@ export function withSentryRouteTracing<P extends Record<string, unknown>, R exte
135145
return <OrigApp {...props} />;
136146
};
137147

148+
if (options.wrapWithErrorBoundary) {
149+
// @ts-ignore Setting more specific React Component typing for `R` generic above
150+
// will break advanced type inference done by react router params
151+
return withErrorBoundary(SentryRoot, options.errorBoundaryOptions);
152+
}
153+
138154
// @ts-ignore Setting more specific React Component typing for `R` generic above
139155
// will break advanced type inference done by react router params
140-
return withErrorBoundary(SentryRoot);
156+
return SentryRoot;
141157
}

0 commit comments

Comments
 (0)