|
1 | 1 | import type { ErrorBoundaryProps } from '@sentry/react'; |
2 | | -import { getCurrentHub, WINDOW, withErrorBoundary } from '@sentry/react'; |
| 2 | +import { WINDOW, withErrorBoundary } from '@sentry/react'; |
3 | 3 | import type { Transaction, TransactionContext } from '@sentry/types'; |
4 | 4 | import { isNodeEnv, logger } from '@sentry/utils'; |
5 | 5 | import * as React from 'react'; |
6 | 6 |
|
7 | | -import { getFutureFlagsBrowser } from '../utils/futureFlags'; |
8 | | -import type { RemixOptions } from '../utils/remixOptions'; |
| 7 | +import { getRemixVersion } from '../utils/futureFlags'; |
9 | 8 |
|
10 | 9 | const DEFAULT_TAGS = { |
11 | 10 | 'routing.instrumentation': 'remix-router', |
@@ -41,13 +40,6 @@ let _useMatches: UseMatches; |
41 | 40 | let _customStartTransaction: (context: TransactionContext) => Transaction | undefined; |
42 | 41 | let _startTransactionOnLocationChange: boolean; |
43 | 42 |
|
44 | | -function isRemixV2(): boolean { |
45 | | - const client = getCurrentHub().getClient(); |
46 | | - const opt = client && (client.getOptions() as RemixOptions); |
47 | | - |
48 | | - return (opt && opt.isRemixV2) || getFutureFlagsBrowser()?.v2_errorBoundary || false; |
49 | | -} |
50 | | - |
51 | 43 | function getInitPathName(): string | undefined { |
52 | 44 | if (WINDOW && WINDOW.location) { |
53 | 45 | return WINDOW.location.pathname; |
@@ -109,6 +101,9 @@ export function withSentry<P extends Record<string, unknown>, R extends React.FC |
109 | 101 | errorBoundaryOptions: {}, |
110 | 102 | }, |
111 | 103 | ): R { |
| 104 | + // This part runs on the server-side so it's safe to use `getRemixVersion` here. |
| 105 | + const remixVersion = getRemixVersion(); |
| 106 | + |
112 | 107 | const SentryRoot: React.FC<P> = (props: P) => { |
113 | 108 | // Early return when any of the required functions is not available. |
114 | 109 | if (!_useEffect || !_useLocation || !_useMatches || !_customStartTransaction) { |
@@ -162,7 +157,7 @@ export function withSentry<P extends Record<string, unknown>, R extends React.FC |
162 | 157 |
|
163 | 158 | isBaseLocation = false; |
164 | 159 |
|
165 | | - if (!isRemixV2() && options.wrapWithErrorBoundary) { |
| 160 | + if (remixVersion < 2 && options.wrapWithErrorBoundary) { |
166 | 161 | // @ts-ignore Setting more specific React Component typing for `R` generic above |
167 | 162 | // will break advanced type inference done by react router params |
168 | 163 | return withErrorBoundary(OrigApp, options.errorBoundaryOptions)(props); |
|
0 commit comments