Skip to content
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

fix(remix): Paramaterize server side transactions #5491

Merged
merged 5 commits into from Aug 2, 2022

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jul 28, 2022

This makes sure server side transactions are parameterized correctly in Remix.

We do this by matching the server routes the same way Remix does under the hood, by reconciling the routes and URL pathname - https://github.com/remix-run/remix/blob/97999d02493e8114c39d48b76944069d58526e8d/packages/remix-server-runtime/server.ts#L36

Copied over a bunch of code from Remix to make this happen (and attributed accordingly).

Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

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

Changes seem sound to me! 👍

(I left some comments even though this is a draft but just so we don't forget)

matchRoutes: (routes: ServerRoute[], pathname: string) => RouteMatch<ServerRoute>[] | null;
}>('react-router-dom');
// https://github.com/remix-run/remix/blob/38e127b1d97485900b9c220d93503de0deb1fc81/packages/remix-server-runtime/routeMatching.ts#L12-L24
function matchServerRoutes(routes: ServerRoute[], pathname: string): RouteMatch<ServerRoute>[] | null {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be posssible to pull loadModule and matchServerRoutes out of the createRoutes closure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I can do this!

}

return matches.map(match => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Copy link
Member

Choose a reason for hiding this comment

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

I think these eslint disables are not necessary

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
pathname: match.pathname,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
route: match.route as unknown as ServerRoute,
Copy link
Member

Choose a reason for hiding this comment

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

Is this type cast needed? I think the correct type is already inferred.

@@ -318,7 +387,7 @@ function makeWrappedCreateRequestHandler(

const requestHandler = origCreateRequestHandler.call(this, { ...build, routes, entry: wrappedEntry }, mode);

return wrapRequestHandler(requestHandler);
return wrapRequestHandler(requestHandler, build);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is working, but just in case anything changes internally in @remix/server-runtime (like comparing the build or route objects or anything), could we use the same build object we provide to origCreateRequestHandler here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, will do

@AbhiPrasad AbhiPrasad self-assigned this Aug 2, 2022
@AbhiPrasad AbhiPrasad added this to the Sentry Remix SDK milestone Aug 2, 2022
@AbhiPrasad AbhiPrasad force-pushed the abhi-paramaterize-remix-server branch from 84c5570 to ea1c5e0 Compare August 2, 2022 17:57
@AbhiPrasad AbhiPrasad marked this pull request as ready for review August 2, 2022 17:57
@AbhiPrasad AbhiPrasad enabled auto-merge (squash) August 2, 2022 18:07
@AbhiPrasad AbhiPrasad merged commit 6f4ad56 into master Aug 2, 2022
@AbhiPrasad AbhiPrasad deleted the abhi-paramaterize-remix-server branch August 2, 2022 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants