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(integrations): Fix support for wildcard paths in react-router-dom v6 integration (#5997) #14076

Conversation

grahamhency
Copy link

This PR attempts to address the issue described in #5997 where wildcard paths (*) in the react-router-dom v6 integration were not being properly reported on for transactions.

To test:

  1. Pull this branch down
  2. Clone this repo and follow the setup & usage instructions in the README.

I also added a test for this change. I noticed that the existing tests had odd react router route declarations as far as nesting goes so I updated those tests to reflect how nested routes within react router should be structured.

Copy link
Collaborator

@onurtemizkan onurtemizkan left a comment

Choose a reason for hiding this comment

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

Thanks for this @grahamhency! Just had a first quick pass, and it seems this fixes the wildcard use in some cases. Though, it does not fix the use of Descendant Routes (#5997). We can try to address that separately.

@@ -250,7 +250,7 @@ describe('reactRouterV6BrowserTracingIntegration', () => {
<MemoryRouter initialEntries={['/']}>
<SentryRoutes>
<Route path="/about" element={<div>About</div>}>
<Route path="/about/us" element={<div>us</div>} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

We still need to cover this usage in tests to be sure we're not breaking anything. This is still a valid use. Could you please instead add a new test case as you update?

@@ -141,6 +141,14 @@ function stripBasenameFromPathname(pathname: string, basename: string): string {
return pathname.slice(startIndex) || '/';
}

function sendIndexPath(pathBuilder: string, pathname: string, basename: string): void | string[] {
const p1 = pathBuilder || stripBasenameFromPathname(pathname, basename);
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 a little hard to track. Could you please add some comments here?


expect(mockStartBrowserTracingNavigationSpan).toHaveBeenCalledTimes(1);
expect(mockStartBrowserTracingNavigationSpan).toHaveBeenLastCalledWith(expect.any(BrowserClient), {
name: '/projects/:projectId/views/:viewId',
Copy link
Collaborator

@onurtemizkan onurtemizkan Oct 25, 2024

Choose a reason for hiding this comment

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

Can we also add a test case where the wildcard exists in the transaction name (like: /param-page/*/details)? Something similar to the example app you provided.

AbhiPrasad pushed a commit that referenced this pull request Nov 11, 2024
Based on @grahamhency's work at
#14076.

Sets correct transaction names when wildcards are used in React Router 6
routes.

This does not fix the usage of the descendant routes
(#5997), which we
should try to address separately.
@AbhiPrasad
Copy link
Member

Closing this because we merged in #14205 - thanks for the PR @grahamhency!

@AbhiPrasad AbhiPrasad closed this Nov 11, 2024
@grahamhency
Copy link
Author

@AbhiPrasad ah, thank you! Sorry I couldn't see this PR through, my work work life got in the way hah. Glad I could help!

@AbhiPrasad
Copy link
Member

You got the ball rolling! That mattered.

I created a PR to give you acknowledgement in our changelog as well: #14228 - that will be published with the next release.

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