@remix-run/router 1.9.0-pre.0 → 1.9.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/history.d.ts +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +32 -44
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +2 -9
- package/dist/router.js +24 -26
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +32 -44
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +16 -8
- package/history.ts +8 -5
- package/index.ts +2 -0
- package/package.json +1 -1
- package/router.ts +4 -27
- package/utils.ts +48 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
+
## 1.9.0-pre.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [REMOVE] Use long generic names ([#10845](https://github.com/remix-run/react-router/pull/10845))
|
|
8
|
+
|
|
9
|
+
## 1.9.0-pre.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- In order to move towards stricter TypeScript support in the future, we're aiming to replace current usages of `any` with `unknown` on exposed typings for user-provided data. To do this in Remix v2 without introducing breaking changes in React Router v6, we have added generics to a number of shared types. These continue to default to `any` in React Router and are overridden with `unknown` in Remix. In React Router v7 we plan to move these to `unknown` as a breakjing change. ([#10843](https://github.com/remix-run/react-router/pull/10843))
|
|
14
|
+
|
|
15
|
+
- `Location` now accepts a generic for the `location.state` value
|
|
16
|
+
- `ActionFunctionArgs`/`ActionFunction`/`LoaderFunctionArgs`/`LoaderFunction` now accept a generic for the `context` parameter (only used in SSR usages via `createStaticHandler`)
|
|
17
|
+
- The return type of `useMatches` (now exported as `UIMatch`) accepts generics for `match.data` and `match.handle` - both of which were already set to `unknown`
|
|
18
|
+
|
|
3
19
|
## 1.9.0-pre.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/dist/history.d.ts
CHANGED
|
@@ -43,11 +43,11 @@ export interface Path {
|
|
|
43
43
|
* An entry in a history stack. A location contains information about the
|
|
44
44
|
* URL path, as well as possibly some arbitrary state and a key.
|
|
45
45
|
*/
|
|
46
|
-
export interface Location extends Path {
|
|
46
|
+
export interface Location<State = any> extends Path {
|
|
47
47
|
/**
|
|
48
48
|
* A value of arbitrary data associated with this location.
|
|
49
49
|
*/
|
|
50
|
-
state:
|
|
50
|
+
state: State;
|
|
51
51
|
/**
|
|
52
52
|
* A unique string associated with this location. May be used to safely store
|
|
53
53
|
* and retrieve data in some other storage API, like `localStorage`.
|
|
@@ -81,8 +81,8 @@ export interface Listener {
|
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Describes a location that is the destination of some navigation, either via
|
|
84
|
-
* `history.push` or `history.replace`.
|
|
85
|
-
* URL path.
|
|
84
|
+
* `history.push` or `history.replace`. This may be either a URL or the pieces
|
|
85
|
+
* of a URL path.
|
|
86
86
|
*/
|
|
87
87
|
export type To = string | Partial<Path>;
|
|
88
88
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, V7_FormMethod, } from "./utils";
|
|
1
|
+
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
|
|
2
2
|
export { AbortedDeferredError, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
|
|
3
3
|
export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
|
|
4
4
|
export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
|
|
5
5
|
export * from "./router";
|
|
6
6
|
/** @internal */
|
|
7
7
|
export type { RouteManifest as UNSAFE_RouteManifest } from "./utils";
|
|
8
|
-
export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
|
|
8
|
+
export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
|
|
9
9
|
export { invariant as UNSAFE_invariant, warning as UNSAFE_warning, } from "./history";
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.9.0-pre.
|
|
2
|
+
* @remix-run/router v1.9.0-pre.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -45,25 +45,23 @@ let Action = /*#__PURE__*/function (Action) {
|
|
|
45
45
|
* The pathname, search, and hash values of a URL.
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
|
+
// TODO: (v7) Change the Location generic default from `any` to `unknown` and
|
|
49
|
+
// remove Remix `useLocation` wrapper.
|
|
48
50
|
/**
|
|
49
51
|
* An entry in a history stack. A location contains information about the
|
|
50
52
|
* URL path, as well as possibly some arbitrary state and a key.
|
|
51
53
|
*/
|
|
52
|
-
|
|
53
54
|
/**
|
|
54
55
|
* A change to the current location.
|
|
55
56
|
*/
|
|
56
|
-
|
|
57
57
|
/**
|
|
58
58
|
* A function that receives notifications about location changes.
|
|
59
59
|
*/
|
|
60
|
-
|
|
61
60
|
/**
|
|
62
61
|
* Describes a location that is the destination of some navigation, either via
|
|
63
|
-
* `history.push` or `history.replace`.
|
|
64
|
-
* URL path.
|
|
62
|
+
* `history.push` or `history.replace`. This may be either a URL or the pieces
|
|
63
|
+
* of a URL path.
|
|
65
64
|
*/
|
|
66
|
-
|
|
67
65
|
/**
|
|
68
66
|
* A history is an interface to the navigation stack. The history serves as the
|
|
69
67
|
* source of truth for the current location, as well as provides a set of
|
|
@@ -72,7 +70,6 @@ let Action = /*#__PURE__*/function (Action) {
|
|
|
72
70
|
* It is similar to the DOM's `window.history` object, but with a smaller, more
|
|
73
71
|
* focused API.
|
|
74
72
|
*/
|
|
75
|
-
|
|
76
73
|
const PopStateEventType = "popstate";
|
|
77
74
|
//#endregion
|
|
78
75
|
|
|
@@ -325,7 +322,7 @@ function warning(cond, message) {
|
|
|
325
322
|
try {
|
|
326
323
|
// Welcome to debugging history!
|
|
327
324
|
//
|
|
328
|
-
// This error is thrown as a convenience so you can more easily
|
|
325
|
+
// This error is thrown as a convenience, so you can more easily
|
|
329
326
|
// find the source for a warning that appears in the console by
|
|
330
327
|
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
331
328
|
throw new Error(message);
|
|
@@ -605,32 +602,29 @@ let ResultType = /*#__PURE__*/function (ResultType) {
|
|
|
605
602
|
* this as a private implementation detail in case they diverge in the future.
|
|
606
603
|
*/
|
|
607
604
|
|
|
605
|
+
// TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
|
|
606
|
+
// ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
|
|
607
|
+
// Also, make them a type alias instead of an interface
|
|
608
608
|
/**
|
|
609
609
|
* Arguments passed to loader functions
|
|
610
610
|
*/
|
|
611
|
-
|
|
612
611
|
/**
|
|
613
612
|
* Arguments passed to action functions
|
|
614
613
|
*/
|
|
615
|
-
|
|
616
614
|
/**
|
|
617
615
|
* Loaders and actions can return anything except `undefined` (`null` is a
|
|
618
616
|
* valid return value if there is no data to return). Responses are preferred
|
|
619
617
|
* and will ease any future migration to Remix
|
|
620
618
|
*/
|
|
621
|
-
|
|
622
619
|
/**
|
|
623
620
|
* Route loader function signature
|
|
624
621
|
*/
|
|
625
|
-
|
|
626
622
|
/**
|
|
627
623
|
* Route action function signature
|
|
628
624
|
*/
|
|
629
|
-
|
|
630
625
|
/**
|
|
631
626
|
* Arguments passed to shouldRevalidate function
|
|
632
627
|
*/
|
|
633
|
-
|
|
634
628
|
/**
|
|
635
629
|
* Route shouldRevalidate function signature. This runs after any submission
|
|
636
630
|
* (navigation or fetcher), so we flatten the navigation/fetcher submission
|
|
@@ -638,25 +632,21 @@ let ResultType = /*#__PURE__*/function (ResultType) {
|
|
|
638
632
|
* or a fetcher, what really matters is the URLs and the formData since loaders
|
|
639
633
|
* have to re-run based on the data models that were potentially mutated.
|
|
640
634
|
*/
|
|
641
|
-
|
|
642
635
|
/**
|
|
643
636
|
* Function provided by the framework-aware layers to set `hasErrorBoundary`
|
|
644
637
|
* from the framework-aware `errorElement` prop
|
|
645
638
|
*
|
|
646
639
|
* @deprecated Use `mapRouteProperties` instead
|
|
647
640
|
*/
|
|
648
|
-
|
|
649
641
|
/**
|
|
650
642
|
* Function provided by the framework-aware layers to set any framework-specific
|
|
651
643
|
* properties from framework-agnostic properties
|
|
652
644
|
*/
|
|
653
|
-
|
|
654
645
|
/**
|
|
655
646
|
* Keys we cannot change from within a lazy() function. We spread all other keys
|
|
656
647
|
* onto the route. Either they're meaningful to the router, or they'll get
|
|
657
648
|
* ignored.
|
|
658
649
|
*/
|
|
659
|
-
|
|
660
650
|
const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
|
|
661
651
|
|
|
662
652
|
/**
|
|
@@ -698,7 +688,7 @@ const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "inde
|
|
|
698
688
|
*/
|
|
699
689
|
|
|
700
690
|
// Attempt to parse the given string segment. If it fails, then just return the
|
|
701
|
-
// plain string type as a default fallback. Otherwise return the union of the
|
|
691
|
+
// plain string type as a default fallback. Otherwise, return the union of the
|
|
702
692
|
// parsed string literals that were referenced as dynamic segments in the route.
|
|
703
693
|
/**
|
|
704
694
|
* The parameters that were parsed from the URL path.
|
|
@@ -710,7 +700,7 @@ function isIndexRoute(route) {
|
|
|
710
700
|
return route.index === true;
|
|
711
701
|
}
|
|
712
702
|
|
|
713
|
-
// Walk the route tree generating unique IDs where necessary so we are working
|
|
703
|
+
// Walk the route tree generating unique IDs where necessary, so we are working
|
|
714
704
|
// solely with AgnosticDataRouteObject's within the Router
|
|
715
705
|
function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath, manifest) {
|
|
716
706
|
if (parentPath === void 0) {
|
|
@@ -773,6 +763,20 @@ function matchRoutes(routes, locationArg, basename) {
|
|
|
773
763
|
}
|
|
774
764
|
return matches;
|
|
775
765
|
}
|
|
766
|
+
function convertRouteMatchToUiMatch(match, loaderData) {
|
|
767
|
+
let {
|
|
768
|
+
route,
|
|
769
|
+
pathname,
|
|
770
|
+
params
|
|
771
|
+
} = match;
|
|
772
|
+
return {
|
|
773
|
+
id: route.id,
|
|
774
|
+
pathname,
|
|
775
|
+
params,
|
|
776
|
+
data: loaderData[route.id],
|
|
777
|
+
handle: route.handle
|
|
778
|
+
};
|
|
779
|
+
}
|
|
776
780
|
function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
777
781
|
if (branches === void 0) {
|
|
778
782
|
branches = [];
|
|
@@ -797,7 +801,7 @@ function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
|
797
801
|
let path = joinPaths([parentPath, meta.relativePath]);
|
|
798
802
|
let routesMeta = parentsMeta.concat(meta);
|
|
799
803
|
|
|
800
|
-
// Add the children before adding this route to the array so we traverse the
|
|
804
|
+
// Add the children before adding this route to the array, so we traverse the
|
|
801
805
|
// route tree depth-first and child routes appear before their parents in
|
|
802
806
|
// the "flattened" version.
|
|
803
807
|
if (route.children && route.children.length > 0) {
|
|
@@ -865,15 +869,15 @@ function explodeOptionalSegments(path) {
|
|
|
865
869
|
let result = [];
|
|
866
870
|
|
|
867
871
|
// All child paths with the prefix. Do this for all children before the
|
|
868
|
-
// optional version for all children so we get consistent ordering where the
|
|
872
|
+
// optional version for all children, so we get consistent ordering where the
|
|
869
873
|
// parent optional aspect is preferred as required. Otherwise, we can get
|
|
870
874
|
// child sections interspersed where deeper optional segments are higher than
|
|
871
|
-
// parent optional segments, where for example, /:two would
|
|
875
|
+
// parent optional segments, where for example, /:two would explode _earlier_
|
|
872
876
|
// then /:one. By always including the parent as required _for all children_
|
|
873
877
|
// first, we avoid this issue
|
|
874
878
|
result.push(...restExploded.map(subpath => subpath === "" ? required : [required, subpath].join("/")));
|
|
875
879
|
|
|
876
|
-
// Then if this is an optional value, add all child versions without
|
|
880
|
+
// Then, if this is an optional value, add all child versions without
|
|
877
881
|
if (isOptional) {
|
|
878
882
|
result.push(...restExploded);
|
|
879
883
|
}
|
|
@@ -1061,7 +1065,7 @@ function compilePath(path, caseSensitive, end) {
|
|
|
1061
1065
|
regexpSource += "\\/*$";
|
|
1062
1066
|
} else if (path !== "" && path !== "/") {
|
|
1063
1067
|
// If our path is non-empty and contains anything beyond an initial slash,
|
|
1064
|
-
// then we have _some_ form of path in our regex so we should expect to
|
|
1068
|
+
// then we have _some_ form of path in our regex, so we should expect to
|
|
1065
1069
|
// match only if we find the end of this path segment. Look for an optional
|
|
1066
1070
|
// non-captured trailing slash (to match a portion of the URL) or the end
|
|
1067
1071
|
// of the path (if we've matched to the end). We used to do this with a
|
|
@@ -2972,7 +2976,7 @@ function createRouter(init) {
|
|
|
2972
2976
|
}
|
|
2973
2977
|
function getScrollKey(location, matches) {
|
|
2974
2978
|
if (getScrollRestorationKey) {
|
|
2975
|
-
let key = getScrollRestorationKey(location, matches.map(m =>
|
|
2979
|
+
let key = getScrollRestorationKey(location, matches.map(m => convertRouteMatchToUiMatch(m, state.loaderData)));
|
|
2976
2980
|
return key || location.key;
|
|
2977
2981
|
}
|
|
2978
2982
|
return location.key;
|
|
@@ -4377,23 +4381,6 @@ async function resolveDeferredData(result, signal, unwrap) {
|
|
|
4377
4381
|
function hasNakedIndexQuery(search) {
|
|
4378
4382
|
return new URLSearchParams(search).getAll("index").some(v => v === "");
|
|
4379
4383
|
}
|
|
4380
|
-
|
|
4381
|
-
// Note: This should match the format exported by useMatches, so if you change
|
|
4382
|
-
// this please also change that :) Eventually we'll DRY this up
|
|
4383
|
-
function createUseMatchesMatch(match, loaderData) {
|
|
4384
|
-
let {
|
|
4385
|
-
route,
|
|
4386
|
-
pathname,
|
|
4387
|
-
params
|
|
4388
|
-
} = match;
|
|
4389
|
-
return {
|
|
4390
|
-
id: route.id,
|
|
4391
|
-
pathname,
|
|
4392
|
-
params,
|
|
4393
|
-
data: loaderData[route.id],
|
|
4394
|
-
handle: route.handle
|
|
4395
|
-
};
|
|
4396
|
-
}
|
|
4397
4384
|
function getTargetMatch(matches, location) {
|
|
4398
4385
|
let search = typeof location === "string" ? parsePath(location).search : location.search;
|
|
4399
4386
|
if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
|
|
@@ -4549,6 +4536,7 @@ exports.IDLE_NAVIGATION = IDLE_NAVIGATION;
|
|
|
4549
4536
|
exports.UNSAFE_DEFERRED_SYMBOL = UNSAFE_DEFERRED_SYMBOL;
|
|
4550
4537
|
exports.UNSAFE_DeferredData = DeferredData;
|
|
4551
4538
|
exports.UNSAFE_ErrorResponseImpl = ErrorResponseImpl;
|
|
4539
|
+
exports.UNSAFE_convertRouteMatchToUiMatch = convertRouteMatchToUiMatch;
|
|
4552
4540
|
exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
|
|
4553
4541
|
exports.UNSAFE_getPathContributingMatches = getPathContributingMatches;
|
|
4554
4542
|
exports.UNSAFE_invariant = invariant;
|