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

feat(react): Add tracing support for React Router 6.4 createBrowserRouter. #6172

Merged
merged 5 commits into from Nov 22, 2022

Conversation

onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Nov 9, 2022

Resolves: #5872

Adds tracing support for React Router 6.4's createBrowserRouter (and seamlessly createMemoryRouter).

React Router 6.4 allows us to reach the router state itself, without having to use React hooks. So, the implementation is much simpler.

Example Spans:

  • Root pageload - Link
  • Parameterized pageload - Link
  • Parameterized navigation - Link
Implementation Details Discussed

This implementation works as is, but I have a few questions to the team, before moving forward:

  • We don't need to access useEffect and react-router functions anymore. It's still required by reactRouterV6Instrumentation, so we may have another instrumentation setup function like reactRouterV64Instrumentation, to avoid this. WDYT?

  • This doesn't fix the issue [react-router-6] Nested Routers produce wrong parametrized URL #5997. When I tried to replicate the issue combining createBrowserRouter, wildcard paths, and descendant routes defined in separate <Routes>, the matches object we're getting from the router is still path/*. It's not about our name parameterisation utility, as we are not getting info from the router. Besides that, I'm not sure if this pattern is recommended with the new API, but it still works in React Router 6.4.

  • This implementation doesn't support createHashRouter yet. It's not much different than createBrowserRouter, but we'll need another wrapper after all. Alternatively, we can try wrapping <RouterProvider>, which can end up with an easier single wrapper for all router types. Thinking about the previous issues about hydration, I'm not very keen to introduce another React component wrapper, but it's also possible. WDYT?

@trogers1
Copy link

Any thoughts on merging this? Further concerns? It's becoming an issue of concern about whether my project will continue to pay for Sentry without it.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 16, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.52 KB (added)
@sentry/browser - ES5 CDN Bundle (minified) 60.37 KB (added)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.17 KB (added)
@sentry/browser - ES6 CDN Bundle (minified) 53.72 KB (added)
@sentry/browser - Webpack (gzipped + minified) 19.91 KB (added)
@sentry/browser - Webpack (minified) 65.18 KB (added)
@sentry/react - Webpack (gzipped + minified) 19.94 KB (added)
@sentry/nextjs Client - Webpack (gzipped + minified) 45.93 KB (added)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.36 KB (added)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.77 KB (added)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

We don't need to access useEffect and react-router functions anymore. It's still required by reactRouterV6Instrumentation, so we may have another instrumentation setup function like reactRouterV64Instrumentation, to avoid this. WDYT

Introducing another function is just more cost (I'm thinking docs and support questions) - let's just stick with the existing function signature.

This doesn't fix the issue

That's fine, we can try digging into this separately.

Thinking about the previous issues about hydration, I'm not very keen to introduce another React component wrapper, but it's also possible

Maybe we ship the createBrowserRouter wrapper as a first step to unblock users, and then try to wrap RouterProvider as a next step.

"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-3": "npm:react-router@3.2.0",
"react-router-4": "npm:react-router@4.1.0",
"react-router-5": "npm:react-router@5.0.0",
"react-router-6": "npm:react-router@6.3.0",
"react-router-6": "npm:react-router@6.4.2",
Copy link
Member

Choose a reason for hiding this comment

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

let's add a new alias for 6.4?

@onurtemizkan onurtemizkan changed the title feat(react): Add tracing support for React Router 6.4 Data API. feat(react): Add tracing support for React Router 6.4 createBrowserRouter. Nov 21, 2022
@onurtemizkan onurtemizkan marked this pull request as ready for review November 21, 2022 12:27
@@ -13,9 +14,17 @@ import {
useNavigationType,
useRoutes,
} from 'react-router-6';
import { createMemoryRouter, Navigate as Navigate_6_4,RouterProvider } from 'react-router-6.4';
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 move this into a new test file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done 👍

@AbhiPrasad
Copy link
Member

Let's also make sure we get a docs PR ready for this @onurtemizkan!

@AbhiPrasad AbhiPrasad merged commit daacd38 into master Nov 22, 2022
@AbhiPrasad AbhiPrasad deleted the onur/support-react-router-6.4 branch November 22, 2022 16:29
@dante01yoon
Copy link

thank you for this patch up!

@dante01yoon
Copy link

dante01yoon commented Nov 22, 2022

do you have integration guide documentation with createBrowserRouter ?

-> you've updated already!
https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/

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.

Support BrowserTracing with React Router v6.4
4 participants