Skip to content

Commit 3046093

Browse files
authored
Remove matchRoutes optimization from render pass (#13562)
1 parent a105445 commit 3046093

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

.changeset/flat-seas-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Partially revert optimization added in `7.1.4` to reduce calls to `matchRoutes` because it surfaced other issues

packages/react-router/lib/hooks.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import type {
3232
} from "./router/router";
3333
import { IDLE_BLOCKER } from "./router/router";
3434
import type {
35-
AgnosticRouteMatch,
3635
ParamParseKey,
3736
Params,
3837
PathMatch,
@@ -445,7 +444,7 @@ export function useRoutesImpl(
445444
`useRoutes() may be used only in the context of a <Router> component.`
446445
);
447446

448-
let { navigator, static: isStatic } = React.useContext(NavigationContext);
447+
let { navigator } = React.useContext(NavigationContext);
449448
let { matches: parentMatches } = React.useContext(RouteContext);
450449
let routeMatch = parentMatches[parentMatches.length - 1];
451450
let parentParams = routeMatch ? routeMatch.params : {};
@@ -532,17 +531,7 @@ export function useRoutesImpl(
532531
remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
533532
}
534533

535-
// Use data router matches when available to avoid another match routes call.
536-
// Skip this during SSR because the matches coming in from StaticHandlerContext
537-
// might be UI agnostic and we want the matches from the createStaticRouter's
538-
// routes
539-
let matches =
540-
!isStatic &&
541-
dataRouterState &&
542-
dataRouterState.matches &&
543-
dataRouterState.matches.length > 0
544-
? (dataRouterState.matches as AgnosticRouteMatch<string, RouteObject>[])
545-
: matchRoutes(routes, { pathname: remainingPathname });
534+
let matches = matchRoutes(routes, { pathname: remainingPathname });
546535

547536
if (ENABLE_DEV_WARNINGS) {
548537
warning(

0 commit comments

Comments
 (0)