-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
…saction normalization
There was a problem hiding this 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
packages/react/src/reactrouterv3.ts
Outdated
|
||
// Join all parts with '/', then replace multiple slashes with a single one. | ||
let fullPath = pathParts.join('/'); | ||
fullPath = fullPath.replace(/\/+/g, '/'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}`;
}, '');
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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]>
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.