feat(react): Add react-router-v6 integration.#5042
Conversation
size-limit report 📦
|
packages/react/src/reactrouterv6.tsx
Outdated
| instrumentationOptions.useLocation = useLocation; | ||
| instrumentationOptions.useNavigationType = useNavigationType; | ||
| instrumentationOptions.matchRoutes = matchRoutes; | ||
| instrumentationOptions.createRoutesFromChildren = createRoutesFromChildren; | ||
|
|
||
| instrumentationOptions.customStartTransaction = customStartTransaction; | ||
| instrumentationOptions.startTransactionOnLocationChange = startTransactionOnLocationChange; | ||
| instrumentationOptions.startTransactionOnPageLoad = startTransactionOnPageLoad; |
There was a problem hiding this comment.
Let's lift these up into individual variables instead of being under the instrumentationOptions object. This way we save on bundle size because otherwise object keys like customStartTransaction or startTransactionOnLocationChange cannot be minified.
| instrumentationOptions.useLocation = useLocation; | |
| instrumentationOptions.useNavigationType = useNavigationType; | |
| instrumentationOptions.matchRoutes = matchRoutes; | |
| instrumentationOptions.createRoutesFromChildren = createRoutesFromChildren; | |
| instrumentationOptions.customStartTransaction = customStartTransaction; | |
| instrumentationOptions.startTransactionOnLocationChange = startTransactionOnLocationChange; | |
| instrumentationOptions.startTransactionOnPageLoad = startTransactionOnPageLoad; | |
| useLocation = useLocation; | |
| useNavigationType = useNavigationType; | |
| matchRoutes = matchRoutes; | |
| createRoutesFromChildren = createRoutesFromChildren; | |
| customStartTransaction = customStartTransaction; | |
| startTransactionOnLocationChange = startTransactionOnLocationChange; | |
| startTransactionOnPageLoad = startTransactionOnPageLoad; |
AbhiPrasad
left a comment
There was a problem hiding this comment.
Looks good!
Can we add another test case around parameterized paths? Specifically with multi-parameter paths like orgs/:orgid/teams/:teamid
packages/react/src/reactrouterv6.tsx
Outdated
| 'routing.instrumentation': 'react-router-v6', | ||
| }; | ||
|
|
||
| export function withSentryV6<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R { |
There was a problem hiding this comment.
Let's call this withSentryReactRouterV6Routing. It's way longer, but it makes it very clear what is happening to users (+ will all get minified in the end anyway).
| startTransactionOnPageLoad = true, | ||
| startTransactionOnLocationChange = true, | ||
| ): void => { | ||
| _useEffect = useEffect; |
There was a problem hiding this comment.
Can we start the transaction here and just update the transaction name in the useeffect call?
Also, is there a way we can listen directly onto history instead of using useEffect?
There was a problem hiding this comment.
Updated to start pageload transaction on init 👍
Tried to find a simple solution to access history but it doesn't look possible without risking reliability (as they're encouraging to use useNavigate and useLocation hooks in v6, so even if we try to use global history, they may conflict?). Combining them with useEffect seems to be the most reliable, but can dig deeper if you like.
There was a problem hiding this comment.
Ok - no worries, let's keep using the hooks then!
packages/react/src/reactrouterv6.tsx
Outdated
| const transactionName = getTransactionName(routes, location, _matchRoutes); | ||
|
|
||
| activeTransaction = _customStartTransaction({ | ||
| name: transactionName, |
There was a problem hiding this comment.
| const transactionName = getTransactionName(routes, location, _matchRoutes); | |
| activeTransaction = _customStartTransaction({ | |
| name: transactionName, | |
| activeTransaction = _customStartTransaction({ | |
| name: getTransactionName(routes, location, _matchRoutes), |
packages/react/src/reactrouterv6.tsx
Outdated
| !_matchRoutes || | ||
| !_customStartTransaction | ||
| ) { | ||
| // Log warning? |
There was a problem hiding this comment.
yeah we should log something here
Co-authored-by: Abhijeet Prasad <[email protected]>
| @@ -0,0 +1,177 @@ | |||
| import { Transaction, TransactionContext } from '@sentry/types'; | |||
There was a problem hiding this comment.
Can we make sure we attribute to whom this implementation was inspired/based on?
|
We will also need a docs PR for this! |
Tracing integration for [`[email protected]`](https://reactrouter.com/docs/en/v6) This implementation will provide a HoC that wraps [`<Routes>`](https://reactrouter.com/docs/en/v6/api#routes-and-route) which replaced `<Switch>` from `[email protected]`.
|
Is there a way to use this integration with |
Tracing integration for
[email protected]This implementation will provide a HoC that wraps
<Routes>which replaced<Switch>from[email protected].This approach is similar to @wontondon's solution here.
Usage example:
Resolves: #4118