Skip to content

fix(remix): Use require() to get react-router-dom in Express wrapper. #5796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/remix/src/utils/serverAdapters/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getCurrentHub } from '@sentry/hub';
import { flush } from '@sentry/node';
import { hasTracingEnabled } from '@sentry/tracing';
import { Transaction } from '@sentry/types';
import { extractRequestData, isString, loadModule, logger } from '@sentry/utils';
import { extractRequestData, isString, logger } from '@sentry/utils';
import { cwd } from 'process';

import {
createRoutes,
Expand All @@ -18,7 +19,6 @@ import {
ExpressRequest,
ExpressRequestHandler,
ExpressResponse,
ReactRouterDomPkg,
ServerBuild,
} from '../types';

Expand All @@ -27,7 +27,6 @@ function wrapExpressRequestHandler(
build: ServerBuild,
): ExpressRequestHandler {
const routes = createRoutes(build.routes);
const pkg = loadModule<ReactRouterDomPkg>('react-router-dom');

// If the core request handler is already wrapped, don't wrap Express handler which uses it.
if (isRequestHandlerWrapped) {
Expand All @@ -52,6 +51,8 @@ function wrapExpressRequestHandler(
}

const url = new URL(request.url);
const pkg = await import(`${cwd()}/node_modules/react-router-dom`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not do this package load on every request - or cache it somehow? How about putting it in line 30, where we did it previously?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried out require as a synchronous alternative to put it to line 30, and it also works. Would that make sense?
Also added a post edit route transaction ⬆️


const [name, source] = getTransactionName(routes, url, pkg);
const transaction = startRequestHandlerTransaction(hub, name, source, {
headers: {
Expand Down