fix(react): improve handling of routes nested under path="/" #14821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We noticed this in Sentry's
/issues/:groupId/
route, which uses SDK v8.43.0. The full route tree is complex, but the relevant parts are:If you navigate to e.g.
/issues/123
(no trailing slash), the recorded transaction name is//issues/:groupId/
(notice the double slash). This looks messy but doesn't have too much of a consequence.The worse issue is when you navigate to e.g.
/issues/123/
(with trailing slash), the transaction name is/issues/123/
- it is not parameterized. This breaks transaction grouping. On themaster
anddevelop
branch of the SDK, the transaction name is recorded as/
. This causes the transactions to be grouped incorrectly with the root, as well as any other routes nested under a route withpath="/"
.(Thanks @JoshFerge for noticing the bad data in Sentry! 🙌)
This commit fixes both of these issues and passes both the new tests (which reproduce the above issues) and all existing tests, but I don't trust my changes.
I effectively revert a change from #14304 where
became
This is the change that caused the difference in results between SDK versions. This will always match when
basename
is empty,branch.pathname
is/
, andlocation.pathname
ends with/
- in other words, if you have a parent route withpath="/"
, every request ending in a slash will match it instead of the more specific child route. (Depending on how often this kind ofRoute
nesting happens in the wild, this could be a wide regression in transaction names.) But, no tests failed from the removal ofendsWith
, which makes me worried that there's some necessary behaviour that isn't covered and would be broken by this fix. @onurtemizkan can you give some context into that change? Thanks!