Skip to content

Commit 25e4981

Browse files
authored
Stabilize unstable_patchRoutesOnNavigation (#11973)
1 parent d573eff commit 25e4981

File tree

8 files changed

+82
-75
lines changed

8 files changed

+82
-75
lines changed

.changeset/happy-grapes-fry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"react-router-dom": minor
3+
"react-router": minor
4+
"@remix-run/router": minor
5+
---
6+
7+
Stabilize `unstable_patchRoutesOnNavigation`

docs/routers/create-browser-router.md

Lines changed: 9 additions & 9 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_patchRoutesOnNavigation?: unstable_PatchRoutesOnNavigationFunction;
55+
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
5656
window?: Window;
5757
}
5858
): RemixRouter;
@@ -438,7 +438,7 @@ let router = createBrowserRouter(routes, {
438438
});
439439
```
440440

441-
## `opts.unstable_patchRoutesOnNavigation`
441+
## `opts.patchRoutesOnNavigation`
442442

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

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

449449
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.
450450

451-
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.
451+
This is where `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.
452452

453453
### Type Declaration
454454

455455
```ts
456-
export interface unstable_PatchRoutesOnNavigationFunction {
456+
export interface PatchRoutesOnNavigationFunction {
457457
(opts: {
458458
path: string;
459459
matches: RouteMatch[];
@@ -467,7 +467,7 @@ export interface unstable_PatchRoutesOnNavigationFunction {
467467

468468
### Overview
469469

470-
`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.
470+
`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.
471471

472472
**Patching children into an existing route**
473473

@@ -481,7 +481,7 @@ const router = createBrowserRouter(
481481
},
482482
],
483483
{
484-
async unstable_patchRoutesOnNavigation({
484+
async patchRoutesOnNavigation({
485485
path,
486486
patch,
487487
}) {
@@ -512,7 +512,7 @@ const router = createBrowserRouter(
512512
},
513513
],
514514
{
515-
async unstable_patchRoutesOnNavigation({
515+
async patchRoutesOnNavigation({
516516
path,
517517
patch,
518518
}) {
@@ -540,7 +540,7 @@ let router = createBrowserRouter(
540540
},
541541
],
542542
{
543-
async unstable_patchRoutesOnNavigation({
543+
async patchRoutesOnNavigation({
544544
path,
545545
patch,
546546
}) {
@@ -598,7 +598,7 @@ let router = createBrowserRouter(
598598
},
599599
],
600600
{
601-
async unstable_patchRoutesOnNavigation({
601+
async patchRoutesOnNavigation({
602602
matches,
603603
patch,
604604
}) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe("v7_partialHydration", () => {
6969
future: {
7070
v7_partialHydration: true,
7171
},
72-
unstable_patchRoutesOnNavigation({ path, patch }) {
72+
patchRoutesOnNavigation({ path, patch }) {
7373
if (path === "/parent/child") {
7474
patch("parent", [
7575
{
@@ -157,7 +157,7 @@ describe("v7_partialHydration", () => {
157157
future: {
158158
v7_partialHydration: true,
159159
},
160-
unstable_patchRoutesOnNavigation({ path, patch }) {
160+
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
@@ -17,7 +17,7 @@ import type {
1717
RouterProviderProps,
1818
To,
1919
unstable_DataStrategyFunction,
20-
unstable_PatchRoutesOnNavigationFunction,
20+
PatchRoutesOnNavigationFunction,
2121
} from "react-router";
2222
import {
2323
Router,
@@ -151,7 +151,7 @@ export type {
151151
ShouldRevalidateFunctionArgs,
152152
To,
153153
UIMatch,
154-
unstable_PatchRoutesOnNavigationFunction,
154+
PatchRoutesOnNavigationFunction,
155155
} from "react-router";
156156
export {
157157
AbortedDeferredError,
@@ -259,7 +259,7 @@ interface DOMRouterOpts {
259259
future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
260260
hydrationData?: HydrationState;
261261
unstable_dataStrategy?: unstable_DataStrategyFunction;
262-
unstable_patchRoutesOnNavigation?: unstable_PatchRoutesOnNavigationFunction;
262+
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
263263
window?: Window;
264264
}
265265

@@ -278,7 +278,7 @@ export function createBrowserRouter(
278278
routes,
279279
mapRouteProperties,
280280
unstable_dataStrategy: opts?.unstable_dataStrategy,
281-
unstable_patchRoutesOnNavigation: opts?.unstable_patchRoutesOnNavigation,
281+
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
282282
window: opts?.window,
283283
}).initialize();
284284
}
@@ -298,7 +298,7 @@ export function createHashRouter(
298298
routes,
299299
mapRouteProperties,
300300
unstable_dataStrategy: opts?.unstable_dataStrategy,
301-
unstable_patchRoutesOnNavigation: opts?.unstable_patchRoutesOnNavigation,
301+
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
302302
window: opts?.window,
303303
}).initialize();
304304
}

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
ShouldRevalidateFunctionArgs,
3333
To,
3434
UIMatch,
35-
unstable_AgnosticPatchRoutesOnNavigationFunction,
35+
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_PatchRoutesOnNavigationFunction
295-
extends unstable_AgnosticPatchRoutesOnNavigationFunction<RouteMatch> {}
294+
export interface PatchRoutesOnNavigationFunction
295+
extends 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_patchRoutesOnNavigation?: unstable_PatchRoutesOnNavigationFunction;
306+
patchRoutesOnNavigation?: 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_patchRoutesOnNavigation: opts?.unstable_patchRoutesOnNavigation,
323+
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
324324
}).initialize();
325325
}
326326

0 commit comments

Comments
 (0)