@remix-run/router 1.0.4-pre.1 → 1.0.5-pre.0
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 +10 -9
- package/dist/history.d.ts +6 -1
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +50 -35
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +46 -35
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +50 -35
- 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 +4 -9
- package/history.ts +23 -3
- package/index.ts +1 -2
- package/package.json +1 -1
- package/router.ts +35 -17
- package/utils.ts +5 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
-
## 1.0.
|
|
3
|
+
## 1.0.5-pre.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Fix URL creation in Cloudflare Pages or other non-browser-environment ([#9682](https://github.com/remix-run/react-router/pull/9682))
|
|
8
|
+
- Fix requests sent to revalidating loaders so they reflect a GET request ([#9680](https://github.com/remix-run/react-router/pull/9680))
|
|
8
9
|
|
|
9
|
-
## 1.0.4
|
|
10
|
+
## 1.0.4
|
|
10
11
|
|
|
11
12
|
### Patch Changes
|
|
12
13
|
|
|
13
|
-
-
|
|
14
|
+
- Throw an error if an `action`/`loader` function returns `undefined` as revalidations need to know whether the loader has previously been executed. `undefined` also causes issues during SSR stringification for hydration. You should always ensure you `loader`/`action` returns a value, and you may return `null` if you don't wish to return anything. ([#9511](https://github.com/remix-run/react-router/pull/9511))
|
|
15
|
+
- Properly handle redirects to external domains ([#9590](https://github.com/remix-run/react-router/pull/9590), [#9654](https://github.com/remix-run/react-router/pull/9654))
|
|
14
16
|
- Preserve the HTTP method on 307/308 redirects ([#9597](https://github.com/remix-run/react-router/pull/9597))
|
|
15
17
|
- Support `basename` in static data routers ([#9591](https://github.com/remix-run/react-router/pull/9591))
|
|
16
|
-
-
|
|
17
|
-
- Enhanced `ErrorResponse` bodies to contain more descriptive text in internal 403/404/405 scenarios ([#9511](https://github.com/remix-run/react-router/pull/9511))
|
|
18
|
+
- Enhanced `ErrorResponse` bodies to contain more descriptive text in internal 403/404/405 scenarios
|
|
18
19
|
|
|
19
20
|
## 1.0.3
|
|
20
21
|
|
|
@@ -52,7 +53,7 @@ For an overview of the features provided by `react-router`, we recommend you go
|
|
|
52
53
|
|
|
53
54
|
For an overview of the features provided by `@remix-run/router`, please check out the [`README`][remix-router-readme].
|
|
54
55
|
|
|
55
|
-
[rr-docs]: https://reactrouter.com
|
|
56
|
-
[rr-feature-overview]: https://reactrouter.com/
|
|
57
|
-
[rr-tutorial]: https://reactrouter.com/
|
|
56
|
+
[rr-docs]: https://reactrouter.com
|
|
57
|
+
[rr-feature-overview]: https://reactrouter.com/start/overview
|
|
58
|
+
[rr-tutorial]: https://reactrouter.com/start/tutorial
|
|
58
59
|
[remix-router-readme]: https://github.com/remix-run/react-router/blob/main/packages/router/README.md
|
package/dist/history.d.ts
CHANGED
|
@@ -214,6 +214,11 @@ export declare type HashHistoryOptions = UrlHistoryOptions;
|
|
|
214
214
|
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
215
215
|
*/
|
|
216
216
|
export declare function createHashHistory(options?: HashHistoryOptions): HashHistory;
|
|
217
|
+
/**
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
export declare function invariant(value: boolean, message?: string): asserts value;
|
|
221
|
+
export declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
|
|
217
222
|
/**
|
|
218
223
|
* Creates a Location object with a unique key from the given Path
|
|
219
224
|
*/
|
|
@@ -226,7 +231,7 @@ export declare function createPath({ pathname, search, hash, }: Partial<Path>):
|
|
|
226
231
|
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
227
232
|
*/
|
|
228
233
|
export declare function parsePath(path: string): Partial<Path>;
|
|
229
|
-
export declare function
|
|
234
|
+
export declare function createClientSideURL(location: Location | string): URL;
|
|
230
235
|
export interface UrlHistory extends History {
|
|
231
236
|
}
|
|
232
237
|
export declare type UrlHistoryOptions = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { convertRoutesToDataRoutes, getPathContributingMatches } from "./utils";
|
|
2
2
|
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils";
|
|
3
|
-
export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname,
|
|
3
|
+
export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils";
|
|
4
4
|
export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
|
|
5
|
-
export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, parsePath, } from "./history";
|
|
5
|
+
export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, invariant, parsePath, } from "./history";
|
|
6
6
|
export * from "./router";
|
|
7
7
|
/** @internal */
|
|
8
8
|
export { convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, };
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.0.
|
|
2
|
+
* @remix-run/router v1.0.5-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -281,6 +281,16 @@ function createHashHistory(options) {
|
|
|
281
281
|
//#region UTILS
|
|
282
282
|
////////////////////////////////////////////////////////////////////////////////
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* @private
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
function invariant(value, message) {
|
|
289
|
+
if (value === false || value === null || typeof value === "undefined") {
|
|
290
|
+
throw new Error(message);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
284
294
|
function warning$1(cond, message) {
|
|
285
295
|
if (!cond) {
|
|
286
296
|
// eslint-disable-next-line no-console
|
|
@@ -379,12 +389,13 @@ function parsePath(path) {
|
|
|
379
389
|
|
|
380
390
|
return parsedPath;
|
|
381
391
|
}
|
|
382
|
-
function
|
|
392
|
+
function createClientSideURL(location) {
|
|
383
393
|
// window.location.origin is "null" (the literal string value) in Firefox
|
|
384
394
|
// under certain conditions, notably when serving from a local HTML file
|
|
385
395
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=878297
|
|
386
|
-
let base = typeof window !== "undefined" && typeof window.location !== "undefined" && window.location.origin !== "null" ? window.location.origin :
|
|
396
|
+
let base = typeof window !== "undefined" && typeof window.location !== "undefined" && window.location.origin !== "null" ? window.location.origin : window.location.href;
|
|
387
397
|
let href = typeof location === "string" ? location : createPath(location);
|
|
398
|
+
invariant(base, "No window.location.(origin|href) available to create URL for href: " + href);
|
|
388
399
|
return new URL(href, base);
|
|
389
400
|
}
|
|
390
401
|
|
|
@@ -479,7 +490,7 @@ function getUrlBasedHistory(getLocation, createHref, validateLocation, options)
|
|
|
479
490
|
|
|
480
491
|
encodeLocation(to) {
|
|
481
492
|
// Encode a Location the same way window.location would
|
|
482
|
-
let url =
|
|
493
|
+
let url = createClientSideURL(typeof to === "string" ? to : createPath(to));
|
|
483
494
|
return {
|
|
484
495
|
pathname: url.pathname,
|
|
485
496
|
search: url.search,
|
|
@@ -555,7 +566,7 @@ function convertRoutesToDataRoutes(routes, parentPath, allIds) {
|
|
|
555
566
|
/**
|
|
556
567
|
* Matches the given routes to a location and returns the match data.
|
|
557
568
|
*
|
|
558
|
-
* @see https://reactrouter.com/
|
|
569
|
+
* @see https://reactrouter.com/utils/match-routes
|
|
559
570
|
*/
|
|
560
571
|
|
|
561
572
|
function matchRoutes(routes, locationArg, basename) {
|
|
@@ -718,7 +729,7 @@ function matchRouteBranch(branch, pathname) {
|
|
|
718
729
|
/**
|
|
719
730
|
* Returns a path with params interpolated.
|
|
720
731
|
*
|
|
721
|
-
* @see https://reactrouter.com/
|
|
732
|
+
* @see https://reactrouter.com/utils/generate-path
|
|
722
733
|
*/
|
|
723
734
|
|
|
724
735
|
|
|
@@ -751,7 +762,7 @@ function generatePath(path, params) {
|
|
|
751
762
|
* Performs pattern matching on a URL pathname and returns information about
|
|
752
763
|
* the match.
|
|
753
764
|
*
|
|
754
|
-
* @see https://reactrouter.com/
|
|
765
|
+
* @see https://reactrouter.com/utils/match-path
|
|
755
766
|
*/
|
|
756
767
|
function matchPath(pattern, pathname) {
|
|
757
768
|
if (typeof pattern === "string") {
|
|
@@ -873,15 +884,6 @@ function stripBasename(pathname, basename) {
|
|
|
873
884
|
* @private
|
|
874
885
|
*/
|
|
875
886
|
|
|
876
|
-
function invariant(value, message) {
|
|
877
|
-
if (value === false || value === null || typeof value === "undefined") {
|
|
878
|
-
throw new Error(message);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* @private
|
|
883
|
-
*/
|
|
884
|
-
|
|
885
887
|
function warning(cond, message) {
|
|
886
888
|
if (!cond) {
|
|
887
889
|
// eslint-disable-next-line no-console
|
|
@@ -900,7 +902,7 @@ function warning(cond, message) {
|
|
|
900
902
|
/**
|
|
901
903
|
* Returns a resolved path object relative to the given pathname.
|
|
902
904
|
*
|
|
903
|
-
* @see https://reactrouter.com/
|
|
905
|
+
* @see https://reactrouter.com/utils/resolve-path
|
|
904
906
|
*/
|
|
905
907
|
|
|
906
908
|
function resolvePath(to, fromPathname) {
|
|
@@ -1624,7 +1626,7 @@ function createRouter(init) {
|
|
|
1624
1626
|
|
|
1625
1627
|
|
|
1626
1628
|
pendingNavigationController = new AbortController();
|
|
1627
|
-
let request =
|
|
1629
|
+
let request = createClientSideRequest(location, pendingNavigationController.signal, opts && opts.submission);
|
|
1628
1630
|
let pendingActionData;
|
|
1629
1631
|
let pendingError;
|
|
1630
1632
|
|
|
@@ -1654,7 +1656,11 @@ function createRouter(init) {
|
|
|
1654
1656
|
location
|
|
1655
1657
|
}, opts.submission);
|
|
1656
1658
|
|
|
1657
|
-
loadingNavigation = navigation;
|
|
1659
|
+
loadingNavigation = navigation; // Create a GET request for the loaders
|
|
1660
|
+
|
|
1661
|
+
request = new Request(request.url, {
|
|
1662
|
+
signal: request.signal
|
|
1663
|
+
});
|
|
1658
1664
|
} // Call loaders
|
|
1659
1665
|
|
|
1660
1666
|
|
|
@@ -1943,7 +1949,7 @@ function createRouter(init) {
|
|
|
1943
1949
|
}); // Call the action for the fetcher
|
|
1944
1950
|
|
|
1945
1951
|
let abortController = new AbortController();
|
|
1946
|
-
let fetchRequest =
|
|
1952
|
+
let fetchRequest = createClientSideRequest(path, abortController.signal, submission);
|
|
1947
1953
|
fetchControllers.set(key, abortController);
|
|
1948
1954
|
let actionResult = await callLoaderOrAction("action", fetchRequest, match, requestMatches, router.basename);
|
|
1949
1955
|
|
|
@@ -1987,7 +1993,7 @@ function createRouter(init) {
|
|
|
1987
1993
|
|
|
1988
1994
|
|
|
1989
1995
|
let nextLocation = state.navigation.location || state.location;
|
|
1990
|
-
let revalidationRequest =
|
|
1996
|
+
let revalidationRequest = createClientSideRequest(nextLocation, abortController.signal);
|
|
1991
1997
|
let matches = state.navigation.state !== "idle" ? matchRoutes(dataRoutes, state.navigation.location, init.basename) : state.matches;
|
|
1992
1998
|
invariant(matches, "Didn't find any matches after fetcher action");
|
|
1993
1999
|
let loadId = ++incrementingLoadId;
|
|
@@ -2107,7 +2113,7 @@ function createRouter(init) {
|
|
|
2107
2113
|
}); // Call the loader for this fetcher route match
|
|
2108
2114
|
|
|
2109
2115
|
let abortController = new AbortController();
|
|
2110
|
-
let fetchRequest =
|
|
2116
|
+
let fetchRequest = createClientSideRequest(path, abortController.signal);
|
|
2111
2117
|
fetchControllers.set(key, abortController);
|
|
2112
2118
|
let result = await callLoaderOrAction("loader", fetchRequest, match, matches, router.basename); // Deferred isn't supported or fetcher loads, await everything and treat it
|
|
2113
2119
|
// as a normal load. resolveDeferredData will return undefined if this
|
|
@@ -2248,7 +2254,7 @@ function createRouter(init) {
|
|
|
2248
2254
|
// accordingly
|
|
2249
2255
|
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, router.basename)), ...fetchersToLoad.map(_ref8 => {
|
|
2250
2256
|
let [, href, match, fetchMatches] = _ref8;
|
|
2251
|
-
return callLoaderOrAction("loader",
|
|
2257
|
+
return callLoaderOrAction("loader", createClientSideRequest(href, request.signal), match, fetchMatches, router.basename);
|
|
2252
2258
|
})]);
|
|
2253
2259
|
let loaderResults = results.slice(0, matchesToLoad.length);
|
|
2254
2260
|
let fetcherResults = results.slice(matchesToLoad.length);
|
|
@@ -2659,7 +2665,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2659
2665
|
if (!actionMatch.route.action) {
|
|
2660
2666
|
let error = getInternalRouterError(405, {
|
|
2661
2667
|
method: request.method,
|
|
2662
|
-
pathname:
|
|
2668
|
+
pathname: new URL(request.url).pathname,
|
|
2663
2669
|
routeId: actionMatch.route.id
|
|
2664
2670
|
});
|
|
2665
2671
|
|
|
@@ -2734,9 +2740,13 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2734
2740
|
[actionMatch.route.id]: result.headers
|
|
2735
2741
|
} : {})
|
|
2736
2742
|
});
|
|
2737
|
-
}
|
|
2743
|
+
} // Create a GET request for the loaders
|
|
2744
|
+
|
|
2738
2745
|
|
|
2739
|
-
let
|
|
2746
|
+
let loaderRequest = new Request(request.url, {
|
|
2747
|
+
signal: request.signal
|
|
2748
|
+
});
|
|
2749
|
+
let context = await loadRouteData(loaderRequest, matches);
|
|
2740
2750
|
return _extends({}, context, result.statusCode ? {
|
|
2741
2751
|
statusCode: result.statusCode
|
|
2742
2752
|
} : {}, {
|
|
@@ -2755,7 +2765,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2755
2765
|
if (isRouteRequest && !(routeMatch != null && routeMatch.route.loader)) {
|
|
2756
2766
|
throw getInternalRouterError(400, {
|
|
2757
2767
|
method: request.method,
|
|
2758
|
-
pathname:
|
|
2768
|
+
pathname: new URL(request.url).pathname,
|
|
2759
2769
|
routeId: routeMatch == null ? void 0 : routeMatch.route.id
|
|
2760
2770
|
});
|
|
2761
2771
|
}
|
|
@@ -2949,9 +2959,9 @@ function isNewRouteInstance(currentMatch, match) {
|
|
|
2949
2959
|
}
|
|
2950
2960
|
|
|
2951
2961
|
function shouldRevalidateLoader(currentLocation, currentMatch, submission, location, match, isRevalidationRequired, actionResult) {
|
|
2952
|
-
let currentUrl =
|
|
2962
|
+
let currentUrl = createClientSideURL(currentLocation);
|
|
2953
2963
|
let currentParams = currentMatch.params;
|
|
2954
|
-
let nextUrl =
|
|
2964
|
+
let nextUrl = createClientSideURL(location);
|
|
2955
2965
|
let nextParams = match.params; // This is the default implementation as to when we revalidate. If the route
|
|
2956
2966
|
// provides it's own implementation, then we give them full control but
|
|
2957
2967
|
// provide this value so they can leverage it if needed after they check
|
|
@@ -3028,13 +3038,15 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3028
3038
|
let location = result.headers.get("Location");
|
|
3029
3039
|
invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header"); // Check if this an external redirect that goes to a new origin
|
|
3030
3040
|
|
|
3031
|
-
let
|
|
3041
|
+
let currentUrl = new URL(request.url);
|
|
3042
|
+
let currentOrigin = currentUrl.origin;
|
|
3043
|
+
let newOrigin = new URL(location, currentOrigin).origin;
|
|
3044
|
+
let external = newOrigin !== currentOrigin; // Support relative routing in internal redirects
|
|
3032
3045
|
|
|
3033
3046
|
if (!external) {
|
|
3034
3047
|
let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
|
|
3035
3048
|
let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
|
|
3036
|
-
let
|
|
3037
|
-
let resolvedLocation = resolveTo(location, routePathnames, requestPath);
|
|
3049
|
+
let resolvedLocation = resolveTo(location, routePathnames, currentUrl.pathname);
|
|
3038
3050
|
invariant(createPath(resolvedLocation), "Unable to resolve redirect location: " + location); // Prepend the basename to the redirect location if we have one
|
|
3039
3051
|
|
|
3040
3052
|
if (basename) {
|
|
@@ -3117,10 +3129,13 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3117
3129
|
type: ResultType.data,
|
|
3118
3130
|
data: result
|
|
3119
3131
|
};
|
|
3120
|
-
}
|
|
3132
|
+
} // Utility method for creating the Request instances for loaders/actions during
|
|
3133
|
+
// client-side navigations and fetches. During SSR we will always have a
|
|
3134
|
+
// Request instance from the static handler (query/queryRoute)
|
|
3135
|
+
|
|
3121
3136
|
|
|
3122
|
-
function
|
|
3123
|
-
let url =
|
|
3137
|
+
function createClientSideRequest(location, signal, submission) {
|
|
3138
|
+
let url = createClientSideURL(stripHashFromPath(location)).toString();
|
|
3124
3139
|
let init = {
|
|
3125
3140
|
signal
|
|
3126
3141
|
};
|