|
| 1 | +import type { ErrorBoundaryProps } from '@sentry/react'; |
1 | 2 | import { withErrorBoundary } from '@sentry/react';
|
2 | 3 | import { Transaction, TransactionContext } from '@sentry/types';
|
3 | 4 | import { getGlobalObject, logger } from '@sentry/utils';
|
@@ -81,14 +82,23 @@ export function remixRouterInstrumentation(useEffect: UseEffect, useLocation: Us
|
81 | 82 | * Wraps a remix `root` (see: https://remix.run/docs/en/v1/guides/migrating-react-router-app#creating-the-root-route)
|
82 | 83 | * To enable pageload/navigation tracing on every route.
|
83 | 84 | */
|
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 { |
85 | 95 | // Early return when any of the required functions is not available.
|
86 | 96 | if (!_useEffect || !_useLocation || !_useMatches || !_customStartTransaction) {
|
87 | 97 | __DEBUG_BUILD__ && logger.warn('Remix SDK was unable to wrap your root because of one or more missing parameters.');
|
88 | 98 |
|
89 | 99 | // @ts-ignore Setting more specific React Component typing for `R` generic above
|
90 | 100 | // will break advanced type inference done by react router params
|
91 |
| - return withErrorBoundary(OrigApp); |
| 101 | + return OrigApp; |
92 | 102 | // Note: Error boundary doesn't depend on any of these functions, so we can return the wrapped component.
|
93 | 103 | }
|
94 | 104 |
|
@@ -135,7 +145,13 @@ export function withSentryRouteTracing<P extends Record<string, unknown>, R exte
|
135 | 145 | return <OrigApp {...props} />;
|
136 | 146 | };
|
137 | 147 |
|
| 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 | + |
138 | 154 | // @ts-ignore Setting more specific React Component typing for `R` generic above
|
139 | 155 | // will break advanced type inference done by react router params
|
140 |
| - return withErrorBoundary(SentryRoot); |
| 156 | + return SentryRoot; |
141 | 157 | }
|
0 commit comments