fix(react): Remove routes from shared set on <Routes> unmount - #22792
Open
logaretm wants to merge 3 commits into
Open
fix(react): Remove routes from shared set on <Routes> unmount#22792logaretm wants to merge 3 commits into
<Routes> unmount#22792logaretm wants to merge 3 commits into
Conversation
…ent routers Adds two independent descendant <SentryRoutes> trees (foo/*, bar/*) and a cross-router client-side navigation. Because allRoutes is a shared module-level set, navigating into the second router picks up the first router's param name, producing the hybrid /bar/:fooId instead of /bar/:barId. This test currently fails, documenting issue #22782.
The module-level `allRoutes` set accumulated every route ever mounted and never removed any, so once two independent routers had each been mounted, `matchRoutes` ran over the union of both and could name a transaction with one router's static segment and another's param (e.g. `/bar/:fooId`). Removing a `<Routes>`'s routes when it unmounts keeps the set to what is currently mounted, so stale routes from an unrelated router can't be matched against a later navigation. Fixes #22782
logaretm
force-pushed
the
awad/js-3213-react-router-v6-integration-allroutes-accumulates-across
branch
from
July 29, 2026 12:47
8771f29 to
1e33054
Compare
The previous cleanup added routes only during the mount render pass but removed them on every unmount. Under StrictMode (mount, unmount, remount) the remount skipped the add, leaving the shared set missing routes and breaking descendant name reconstruction in cross-usage scenarios. Add and remove now share one effect lifecycle, so a StrictMode remount re-adds the routes it removed on the intermediate unmount.
logaretm
marked this pull request as ready for review
July 29, 2026 15:32
logaretm
requested review from
nicohrubec and
s1gr1d
and removed request for
a team
July 29, 2026 15:32
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.
Removes a
<Routes>'s routes from the module-levelallRoutesset when it unmounts, so they can't be matched against a later, unrelated navigation.The set accumulated every route ever mounted and never removed any. Once two independent routers had each been mounted,
matchRoutesran over the union of both, so a navigation into one could pick up a param name from the other and produce a hybrid transaction name like/bar/:fooIdinstead of/bar/:barId.I've taken out the route adding logic from the effect we had and added another one so that we can isolate the add/remove to the same effect to avoid relying on refs that can be fidgity in dev/prod and strict modes.
closes #22782
Will backport to v10