fix(react-router): Correct url attributes for history and relative navigations#22131
Merged
Conversation
Contributor
size-limit report 📦
|
…vigations The url.* attribute work surfaced incorrect destination URLs for navigate(-1), navigate(1), and relative navigate() targets. Update url.path/url.full after numeric navigation completes and match route parameterization against url.path for relative navigations. Co-Authored-By: Cursor <cursoragent@cursor.com>
73ea032 to
5cdb540
Compare
Move shared normalizePathname/getParameterizedRoute helpers to utils.ts and add finalizeNavigationSpanFromHydratedRouter so createClientInstrumentation does not need react-router types. Add tests for stale router state during sync numeric navigation. Co-Authored-By: Cursor <cursoragent@cursor.com>
chargome
approved these changes
Jul 10, 2026
| }; | ||
|
|
||
| if (result != null && typeof (result as Promise<unknown>).then === 'function') { | ||
| void (result as Promise<unknown>).then(finalizeNumericNavigation); |
Member
There was a problem hiding this comment.
m: Would also finalize the navigation in the error case here (which is just an edge case if the navigation rejects)? In either case I'd appreciate a comment at this part to better understand whats going on 🙏
Member
Author
There was a problem hiding this comment.
fixed. Also simplified the code and used isThenable instead of this ... check. Clankers gonna clank
|
|
||
| const GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & { | ||
| __reactRouterDataRouter?: { state: RouterState }; | ||
| }; |
Member
There was a problem hiding this comment.
l: The type differs from the one declared in hydratedRouter:
const GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
__reactRouterDataRouter?: DataRouter;
};
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.
Follow-up to the merged url.* attribute work (#22018): That PR set
url.template,url.path, andurl.fullon pageload/navigation spans, but exposed incorrect destination URLs fornavigate(-1)/navigate(1)and relativenavigate()targets. Similarly, independent of #22018, span names of relative navigations were also incorrect.This PR fixes destination URL updates and span anmes after numeric navigation (legacy + instrumentation API), route parameterization for relative navigations via
url.pathmatching, and adds E2E coverage for history back navigation.