Skip to content

Commit 4989bd5

Browse files
committed
Add flag to client-side.
1 parent 27d4965 commit 4989bd5

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

packages/e2e-tests/test-applications/create-remix-app-v2/app/entry.client.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Sentry from '@sentry/remix';
1111

1212
Sentry.init({
1313
dsn: window.ENV.SENTRY_DSN,
14+
isRemixV2: true,
1415
integrations: [
1516
new Sentry.BrowserTracing({
1617
routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches),

packages/e2e-tests/test-applications/create-remix-app-v2/app/root.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,4 @@ function App() {
6060
);
6161
}
6262

63-
export default withSentry(App, {
64-
wrapWithErrorBoundary: false,
65-
});
63+
export default withSentry(App);

packages/e2e-tests/test-applications/create-remix-app-v2/remix.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,4 @@ module.exports = {
66
// serverBuildPath: 'build/index.js',
77
// publicPath: '/build/',
88
serverModuleFormat: 'cjs',
9-
future: {
10-
v2_dev: true,
11-
v2_headers: true,
12-
v2_errorBoundary: true,
13-
v2_meta: true,
14-
v2_normalizeFormMethod: true,
15-
v2_routeConvention: true,
16-
},
179
};

packages/remix/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"@types/express": "^4.17.14"
4343
},
4444
"peerDependencies": {
45-
"@remix-run/node": "1.x",
46-
"@remix-run/react": "1.x",
45+
"@remix-run/node": "1.x || 2.x",
46+
"@remix-run/react": "1.x || 2.x",
4747
"react": "16.x || 17.x || 18.x"
4848
},
4949
"scripts": {

packages/remix/src/client/performance.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { ErrorBoundaryProps } from '@sentry/react';
2-
import { WINDOW, withErrorBoundary } from '@sentry/react';
2+
import { getCurrentHub, WINDOW, withErrorBoundary } from '@sentry/react';
33
import type { Transaction, TransactionContext } from '@sentry/types';
44
import { isNodeEnv, logger } from '@sentry/utils';
55
import * as React from 'react';
66

77
import { getFutureFlagsBrowser } from '../utils/futureFlags';
8+
import type { RemixOptions } from '../utils/remixOptions';
89

910
const DEFAULT_TAGS = {
1011
'routing.instrumentation': 'remix-router',
@@ -40,6 +41,13 @@ let _useMatches: UseMatches;
4041
let _customStartTransaction: (context: TransactionContext) => Transaction | undefined;
4142
let _startTransactionOnLocationChange: boolean;
4243

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+
4351
function getInitPathName(): string | undefined {
4452
if (WINDOW && WINDOW.location) {
4553
return WINDOW.location.pathname;
@@ -97,7 +105,7 @@ export function withSentry<P extends Record<string, unknown>, R extends React.FC
97105
errorBoundaryOptions?: ErrorBoundaryProps;
98106
} = {
99107
// We don't want to wrap application with Sentry's ErrorBoundary by default for Remix v2
100-
wrapWithErrorBoundary: getFutureFlagsBrowser()?.v2_errorBoundary ? false : true,
108+
wrapWithErrorBoundary: true,
101109
errorBoundaryOptions: {},
102110
},
103111
): R {
@@ -159,7 +167,7 @@ export function withSentry<P extends Record<string, unknown>, R extends React.FC
159167
return <OrigApp {...props} />;
160168
};
161169

162-
if (options.wrapWithErrorBoundary) {
170+
if (!isRemixV2() && options.wrapWithErrorBoundary) {
163171
// @ts-ignore Setting more specific React Component typing for `R` generic above
164172
// will break advanced type inference done by react router params
165173
return withErrorBoundary(SentryRoot, options.errorBoundaryOptions);

0 commit comments

Comments
 (0)