Skip to content

Commit be14cd9

Browse files
committed
Rename enhanceAgnosticRoutes -> mapRouteProperties
1 parent a65c398 commit be14cd9

File tree

8 files changed

+63
-56
lines changed

8 files changed

+63
-56
lines changed

packages/react-router-dom/__tests__/exports-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as ReactRouter from "react-router";
22
import * as ReactRouterDOM from "react-router-dom";
33

4-
let nonReExportedKeys = new Set(["UNSAFE_enhanceAgnosticRoute"]);
4+
let nonReExportedKeys = new Set(["UNSAFE_mapRouteProperties"]);
55

66
describe("react-router-dom", () => {
77
for (let key in ReactRouter) {

packages/react-router-dom/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
UNSAFE_DataRouterStateContext as DataRouterStateContext,
2424
UNSAFE_NavigationContext as NavigationContext,
2525
UNSAFE_RouteContext as RouteContext,
26-
UNSAFE_enhanceAgnosticRoute as enhanceAgnosticRoute,
26+
UNSAFE_mapRouteProperties as mapRouteProperties,
2727
} from "react-router";
2828
import type {
2929
BrowserHistory,
@@ -220,7 +220,7 @@ export function createBrowserRouter(
220220
history: createBrowserHistory({ window: opts?.window }),
221221
hydrationData: opts?.hydrationData || parseHydrationData(),
222222
routes,
223-
enhanceAgnosticRoute,
223+
mapRouteProperties,
224224
}).initialize();
225225
}
226226

@@ -234,7 +234,7 @@ export function createHashRouter(
234234
history: createHashHistory({ window: opts?.window }),
235235
hydrationData: opts?.hydrationData || parseHydrationData(),
236236
routes,
237-
enhanceAgnosticRoute,
237+
mapRouteProperties,
238238
}).initialize();
239239
}
240240

packages/react-router-dom/server.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
createStaticHandler as routerCreateStaticHandler,
1818
UNSAFE_convertRoutesToDataRoutes as convertRoutesToDataRoutes,
1919
} from "@remix-run/router";
20-
import { UNSAFE_enhanceAgnosticRoute as enhanceAgnosticRoute } from "react-router";
20+
import { UNSAFE_mapRouteProperties as mapRouteProperties } from "react-router";
2121
import type { Location, RouteObject, To } from "react-router-dom";
2222
import { Routes } from "react-router-dom";
2323
import {
@@ -209,7 +209,7 @@ function getStatelessNavigator() {
209209

210210
type CreateStaticHandlerOptions = Omit<
211211
RouterCreateStaticHandlerOptions,
212-
"detectErrorBoundary" | "enhanceAgnosticRoute"
212+
"detectErrorBoundary" | "mapRouteProperties"
213213
>;
214214

215215
export function createStaticHandler(
@@ -218,7 +218,7 @@ export function createStaticHandler(
218218
) {
219219
return routerCreateStaticHandler(routes, {
220220
...opts,
221-
enhanceAgnosticRoute,
221+
mapRouteProperties,
222222
});
223223
}
224224

@@ -229,7 +229,7 @@ export function createStaticRouter(
229229
let manifest: RouteManifest = {};
230230
let dataRoutes = convertRoutesToDataRoutes(
231231
routes,
232-
enhanceAgnosticRoute,
232+
mapRouteProperties,
233233
undefined,
234234
manifest
235235
);

packages/react-router-native/__tests__/exports-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as ReactRouter from "react-router";
22
import * as ReactRouterNative from "react-router-native";
33

4-
let nonReExportedKeys = new Set(["UNSAFE_enhanceAgnosticRoute"]);
4+
let nonReExportedKeys = new Set(["UNSAFE_mapRouteProperties"]);
55

66
describe("react-router-native", () => {
77
for (let key in ReactRouter) {

packages/react-router/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export {
208208
useRoutes,
209209
};
210210

211-
function enhanceAgnosticRoute(route: RouteObject) {
211+
function mapRouteProperties(route: RouteObject) {
212212
let updates: Partial<RouteObject> & { hasErrorBoundary: boolean } = {
213213
// Note: this check also occurs in createRoutesFromChildren so update
214214
// there if you change this -- please and thank you!
@@ -269,7 +269,7 @@ export function createMemoryRouter(
269269
}),
270270
hydrationData: opts?.hydrationData,
271271
routes,
272-
enhanceAgnosticRoute,
272+
mapRouteProperties,
273273
}).initialize();
274274
}
275275

@@ -293,5 +293,5 @@ export {
293293
RouteContext as UNSAFE_RouteContext,
294294
DataRouterContext as UNSAFE_DataRouterContext,
295295
DataRouterStateContext as UNSAFE_DataRouterStateContext,
296-
enhanceAgnosticRoute as UNSAFE_enhanceAgnosticRoute,
296+
mapRouteProperties as UNSAFE_mapRouteProperties,
297297
};

packages/router/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The `@remix-run/router` package is a framework-agnostic routing package (sometimes referred to as a browser-emulator) that serves as the heart of [React Router][react-router] and [Remix][remix] and provides all the core functionality for routing coupled with data loading and data mutations. It comes with built-in handling of errors, race-conditions, interruptions, cancellations, lazy-loading data, and much, much more.
44

5-
If you're using React Router, you should never `import` anything directly from the `@remix-run/router` or `react-router` packages, but you should have everything you need in either `react-router-dom` or `react-router-native`. Both of those packages re-export everything from `@remix-run/router` and `react-router`.
5+
If you're using React Router, you should never `import` anything directly from the `@remix-run/router` - you should have everything you need in `react-router-dom` (or `react-router`/`react-router-native` if you're not rendering in the browser). All of those packages should re-export everything you would otherwise need from `@remix-run/router`.
66

77
> **Warning**
88
>
@@ -16,11 +16,16 @@ A Router instance can be created using `createRouter`:
1616
// Create and initialize a router. "initialize" contains all side effects
1717
// including history listeners and kicking off the initial data fetch
1818
let router = createRouter({
19-
// Routes array
20-
routes: ,
21-
// History instance
22-
history,
23-
}).initialize()
19+
// Required properties
20+
routes, // Routes array
21+
history, // History instance
22+
23+
// Optional properties
24+
basename, // Base path
25+
mapRouteProperties, // Map function framework-agnostic routes to framework-aware routes
26+
future, // Future flags
27+
hydrationData, // Hydration data if using server-side-rendering
28+
}).initialize();
2429
```
2530

2631
Internally, the Router represents the state in an object of the following format, which is available through `router.state`. You can also register a subscriber of the signature `(state: RouterState) => void` to execute when the state updates via `router.subscribe()`;

packages/router/router.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import type {
3232
V7_FormMethod,
3333
HTMLFormMethod,
3434
MutationFormMethod,
35-
EnhanceAgnosticRouteFunction,
35+
MapRoutePropertiesFunction,
3636
} from "./utils";
3737
import {
3838
ErrorResponse,
@@ -345,10 +345,10 @@ export interface RouterInit {
345345
history: History;
346346
basename?: string;
347347
/**
348-
* @deprecated Use `enhanceAgnosticRoute` instead
348+
* @deprecated Use `mapRouteProperties` instead
349349
*/
350350
detectErrorBoundary?: DetectErrorBoundaryFunction;
351-
enhanceAgnosticRoute?: EnhanceAgnosticRouteFunction;
351+
mapRouteProperties?: MapRoutePropertiesFunction;
352352
future?: FutureConfig;
353353
hydrationData?: HydrationState;
354354
}
@@ -663,7 +663,7 @@ const isBrowser =
663663
typeof window.document.createElement !== "undefined";
664664
const isServer = !isBrowser;
665665

666-
const defaultEnhanceAgnosticRoute: EnhanceAgnosticRouteFunction = (route) => ({
666+
const defaultMapRouteProperties: MapRoutePropertiesFunction = (route) => ({
667667
hasErrorBoundary: Boolean(route.hasErrorBoundary),
668668
});
669669

@@ -682,24 +682,25 @@ export function createRouter(init: RouterInit): Router {
682682
"You must provide a non-empty routes array to createRouter"
683683
);
684684

685-
let enhanceAgnosticRoute: EnhanceAgnosticRouteFunction;
686-
if (init.enhanceAgnosticRoute) {
687-
enhanceAgnosticRoute = init.enhanceAgnosticRoute;
685+
let mapRouteProperties: MapRoutePropertiesFunction;
686+
if (init.mapRouteProperties) {
687+
mapRouteProperties = init.mapRouteProperties;
688688
} else if (init.detectErrorBoundary) {
689+
// If they are still using the deprecated version, wrap it with the new API
689690
let detectErrorBoundary = init.detectErrorBoundary;
690-
enhanceAgnosticRoute = (route) => ({
691+
mapRouteProperties = (route) => ({
691692
hasErrorBoundary: detectErrorBoundary(route),
692693
});
693694
} else {
694-
enhanceAgnosticRoute = defaultEnhanceAgnosticRoute;
695+
mapRouteProperties = defaultMapRouteProperties;
695696
}
696697

697698
// Routes keyed by ID
698699
let manifest: RouteManifest = {};
699700
// Routes in tree format for matching
700701
let dataRoutes = convertRoutesToDataRoutes(
701702
init.routes,
702-
enhanceAgnosticRoute,
703+
mapRouteProperties,
703704
undefined,
704705
manifest
705706
);
@@ -1343,7 +1344,7 @@ export function createRouter(init: RouterInit): Router {
13431344
actionMatch,
13441345
matches,
13451346
manifest,
1346-
enhanceAgnosticRoute,
1347+
mapRouteProperties,
13471348
router.basename
13481349
);
13491350

@@ -1701,7 +1702,7 @@ export function createRouter(init: RouterInit): Router {
17011702
match,
17021703
requestMatches,
17031704
manifest,
1704-
enhanceAgnosticRoute,
1705+
mapRouteProperties,
17051706
router.basename
17061707
);
17071708

@@ -1944,7 +1945,7 @@ export function createRouter(init: RouterInit): Router {
19441945
match,
19451946
matches,
19461947
manifest,
1947-
enhanceAgnosticRoute,
1948+
mapRouteProperties,
19481949
router.basename
19491950
);
19501951

@@ -2162,7 +2163,7 @@ export function createRouter(init: RouterInit): Router {
21622163
match,
21632164
matches,
21642165
manifest,
2165-
enhanceAgnosticRoute,
2166+
mapRouteProperties,
21662167
router.basename
21672168
)
21682169
),
@@ -2174,7 +2175,7 @@ export function createRouter(init: RouterInit): Router {
21742175
f.match,
21752176
f.matches,
21762177
manifest,
2177-
enhanceAgnosticRoute,
2178+
mapRouteProperties,
21782179
router.basename
21792180
);
21802181
} else {
@@ -2494,10 +2495,10 @@ export const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred");
24942495
export interface CreateStaticHandlerOptions {
24952496
basename?: string;
24962497
/**
2497-
* @deprecated Use `enhanceAgnosticRoute` instead
2498+
* @deprecated Use `mapRouteProperties` instead
24982499
*/
24992500
detectErrorBoundary?: DetectErrorBoundaryFunction;
2500-
enhanceAgnosticRoute?: EnhanceAgnosticRouteFunction;
2501+
mapRouteProperties?: MapRoutePropertiesFunction;
25012502
}
25022503

25032504
export function createStaticHandler(
@@ -2511,21 +2512,22 @@ export function createStaticHandler(
25112512

25122513
let manifest: RouteManifest = {};
25132514
let basename = (opts ? opts.basename : null) || "/";
2514-
let enhanceAgnosticRoute: EnhanceAgnosticRouteFunction;
2515-
if (opts?.enhanceAgnosticRoute) {
2516-
enhanceAgnosticRoute = opts.enhanceAgnosticRoute;
2515+
let mapRouteProperties: MapRoutePropertiesFunction;
2516+
if (opts?.mapRouteProperties) {
2517+
mapRouteProperties = opts.mapRouteProperties;
25172518
} else if (opts?.detectErrorBoundary) {
2519+
// If they are still using the deprecated version, wrap it with the new API
25182520
let detectErrorBoundary = opts.detectErrorBoundary;
2519-
enhanceAgnosticRoute = (route) => ({
2521+
mapRouteProperties = (route) => ({
25202522
hasErrorBoundary: detectErrorBoundary(route),
25212523
});
25222524
} else {
2523-
enhanceAgnosticRoute = defaultEnhanceAgnosticRoute;
2525+
mapRouteProperties = defaultMapRouteProperties;
25242526
}
25252527

25262528
let dataRoutes = convertRoutesToDataRoutes(
25272529
routes,
2528-
enhanceAgnosticRoute,
2530+
mapRouteProperties,
25292531
undefined,
25302532
manifest
25312533
);
@@ -2782,7 +2784,7 @@ export function createStaticHandler(
27822784
actionMatch,
27832785
matches,
27842786
manifest,
2785-
enhanceAgnosticRoute,
2787+
mapRouteProperties,
27862788
basename,
27872789
true,
27882790
isRouteRequest,
@@ -2950,7 +2952,7 @@ export function createStaticHandler(
29502952
match,
29512953
matches,
29522954
manifest,
2953-
enhanceAgnosticRoute,
2955+
mapRouteProperties,
29542956
basename,
29552957
true,
29562958
isRouteRequest,
@@ -3302,7 +3304,7 @@ function shouldRevalidateLoader(
33023304
*/
33033305
async function loadLazyRouteModule(
33043306
route: AgnosticDataRouteObject,
3305-
enhanceAgnosticRoute: EnhanceAgnosticRouteFunction,
3307+
mapRouteProperties: MapRoutePropertiesFunction,
33063308
manifest: RouteManifest
33073309
) {
33083310
if (!route.lazy) {
@@ -3357,18 +3359,18 @@ async function loadLazyRouteModule(
33573359
}
33583360

33593361
// Mutate the route with the provided updates. Do this first so we pass
3360-
// the updated version to enhanceAgnosticRoute
3362+
// the updated version to mapRouteProperties
33613363
Object.assign(routeToUpdate, routeUpdates);
33623364

33633365
// Mutate the `hasErrorBoundary` property on the route based on the route
33643366
// updates and remove the `lazy` function so we don't resolve the lazy
33653367
// route again.
33663368
Object.assign(routeToUpdate, {
33673369
// To keep things framework agnostic, we use the provided
3368-
// `enhanceAgnosticRoute` (or wrapped `detectErrorBoundary`) function to
3370+
// `mapRouteProperties` (or wrapped `detectErrorBoundary`) function to
33693371
// set the framework-aware properties (`element`/`hasErrorBoundary`) since
33703372
// the logic will differ between frameworks.
3371-
...enhanceAgnosticRoute(routeToUpdate),
3373+
...mapRouteProperties(routeToUpdate),
33723374
lazy: undefined,
33733375
});
33743376
}
@@ -3379,7 +3381,7 @@ async function callLoaderOrAction(
33793381
match: AgnosticDataRouteMatch,
33803382
matches: AgnosticDataRouteMatch[],
33813383
manifest: RouteManifest,
3382-
enhanceAgnosticRoute: EnhanceAgnosticRouteFunction,
3384+
mapRouteProperties: MapRoutePropertiesFunction,
33833385
basename = "/",
33843386
isStaticRequest: boolean = false,
33853387
isRouteRequest: boolean = false,
@@ -3409,12 +3411,12 @@ async function callLoaderOrAction(
34093411
// Run statically defined handler in parallel with lazy()
34103412
let values = await Promise.all([
34113413
runHandler(handler),
3412-
loadLazyRouteModule(match.route, enhanceAgnosticRoute, manifest),
3414+
loadLazyRouteModule(match.route, mapRouteProperties, manifest),
34133415
]);
34143416
result = values[0];
34153417
} else {
34163418
// Load lazy route module, then run any returned handler
3417-
await loadLazyRouteModule(match.route, enhanceAgnosticRoute, manifest);
3419+
await loadLazyRouteModule(match.route, mapRouteProperties, manifest);
34183420

34193421
handler = match.route[type];
34203422
if (handler) {

0 commit comments

Comments
 (0)