Skip to content

Commit 5a6545b

Browse files
authored
Rename patchRoutesOnMiss to patchRoutesOnNavigation (#11888)
1 parent bd4ac8e commit 5a6545b

File tree

10 files changed

+123
-101
lines changed

10 files changed

+123
-101
lines changed

.changeset/silver-coats-work.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"react-router-dom": patch
3+
"react-router": patch
4+
"@remix-run/router": patch
5+
---
6+
7+
Rename `unstable_patchRoutesOnMiss` to `unstable_patchRoutesOnNavigation` because it will now be called on the first navigation to paths matching splat/param routes in case there exists a higher-scoring route match not yet discovered

docs/routers/create-browser-router.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function createBrowserRouter(
5252
future?: FutureConfig;
5353
hydrationData?: HydrationState;
5454
unstable_dataStrategy?: unstable_DataStrategyFunction;
55-
unstable_patchRoutesOnMiss?: unstable_PatchRoutesOnMissFunction;
55+
unstable_patchRoutesOnNavigation?: unstable_PatchRoutesOnNavigationFunction;
5656
window?: Window;
5757
}
5858
): RemixRouter;
@@ -384,7 +384,7 @@ let router = createBrowserRouter(routes, {
384384
});
385385
```
386386

387-
## `opts.unstable_patchRoutesOnMiss`
387+
## `opts.unstable_patchRoutesOnNavigation`
388388

389389
<docs-warning>This API is marked "unstable" so it is subject to breaking API changes in minor releases</docs-warning>
390390

@@ -394,12 +394,12 @@ To combat this, we introduced [`route.lazy`][route-lazy] in [v6.9.0][6-9-0] whic
394394

395395
In some cases, even this doesn't go far enough. For very large applications, providing all route definitions up front can be prohibitively expensive. Additionally, it might not even be possible to provide all route definitions up front in certain Micro-Frontend or Module-Federation architectures.
396396

397-
This is where `unstable_patchRoutesOnMiss` comes in ([RFC][fog-of-war-rfc]). This API is for advanced use-cases where you are unable to provide the full route tree up-front and need a way to lazily "discover" portions of the route tree at runtime. This feature is often referred to as ["Fog of War"][fog-of-war] because similar to how video games expand the "world" as you move around - the router would be expanding its routing tree as the user navigated around the app - but would only ever end up loading portions of the tree that the user visited.
397+
This is where `unstable_patchRoutesOnNavigation` comes in ([RFC][fog-of-war-rfc]). This API is for advanced use-cases where you are unable to provide the full route tree up-front and need a way to lazily "discover" portions of the route tree at runtime. This feature is often referred to as ["Fog of War"][fog-of-war] because similar to how video games expand the "world" as you move around - the router would be expanding its routing tree as the user navigated around the app - but would only ever end up loading portions of the tree that the user visited.
398398

399399
### Type Declaration
400400

401401
```ts
402-
export interface unstable_PatchRoutesOnMissFunction {
402+
export interface unstable_PatchRoutesOnNavigationFunction {
403403
(opts: {
404404
path: string;
405405
matches: RouteMatch[];
@@ -413,7 +413,7 @@ export interface unstable_PatchRoutesOnMissFunction {
413413

414414
### Overview
415415

416-
`unstable_patchRoutesOnMiss` will be called anytime React Router is unable to match a `path`. The arguments include the `path`, any partial `matches`, and a `patch` function you can call to patch new routes into the tree at a specific location. This method is executed during the `loading` portion of the navigation for `GET` requests and during the `submitting` portion of the navigation for non-`GET` requests.
416+
`unstable_patchRoutesOnNavigation` will be called anytime React Router is unable to match a `path`. The arguments include the `path`, any partial `matches`, and a `patch` function you can call to patch new routes into the tree at a specific location. This method is executed during the `loading` portion of the navigation for `GET` requests and during the `submitting` portion of the navigation for non-`GET` requests.
417417

418418
**Patching children into an existing route**
419419

@@ -427,7 +427,10 @@ const router = createBrowserRouter(
427427
},
428428
],
429429
{
430-
async unstable_patchRoutesOnMiss({ path, patch }) {
430+
async unstable_patchRoutesOnNavigation({
431+
path,
432+
patch,
433+
}) {
431434
if (path === "/a") {
432435
// Load/patch the `a` route as a child of the route with id `root`
433436
let route = await getARoute();
@@ -439,7 +442,7 @@ const router = createBrowserRouter(
439442
);
440443
```
441444

442-
In the above example, if the user clicks a link to `/a`, React Router won't be able to match it initially and will call `patchRoutesOnMiss` with `/a` and a `matches` array containing the root route match. By calling `patch`, the `a` route will be added to the route tree and React Router will perform matching again. This time it will successfully match the `/a` path and the navigation will complete successfully.
445+
In the above example, if the user clicks a link to `/a`, React Router won't be able to match it initially and will call `patchRoutesOnNavigation` with `/a` and a `matches` array containing the root route match. By calling `patch`, the `a` route will be added to the route tree and React Router will perform matching again. This time it will successfully match the `/a` path and the navigation will complete successfully.
443446

444447
**Patching new root-level routes**
445448

@@ -455,7 +458,10 @@ const router = createBrowserRouter(
455458
},
456459
],
457460
{
458-
async unstable_patchRoutesOnMiss({ path, patch }) {
461+
async unstable_patchRoutesOnNavigation({
462+
path,
463+
patch,
464+
}) {
459465
if (path === "/root-sibling") {
460466
// Load/patch the `/root-sibling` route as a sibling of the root route
461467
let route = await getRootSiblingRoute();
@@ -480,7 +486,10 @@ let router = createBrowserRouter(
480486
},
481487
],
482488
{
483-
async unstable_patchRoutesOnMiss({ path, patch }) {
489+
async unstable_patchRoutesOnNavigation({
490+
path,
491+
patch,
492+
}) {
484493
if (path.startsWith("/dashboard")) {
485494
let children = await import("./dashboard");
486495
patch(null, children);
@@ -510,7 +519,7 @@ let router = createBrowserRouter(
510519
children: [
511520
{
512521
// If we want to include /dashboard in the critical routes, we need to
513-
// also include it's index route since patchRoutesOnMiss will not be
522+
// also include it's index route since patchRoutesOnNavigation will not be
514523
// called on a navigation to `/dashboard` because it will have successfully
515524
// matched the `/dashboard` parent route
516525
index: true,
@@ -535,7 +544,10 @@ let router = createBrowserRouter(
535544
},
536545
],
537546
{
538-
async unstable_patchRoutesOnMiss({ matches, patch }) {
547+
async unstable_patchRoutesOnNavigation({
548+
matches,
549+
patch,
550+
}) {
539551
let leafRoute = matches[matches.length - 1]?.route;
540552
if (leafRoute?.handle?.lazyChildren) {
541553
let children =

packages/react-router-dom/__tests__/partial-hydration-test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("v7_partialHydration", () => {
3131
testPartialHydration(createMemoryRouter, ReactRouter_RouterProvider);
3232

3333
// these tests only run for memory since we just need to set initialEntries
34-
it("supports partial hydration w/patchRoutesOnMiss (leaf fallback)", async () => {
34+
it("supports partial hydration w/patchRoutesOnNavigation (leaf fallback)", async () => {
3535
let parentDfd = createDeferred();
3636
let childDfd = createDeferred();
3737
let router = createMemoryRouter(
@@ -69,7 +69,7 @@ describe("v7_partialHydration", () => {
6969
future: {
7070
v7_partialHydration: true,
7171
},
72-
unstable_patchRoutesOnMiss({ path, patch }) {
72+
unstable_patchRoutesOnNavigation({ path, patch }) {
7373
if (path === "/parent/child") {
7474
patch("parent", [
7575
{
@@ -119,7 +119,7 @@ describe("v7_partialHydration", () => {
119119
`);
120120
});
121121

122-
it("supports partial hydration w/patchRoutesOnMiss (root fallback)", async () => {
122+
it("supports partial hydration w/patchRoutesOnNavigation (root fallback)", async () => {
123123
let parentDfd = createDeferred();
124124
let childDfd = createDeferred();
125125
let router = createMemoryRouter(
@@ -157,7 +157,7 @@ describe("v7_partialHydration", () => {
157157
future: {
158158
v7_partialHydration: true,
159159
},
160-
unstable_patchRoutesOnMiss({ path, patch }) {
160+
unstable_patchRoutesOnNavigation({ path, patch }) {
161161
if (path === "/parent/child") {
162162
patch("parent", [
163163
{

packages/react-router-dom/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
RouterProps,
1717
RouterProviderProps,
1818
To,
19-
unstable_PatchRoutesOnMissFunction,
19+
unstable_PatchRoutesOnNavigationFunction,
2020
} from "react-router";
2121
import {
2222
Router,
@@ -153,7 +153,7 @@ export type {
153153
To,
154154
UIMatch,
155155
unstable_HandlerResult,
156-
unstable_PatchRoutesOnMissFunction,
156+
unstable_PatchRoutesOnNavigationFunction,
157157
} from "react-router";
158158
export {
159159
AbortedDeferredError,
@@ -261,7 +261,7 @@ interface DOMRouterOpts {
261261
future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
262262
hydrationData?: HydrationState;
263263
unstable_dataStrategy?: unstable_DataStrategyFunction;
264-
unstable_patchRoutesOnMiss?: unstable_PatchRoutesOnMissFunction;
264+
unstable_patchRoutesOnNavigation?: unstable_PatchRoutesOnNavigationFunction;
265265
window?: Window;
266266
}
267267

@@ -280,7 +280,7 @@ export function createBrowserRouter(
280280
routes,
281281
mapRouteProperties,
282282
unstable_dataStrategy: opts?.unstable_dataStrategy,
283-
unstable_patchRoutesOnMiss: opts?.unstable_patchRoutesOnMiss,
283+
unstable_patchRoutesOnNavigation: opts?.unstable_patchRoutesOnNavigation,
284284
window: opts?.window,
285285
}).initialize();
286286
}
@@ -300,7 +300,7 @@ export function createHashRouter(
300300
routes,
301301
mapRouteProperties,
302302
unstable_dataStrategy: opts?.unstable_dataStrategy,
303-
unstable_patchRoutesOnMiss: opts?.unstable_patchRoutesOnMiss,
303+
unstable_patchRoutesOnNavigation: opts?.unstable_patchRoutesOnNavigation,
304304
window: opts?.window,
305305
}).initialize();
306306
}

packages/react-router/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import type {
3232
To,
3333
UIMatch,
3434
unstable_HandlerResult,
35-
unstable_AgnosticPatchRoutesOnMissFunction,
35+
unstable_AgnosticPatchRoutesOnNavigationFunction,
3636
} from "@remix-run/router";
3737
import {
3838
AbortedDeferredError,
@@ -291,8 +291,8 @@ function mapRouteProperties(route: RouteObject) {
291291
return updates;
292292
}
293293

294-
export interface unstable_PatchRoutesOnMissFunction
295-
extends unstable_AgnosticPatchRoutesOnMissFunction<RouteMatch> {}
294+
export interface unstable_PatchRoutesOnNavigationFunction
295+
extends unstable_AgnosticPatchRoutesOnNavigationFunction<RouteMatch> {}
296296

297297
export function createMemoryRouter(
298298
routes: RouteObject[],
@@ -303,7 +303,7 @@ export function createMemoryRouter(
303303
initialEntries?: InitialEntry[];
304304
initialIndex?: number;
305305
unstable_dataStrategy?: unstable_DataStrategyFunction;
306-
unstable_patchRoutesOnMiss?: unstable_PatchRoutesOnMissFunction;
306+
unstable_patchRoutesOnNavigation?: unstable_PatchRoutesOnNavigationFunction;
307307
}
308308
): RemixRouter {
309309
return createRouter({
@@ -320,7 +320,7 @@ export function createMemoryRouter(
320320
routes,
321321
mapRouteProperties,
322322
unstable_dataStrategy: opts?.unstable_dataStrategy,
323-
unstable_patchRoutesOnMiss: opts?.unstable_patchRoutesOnMiss,
323+
unstable_patchRoutesOnNavigation: opts?.unstable_patchRoutesOnNavigation,
324324
}).initialize();
325325
}
326326

packages/react-router/lib/hooks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ export function _renderMatches(
698698
dataRouterState.matches.length > 0
699699
) {
700700
// Don't bail if we're initializing with partial hydration and we have
701-
// router matches. That means we're actively running `patchRoutesOnMiss`
701+
// router matches. That means we're actively running `patchRoutesOnNavigation`
702702
// so we should render down the partial matches to the appropriate
703703
// `HydrateFallback`. We only do this if `parentMatches` is empty so it
704704
// only impacts the root matches for `RouterProvider` and no descendant

0 commit comments

Comments
 (0)