Repository navigation
fix(react): Parameterize React Router transactions with encoded params - #25639
Open
seongwon030 wants to merge 1 commit into
Open
seongwon030 wants to merge 1 commit into
seongwon030 wants to merge 1 commit into
Conversation
`location.pathname` is percent-encoded, but React Router decodes the pathname before matching, so `RouteMatch.pathname` and `pathnameBase` are decoded. The instrumentation compared the two with plain string equality, so a route like `/clubs/:clubId` visited as `/clubs/%ED%95%9C%EA%B8%80` never matched and the transaction fell back to the raw URL with source `url`. Decode both sides, segment by segment like React Router's `decodePath`, before comparing in `getNormalizedName` and before stripping `pathnameBase` for descendant routes.
seongwon030
requested review from
chargome and
s1gr1d
and removed request for
a team
October 22, 2026 03:18
s1gr1d
reviewed
Oct 23, 2026
s1gr1d
left a comment
Member
There was a problem hiding this comment.
Thanks, the looking into this and tests are great!
Instead of decoding, could we compare segment counts? Decoding never changes the number of / segments, so we don't need decodePathname. That also avoids two issues: /clubs/%2541 still doesn't match, because match.pathname gets decoded twice. And descendant routes now pass decoded paths back into matchRoutes, so /clubs/100%25 logs a "could not be decoded" warning.
Your tests already pass with the segment approach. Could you add those two URLs as cases too?
| * at all). Decoding both sides before comparing them keeps routes with an encoded parameter (non-ASCII, spaces, | ||
| * reserved characters) matchable regardless of which side is still encoded. | ||
| */ | ||
| export function decodePathname(pathname: string): string { |
Member
There was a problem hiding this comment.
Heads-up: react-router 6.22.1+ already decodes match.pathname, so this decodes it a second time. A literal %41 in a param then doesn't match.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #25638
pnpm run lint) & (pnpm run test).location.pathnameis percent-encoded, but React Router decodes the pathname before matching (decodePath), soRouteMatch.pathnameandpathnameBaseare decoded. The React Router instrumentation compared the two with plain string equality, so a route like/clubs/:clubIdvisited as/clubs/%ED%95%9C%EA%B8%80never matched and the transaction fell back to the raw URL with sourceurl. Every non-ASCII parameter value became its own transaction name. Descendant routes (<Routes>nested under a/*route) produced the raw URL with sourceroute.This adds
decodePathname, the same segment-wise algorithm as React Router'sdecodePath, and applies it to both sides of the comparison ingetNormalizedNameand of thepathnameBasestripping for descendant routes. Decoding both sides keeps percent-encoded basenames and older 6.x routers working: before 6.22.1matchRoutesmatched against the raw pathname or useddecodeURI, so there the branch pathname is the side that is still encoded. A value that still looks percent-encoded after one decode (a literal%41) is decoded once more; such values were not parameterized before either.Validation (in
packages/react):vitest runon the React Router suites (react-router,reactrouterv6,reactrouter-descendant-routes,reactrouter-cross-usage,reactrouter-compat-utils/*): 276 tests passed, including the new onesdecodePathname,getNormalizedName,rebuildRoutePathFromAllRoutes, v7 pageload/navigation and v6 descendant-route tests fail without the fixpnpm run lintclean;oxfmt --checkpassed on the changed files