Skip to content

Remove matchRoutes optimization from render pass #13623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-emus-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

Partially revert optimization added in `6.29.0` to reduce calls to `matchRoutes` because it surfaced other issues
11 changes: 2 additions & 9 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from "react";
import type {
AgnosticRouteMatch,
Blocker,
BlockerFunction,
Location,
Expand Down Expand Up @@ -359,7 +358,7 @@ export function useRoutesImpl(
`useRoutes() may be used only in the context of a <Router> component.`
);

let { navigator, static: isStatic } = React.useContext(NavigationContext);
let { navigator } = React.useContext(NavigationContext);
let { matches: parentMatches } = React.useContext(RouteContext);
let routeMatch = parentMatches[parentMatches.length - 1];
let parentParams = routeMatch ? routeMatch.params : {};
Expand Down Expand Up @@ -446,13 +445,7 @@ export function useRoutesImpl(
remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
}

let matches =
!isStatic &&
dataRouterState &&
dataRouterState.matches &&
dataRouterState.matches.length > 0
? (dataRouterState.matches as AgnosticRouteMatch<string, RouteObject>[])
: matchRoutes(routes, { pathname: remainingPathname });
let matches = matchRoutes(routes, { pathname: remainingPathname });

if (__DEV__) {
warning(
Expand Down