|
| 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,7 +82,16 @@ 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 | const SentryRoot: React.FC<P> = (props: P) => {
|
86 | 96 | // Early return when any of the required functions is not available.
|
87 | 97 | if (!_useEffect || !_useLocation || !_useMatches || !_customStartTransaction) {
|
@@ -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