Skip to content

fix(react): Handle nested parameterized routes in reactrouterv3 transaction normalization #16274

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
May 13, 2025

Conversation

sidx1024
Copy link
Contributor

We noticed that routes like /teams/:teamId/details were normalized to /teams:teamIddetails which is missing / and is incorrect.

This PR updates the tests for the React Router v3 integration to ensure correct transaction name normalization for nested parameterized routes.

Specifically, it modifies the normalizes transaction name test case to include navigation to a route like /teams/:teamId/details and verifies that the resulting transaction name is correctly normalized. This addresses an issue where similar nested route patterns might not be handled correctly.

@mydea mydea requested review from lforst, AbhiPrasad and RulaKhaled May 13, 2025 07:30
Copy link
Member

@RulaKhaled RulaKhaled left a comment

Choose a reason for hiding this comment

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

Look good to me. Thanks for contributing


// Join all parts with '/', then replace multiple slashes with a single one.
let fullPath = pathParts.join('/');
fullPath = fullPath.replace(/\/+/g, '/');
Copy link
Member

Choose a reason for hiding this comment

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

We should check if reduce is faster than the join + replace here.

it will also likely be more bundle size efficient, and we can account for the edge case.

Copy link
Member

Choose a reason for hiding this comment

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

thought about this more - I think this works. We can replace both const pathParts and the fullPath calculations.

return routesWithPaths.slice(index).reduce((acc, { path }) => {
  const pathSegment = acc === '/' || acc === '' ? path : `/${path}`;
  return `${acc}${pathSegment}`;
}, '');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reduce is 2.51% slower: https://jsbench.me/g2mamtp9bd/1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On my M1 Macbook it does 102K ops/s, I don't think it matters that much. Added a commit here: c1144e2

@sidx1024 sidx1024 requested a review from AbhiPrasad May 13, 2025 18:08
@sidx1024 sidx1024 changed the title test(react): Handle nested parameterized routes in reactrouterv3 transaction normalization fix(react): Handle nested parameterized routes in reactrouterv3 transaction normalization May 13, 2025
@AbhiPrasad AbhiPrasad merged commit f55018f into getsentry:develop May 13, 2025
140 checks passed
mydea pushed a commit that referenced this pull request May 14, 2025
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #16274

Co-authored-by: AbhiPrasad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants