question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[react-router-6] Nested Routers produce wrong parametrized URL

See original GitHub issue

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/react

SDK Version

7.16

Framework Version

React 18

Link to Sentry event

https://sentry.io/organizations/astraea/issues/3684294425/?project=5995515&query=is%3Aunresolved

Steps to Reproduce

I have quite a complex router so I recreated a small part of it here with repro steps in the readme: https://github.com/tirli/repro-sentry-react-router

I’m pretty sure several nested SentryRoutes are to blame here but I cannot rewrite my usage of the router 😦 Also, I’ve seen a lot of similar issues that are blaming the wrong order of sentry init and router usage so I checked this case and I feel like it’s not the problem here

Expected Result

http://localhost:5173/monitor/projects/:projectId/:siteId in error details

Actual Result

http://localhost:5173/monitor/projects/someProjectId/someSiteId

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
onurtemizkancommented, Nov 3, 2022

I agree, this would end up quite hacky even if we change our API. Haven’t tried, but 6.4 seems to make it fairly easier for us to instrument.

1reaction
onurtemizkancommented, Oct 26, 2022

Thanks for reporting this @tirli.

I was able to debug the reproduction, and indeed the problem seems to be the use of Descendant Routes.

I have tried two scenarios to figure out how we can support this pattern.


1 - When you only use SentryRoutes on the root, and unwrapped Routes in descendants.

In this scenario, createRoutesFromChildren (Remix utility that Sentry uses) only returns top level routes (which in your case are monitor/* and *). The child element props (thus the descendant routes) are inaccessible, as they are not rendered at the time we can access them.

In this case, we also lose pageload/navigation transactions of child routes, which IMO makes this approach unworthy to follow unless we find a way to access props inside Route elements.


2 - When you use SentryRoutes for every Routes instance in the app. (Your Case)

In this case, createRoutesFromChildren is called for every SentryRoutes instance, and each have their own slice of route. So we fail to match the parameters, as we don’t have the full route.

For example, in your project:

Root SentryRoute has: monitor/* First child SentryRoute has: project/ and so on.

We don’t have any info about the parent/child relationships of routes in the current structure, so it might not be easy to make multiple SentryRoutes instances work together and form the full path. We can try using useOutletContext, to define parent / child flags on the root SentryRoutes, but that will require an API change on our side.


We do not support most of the new features of React Router 6.4 yet (https://github.com/getsentry/sentry-javascript/issues/5872). Maybe we can come up with a better or simpler solution for descendant routes, while working on that.

cc: @AbhiPrasad

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Route not working on React Router v6 - Stack Overflow
Routes and routed components are rendering without issue here in this codesandbox. I suspect there's no issue with the routes and you've an ......
Read more >
Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >
React Router v6: Nested Routes - Denis listiadi - Medium
A solid understanding of how, when and why to create nested routes is ... React Router v6: Fundamental, URL Parameter, Query Strings, Customizing...
Read more >
React Router v6 Authentication with Protected Routes, Nested ...
Nearly every react application has a react - router to make routes. ... Protected Router, Nested Router, Active Link, Search Parameter, ...
Read more >
React Router v6 - Protected Routes, Nested ... - YouTube
Nearly every react application has a react - router to make routes. React Router allows you to make routers in the react application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found