react-router 8.5.1 → 8.5.3
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 +79 -3
- package/dist/development/dom-export.js +1 -1
- package/dist/development/index-react-server-client.js +1 -1
- package/dist/development/index-react-server.d.ts +46 -39
- package/dist/development/index-react-server.js +104 -41
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/await.js +1 -1
- package/dist/development/lib/components.d.ts +42 -38
- package/dist/development/lib/components.js +34 -36
- package/dist/development/lib/context.js +3 -2
- package/dist/development/lib/dom/dom.js +16 -5
- package/dist/development/lib/dom/lib.d.ts +2 -2
- package/dist/development/lib/dom/lib.js +22 -8
- package/dist/development/lib/dom/server.js +5 -3
- package/dist/development/lib/dom/ssr/components.js +4 -1
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/errorBoundaries.js +2 -1
- package/dist/development/lib/dom/ssr/fallback.js +2 -1
- package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
- package/dist/development/lib/dom/ssr/hydration.d.ts +1 -0
- package/dist/development/lib/dom/ssr/hydration.js +1 -1
- package/dist/development/lib/dom/ssr/invariant.js +1 -1
- package/dist/development/lib/dom/ssr/links.js +1 -1
- package/dist/development/lib/dom/ssr/markup.js +1 -1
- package/dist/development/lib/dom/ssr/route-discovery.js +1 -1
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +3 -1
- package/dist/development/lib/dom/ssr/routes.js +2 -1
- package/dist/development/lib/dom/ssr/server.js +1 -1
- package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.d.ts +1 -1
- package/dist/development/lib/dom-export/hydrated-router.js +4 -2
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.d.ts +30 -0
- package/dist/development/lib/hooks.js +46 -7
- package/dist/development/lib/href.js +4 -4
- package/dist/development/lib/router/history.js +10 -4
- package/dist/development/lib/router/instrumentation.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/development/lib/router/matcher.js +1 -1
- package/dist/development/lib/router/navigation.js +17 -2
- package/dist/development/lib/router/router.js +26 -9
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +8 -5
- package/dist/development/lib/router/utils.js +24 -9
- package/dist/development/lib/rsc/browser.js +27 -4
- package/dist/development/lib/rsc/errorBoundaries.js +3 -2
- package/dist/development/lib/rsc/html-stream/browser.js +1 -1
- package/dist/development/lib/rsc/html-stream/server.js +1 -1
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +4 -1
- package/dist/development/lib/rsc/server.ssr.d.ts +1 -0
- package/dist/development/lib/rsc/server.ssr.js +5 -4
- package/dist/development/lib/server-runtime/cookies.js +1 -1
- package/dist/development/lib/server-runtime/crypto.js +1 -1
- package/dist/development/lib/server-runtime/data.js +1 -1
- package/dist/development/lib/server-runtime/dev.js +1 -1
- package/dist/development/lib/server-runtime/entry.js +1 -1
- package/dist/development/lib/server-runtime/errors.js +1 -1
- package/dist/development/lib/server-runtime/headers.js +1 -1
- package/dist/development/lib/server-runtime/invariant.js +1 -1
- package/dist/development/lib/server-runtime/mode.js +1 -1
- package/dist/development/lib/server-runtime/routeMatching.js +1 -1
- package/dist/development/lib/server-runtime/routes.js +1 -1
- package/dist/development/lib/server-runtime/server.js +9 -6
- package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +3 -2
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions.d.ts +1 -1
- package/dist/development/lib/server-runtime/sessions.js +5 -3
- package/dist/development/lib/server-runtime/single-fetch.js +1 -1
- package/dist/development/lib/server-runtime/urls.js +1 -1
- package/dist/development/lib/server-runtime/warnings.js +1 -1
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/route-module-annotations.d.ts +16 -9
- package/dist/development/route-pattern.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +83 -73
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
- package/dist/production/dom-export.js +1 -1
- package/dist/production/index-react-server-client.js +1 -1
- package/dist/production/index-react-server.d.ts +46 -39
- package/dist/production/index-react-server.js +104 -41
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/await.js +1 -1
- package/dist/production/lib/components.d.ts +42 -38
- package/dist/production/lib/components.js +34 -36
- package/dist/production/lib/context.js +3 -2
- package/dist/production/lib/dom/dom.js +16 -5
- package/dist/production/lib/dom/lib.d.ts +2 -2
- package/dist/production/lib/dom/lib.js +22 -8
- package/dist/production/lib/dom/server.js +5 -3
- package/dist/production/lib/dom/ssr/components.js +4 -1
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/errorBoundaries.js +2 -1
- package/dist/production/lib/dom/ssr/fallback.js +1 -1
- package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
- package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
- package/dist/production/lib/dom/ssr/hydration.js +1 -1
- package/dist/production/lib/dom/ssr/invariant.js +1 -1
- package/dist/production/lib/dom/ssr/links.js +1 -1
- package/dist/production/lib/dom/ssr/markup.js +1 -1
- package/dist/production/lib/dom/ssr/route-discovery.js +1 -1
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +3 -1
- package/dist/production/lib/dom/ssr/routes.js +2 -1
- package/dist/production/lib/dom/ssr/server.js +1 -1
- package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
- package/dist/production/lib/dom-export/hydrated-router.js +4 -2
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.d.ts +30 -0
- package/dist/production/lib/hooks.js +45 -6
- package/dist/production/lib/href.js +4 -4
- package/dist/production/lib/router/history.js +10 -4
- package/dist/production/lib/router/instrumentation.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/production/lib/router/matcher.js +1 -1
- package/dist/production/lib/router/navigation.js +17 -2
- package/dist/production/lib/router/router.js +26 -9
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +8 -5
- package/dist/production/lib/router/utils.js +24 -9
- package/dist/production/lib/rsc/browser.js +27 -4
- package/dist/production/lib/rsc/errorBoundaries.js +3 -2
- package/dist/production/lib/rsc/html-stream/browser.js +1 -1
- package/dist/production/lib/rsc/html-stream/server.js +1 -1
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +4 -1
- package/dist/production/lib/rsc/server.ssr.d.ts +1 -0
- package/dist/production/lib/rsc/server.ssr.js +5 -4
- package/dist/production/lib/server-runtime/cookies.js +1 -1
- package/dist/production/lib/server-runtime/crypto.js +1 -1
- package/dist/production/lib/server-runtime/data.js +1 -1
- package/dist/production/lib/server-runtime/dev.js +1 -1
- package/dist/production/lib/server-runtime/entry.js +1 -1
- package/dist/production/lib/server-runtime/errors.js +1 -1
- package/dist/production/lib/server-runtime/headers.js +1 -1
- package/dist/production/lib/server-runtime/invariant.js +1 -1
- package/dist/production/lib/server-runtime/mode.js +1 -1
- package/dist/production/lib/server-runtime/routeMatching.js +1 -1
- package/dist/production/lib/server-runtime/routes.js +1 -1
- package/dist/production/lib/server-runtime/server.js +9 -6
- package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +3 -2
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions.d.ts +1 -1
- package/dist/production/lib/server-runtime/sessions.js +5 -3
- package/dist/production/lib/server-runtime/single-fetch.js +1 -1
- package/dist/production/lib/server-runtime/urls.js +1 -1
- package/dist/production/lib/server-runtime/warnings.js +1 -1
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/route-module-annotations.d.ts +16 -9
- package/dist/production/route-pattern.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +83 -73
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/upgrading/v7.md +11 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { warning } from "../router/history.js";
|
|
11
|
+
import { createPath, parsePath, warning } from "../router/history.js";
|
|
12
12
|
import { stripBasename } from "../router/utils.js";
|
|
13
13
|
const defaultEncType = "application/x-www-form-urlencoded";
|
|
14
14
|
function isHtmlElement(object) {
|
|
@@ -27,7 +27,8 @@ function isModifiedEvent(event) {
|
|
|
27
27
|
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
28
28
|
}
|
|
29
29
|
function shouldProcessLinkClick(event, target) {
|
|
30
|
-
|
|
30
|
+
let element = event.currentTarget;
|
|
31
|
+
return event.button === 0 && (!target || target === "_self") && !isModifiedEvent(event) && !((element?.localName === "a" || element?.localName === "area") && element.hasAttribute("href") && element.hasAttribute("download"));
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Creates a URLSearchParams object using the given initializer.
|
|
@@ -86,12 +87,22 @@ const supportedFormEncTypes = new Set([
|
|
|
86
87
|
"text/plain"
|
|
87
88
|
]);
|
|
88
89
|
function getFormEncType(encType) {
|
|
90
|
+
encType = encType?.toLowerCase() ?? null;
|
|
89
91
|
if (encType != null && !supportedFormEncTypes.has(encType)) {
|
|
90
92
|
warning(false, `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`);
|
|
91
93
|
return null;
|
|
92
94
|
}
|
|
93
95
|
return encType;
|
|
94
96
|
}
|
|
97
|
+
function stripBasenameFromAction(action, basename) {
|
|
98
|
+
if (basename === "/") return action;
|
|
99
|
+
let path = parsePath(action);
|
|
100
|
+
let pathname = stripBasename(path.pathname || "", basename);
|
|
101
|
+
return pathname == null ? null : createPath({
|
|
102
|
+
...path,
|
|
103
|
+
pathname
|
|
104
|
+
});
|
|
105
|
+
}
|
|
95
106
|
function getFormSubmissionInfo(target, basename) {
|
|
96
107
|
let method;
|
|
97
108
|
let action;
|
|
@@ -100,7 +111,7 @@ function getFormSubmissionInfo(target, basename) {
|
|
|
100
111
|
let body;
|
|
101
112
|
if (isFormElement(target)) {
|
|
102
113
|
let attr = target.getAttribute("action");
|
|
103
|
-
action = attr ?
|
|
114
|
+
action = attr ? stripBasenameFromAction(attr, basename) : null;
|
|
104
115
|
method = target.getAttribute("method") || "get";
|
|
105
116
|
encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
|
|
106
117
|
formData = new FormData(target);
|
|
@@ -108,7 +119,7 @@ function getFormSubmissionInfo(target, basename) {
|
|
|
108
119
|
let form = target.form;
|
|
109
120
|
if (form == null) throw new Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);
|
|
110
121
|
let attr = target.getAttribute("formaction") || form.getAttribute("action");
|
|
111
|
-
action = attr ?
|
|
122
|
+
action = attr ? stripBasenameFromAction(attr, basename) : null;
|
|
112
123
|
method = target.getAttribute("formmethod") || form.getAttribute("method") || "get";
|
|
113
124
|
encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
|
|
114
125
|
formData = new FormData(form, target);
|
|
@@ -69,7 +69,7 @@ interface DOMRouterOpts {
|
|
|
69
69
|
*
|
|
70
70
|
* You will almost always include a complete set of `loaderData` to hydrate a
|
|
71
71
|
* server-rendered app. But in advanced use-cases (such as Framework Mode's
|
|
72
|
-
* [`clientLoader`](../../start/framework/route-module#
|
|
72
|
+
* [`clientLoader`](../../start/framework/route-module#clientloader)), you may
|
|
73
73
|
* want to include `loaderData` for only some routes that were loaded/rendered
|
|
74
74
|
* on the server. This allows you to hydrate _some_ of the routes (such as the
|
|
75
75
|
* app layout/shell) while showing a `HydrateFallback` component and running
|
|
@@ -208,7 +208,7 @@ interface DOMRouterOpts {
|
|
|
208
208
|
* To combat this, we introduced [`route.lazy`](../../start/data/route-object#lazy)
|
|
209
209
|
* in [v6.9.0](https://github.com/remix-run/react-router/blob/main/CHANGELOG.md#v690)
|
|
210
210
|
* which lets you lazily load the route _implementation_ ([`loader`](../../start/data/route-object#loader),
|
|
211
|
-
* [`Component`](../../start/data/route-object#
|
|
211
|
+
* [`Component`](../../start/data/route-object#component), etc.) while still
|
|
212
212
|
* providing the route _definition_ aspects up front (`path`, `index`, etc.).
|
|
213
213
|
* This is a good middle ground. React Router still knows about your route
|
|
214
214
|
* definitions (the lightweight part) up front and can perform synchronous
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { ABSOLUTE_URL_REGEX } from "../router/url.js";
|
|
12
12
|
import { createBrowserHistory, createHashHistory, createPath, invariant, warning } from "../router/history.js";
|
|
13
|
+
import { validateDocumentNavigationTarget } from "../router/navigation.js";
|
|
13
14
|
import { ErrorResponseImpl, SUPPORTED_ERROR_TYPES, defaultMapRouteProperties, joinPaths, matchPath, parseToInfo, resolveTo, stripBasename } from "../router/utils.js";
|
|
14
15
|
import { IDLE_FETCHER, createRouter } from "../router/router.js";
|
|
15
16
|
import { DataRouterNavigationContext, NavigationContext, RouteContext, ViewTransitionContext } from "../context.js";
|
|
@@ -314,10 +315,12 @@ const Link = React$1.forwardRef(function LinkWithRef({ onClick, discover = "rend
|
|
|
314
315
|
if (!event.defaultPrevented) internalOnClick(event);
|
|
315
316
|
}
|
|
316
317
|
let isSpaLink = !(parsed.isExternal || reloadDocument);
|
|
318
|
+
let renderedHref = (isSpaLink ? maskedHref : void 0) || parsed.absoluteURL || href;
|
|
319
|
+
validateDocumentNavigationTarget(renderedHref);
|
|
317
320
|
let link = /* @__PURE__ */ React$1.createElement("a", {
|
|
318
321
|
...rest,
|
|
319
322
|
...prefetchHandlers,
|
|
320
|
-
href:
|
|
323
|
+
href: renderedHref,
|
|
321
324
|
onClick: isSpaLink ? handleClick : onClick,
|
|
322
325
|
ref: mergeRefs(forwardedRef, prefetchRef),
|
|
323
326
|
target,
|
|
@@ -326,6 +329,8 @@ const Link = React$1.forwardRef(function LinkWithRef({ onClick, discover = "rend
|
|
|
326
329
|
return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, link, /* @__PURE__ */ React$1.createElement(PrefetchPageLinks, { page: href })) : link;
|
|
327
330
|
});
|
|
328
331
|
Link.displayName = "Link";
|
|
332
|
+
const subscribeToNothing = () => () => {};
|
|
333
|
+
const getClientSpaFallback = () => false;
|
|
329
334
|
/**
|
|
330
335
|
* Wraps {@link Link | `<Link>`} with additional props for styling active and
|
|
331
336
|
* pending states.
|
|
@@ -374,7 +379,9 @@ const NavLink = React$1.forwardRef(function NavLinkWithRef({ "aria-current": ari
|
|
|
374
379
|
let location = useLocation();
|
|
375
380
|
let routerNavigation = React$1.useContext(DataRouterNavigationContext);
|
|
376
381
|
let { navigator, basename } = React$1.useContext(NavigationContext);
|
|
377
|
-
let
|
|
382
|
+
let isSpaMode = React$1.useContext(FrameworkContext)?.isSpaMode === true;
|
|
383
|
+
let isSpaFallback = React$1.useSyncExternalStore(subscribeToNothing, getClientSpaFallback, () => isSpaMode);
|
|
384
|
+
let isTransitioning = routerNavigation != null && useViewTransitionState(path) && viewTransition === true && !isSpaFallback;
|
|
378
385
|
let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
|
|
379
386
|
let locationPathname = location.pathname;
|
|
380
387
|
let nextLocationPathname = routerNavigation?.navigation.location ? routerNavigation.navigation.location.pathname : null;
|
|
@@ -385,8 +392,8 @@ const NavLink = React$1.forwardRef(function NavLinkWithRef({ "aria-current": ari
|
|
|
385
392
|
}
|
|
386
393
|
if (nextLocationPathname && basename) nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
|
|
387
394
|
const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
|
|
388
|
-
let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
|
|
389
|
-
let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(endSlashPosition) === "/");
|
|
395
|
+
let isActive = !isSpaFallback && (locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/");
|
|
396
|
+
let isPending = !isSpaFallback && nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(endSlashPosition) === "/");
|
|
390
397
|
let renderProps = {
|
|
391
398
|
isActive,
|
|
392
399
|
isPending,
|
|
@@ -562,7 +569,9 @@ function ScrollRestoration({ getKey, storageKey, ...props }) {
|
|
|
562
569
|
if (typeof storedY === "number") window.scrollTo(0, storedY);
|
|
563
570
|
} catch (error) {
|
|
564
571
|
console.error(error);
|
|
565
|
-
|
|
572
|
+
try {
|
|
573
|
+
sessionStorage.removeItem(storageKey);
|
|
574
|
+
} catch {}
|
|
566
575
|
}
|
|
567
576
|
}).toString();
|
|
568
577
|
if (props.nonce == null && remixContext?.nonce) props.nonce = remixContext.nonce;
|
|
@@ -872,7 +881,9 @@ function useFormAction(action, { relative } = {}) {
|
|
|
872
881
|
}
|
|
873
882
|
if ((!action || action === ".") && match.route.index) path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
874
883
|
if (basename !== "/") path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
875
|
-
|
|
884
|
+
let formAction = createPath(path);
|
|
885
|
+
validateDocumentNavigationTarget(formAction);
|
|
886
|
+
return formAction;
|
|
876
887
|
}
|
|
877
888
|
/**
|
|
878
889
|
* Useful for creating complex, dynamic user interfaces that require multiple,
|
|
@@ -1101,7 +1112,10 @@ function useScrollRestoration({ getKey, storageKey } = {}) {
|
|
|
1101
1112
|
React$1.useLayoutEffect(() => {
|
|
1102
1113
|
try {
|
|
1103
1114
|
let sessionPositions = sessionStorage.getItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY);
|
|
1104
|
-
if (sessionPositions)
|
|
1115
|
+
if (sessionPositions) {
|
|
1116
|
+
let parsedPositions = JSON.parse(sessionPositions);
|
|
1117
|
+
savedScrollPositions = parsedPositions && typeof parsedPositions === "object" && !Array.isArray(parsedPositions) ? parsedPositions : {};
|
|
1118
|
+
}
|
|
1105
1119
|
} catch {}
|
|
1106
1120
|
}, [storageKey]);
|
|
1107
1121
|
React$1.useLayoutEffect(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { PROTOCOL_RELATIVE_URL_REGEX } from "../router/url.js";
|
|
12
12
|
import { createPath, invariant, parsePath, warning } from "../router/history.js";
|
|
13
13
|
import { convertRoutesToDataRoutes, isRouteErrorResponse } from "../router/utils.js";
|
|
14
14
|
import { IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION } from "../router/router.js";
|
|
@@ -314,9 +314,11 @@ function createHref(to) {
|
|
|
314
314
|
return typeof to === "string" ? to : createPath(to);
|
|
315
315
|
}
|
|
316
316
|
function encodeLocation(to) {
|
|
317
|
+
let base = "http://localhost";
|
|
317
318
|
let href = typeof to === "string" ? to : createPath(to);
|
|
318
319
|
href = href.replace(/ $/, "%20");
|
|
319
|
-
|
|
320
|
+
if (PROTOCOL_RELATIVE_URL_REGEX.test(href)) href = base + href;
|
|
321
|
+
let encoded = new URL(href, base);
|
|
320
322
|
return {
|
|
321
323
|
pathname: encoded.pathname,
|
|
322
324
|
search: encoded.search,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -143,12 +143,14 @@ function Links({ nonce, crossOrigin }) {
|
|
|
143
143
|
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, typeof criticalCss === "string" ? /* @__PURE__ */ React$1.createElement("style", {
|
|
144
144
|
[CRITICAL_CSS_DATA_ATTRIBUTE]: "",
|
|
145
145
|
nonce,
|
|
146
|
+
suppressHydrationWarning: true,
|
|
146
147
|
dangerouslySetInnerHTML: { __html: criticalCss }
|
|
147
148
|
}) : null, typeof criticalCss === "object" ? /* @__PURE__ */ React$1.createElement("link", {
|
|
148
149
|
[CRITICAL_CSS_DATA_ATTRIBUTE]: "",
|
|
149
150
|
rel: "stylesheet",
|
|
150
151
|
href: criticalCss.href,
|
|
151
152
|
nonce,
|
|
153
|
+
suppressHydrationWarning: true,
|
|
152
154
|
crossOrigin
|
|
153
155
|
}) : null, keyedLinks.map(({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React$1.createElement(PrefetchPageLinks, {
|
|
154
156
|
key,
|
|
@@ -158,6 +160,7 @@ function Links({ nonce, crossOrigin }) {
|
|
|
158
160
|
}) : /* @__PURE__ */ React$1.createElement("link", {
|
|
159
161
|
key,
|
|
160
162
|
nonce,
|
|
163
|
+
suppressHydrationWarning: true,
|
|
161
164
|
...link,
|
|
162
165
|
crossOrigin: link.crossOrigin ?? crossOrigin
|
|
163
166
|
})));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -49,6 +49,7 @@ function RemixRootDefaultErrorBoundary({ error, isOutsideRemixApp }) {
|
|
|
49
49
|
console.error(error);
|
|
50
50
|
let heyDeveloper = /* @__PURE__ */ React$1.createElement("script", {
|
|
51
51
|
nonce,
|
|
52
|
+
suppressHydrationWarning: true,
|
|
52
53
|
dangerouslySetInnerHTML: { __html: `
|
|
53
54
|
console.log(
|
|
54
55
|
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
|
|
@@ -22,6 +22,7 @@ declare function getHydrationData({
|
|
|
22
22
|
routes: DataRouteObject[];
|
|
23
23
|
getRouteInfo: (routeId: string) => {
|
|
24
24
|
clientLoader: ClientLoaderFunction | undefined;
|
|
25
|
+
clientMiddleware?: DataRouteObject["middleware"];
|
|
25
26
|
hasLoader: boolean;
|
|
26
27
|
hasHydrateFallback: boolean;
|
|
27
28
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -69,6 +69,7 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
|
69
69
|
id: route.id,
|
|
70
70
|
path: route.path,
|
|
71
71
|
index: route.index,
|
|
72
|
+
caseSensitive: route.caseSensitive,
|
|
72
73
|
Component: route.Component ? withComponentProps(route.Component) : void 0,
|
|
73
74
|
HydrateFallback: route.HydrateFallback ? withHydrateFallbackProps(route.HydrateFallback) : void 0,
|
|
74
75
|
ErrorBoundary: route.ErrorBoundary ? withErrorBoundaryProps(route.ErrorBoundary) : void 0,
|
|
@@ -91,6 +92,7 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
|
91
92
|
id: route.id,
|
|
92
93
|
path: route.path,
|
|
93
94
|
index: route.index,
|
|
95
|
+
caseSensitive: route.caseSensitive,
|
|
94
96
|
parentId,
|
|
95
97
|
hasAction: route.action != null,
|
|
96
98
|
hasLoader: route.loader != null,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -114,6 +114,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
let dataRoute = {
|
|
117
|
+
caseSensitive: route.caseSensitive,
|
|
117
118
|
id: route.id,
|
|
118
119
|
index: route.index,
|
|
119
120
|
path: route.path
|
|
@@ -15,7 +15,7 @@ interface HydratedRouterProps {
|
|
|
15
15
|
* Context factory function to be passed through to {@link createBrowserRouter}.
|
|
16
16
|
* This function will be called to create a fresh `context` instance on each
|
|
17
17
|
* navigation/fetch and made available to
|
|
18
|
-
* [`clientAction`](../../start/framework/route-module#
|
|
18
|
+
* [`clientAction`](../../start/framework/route-module#clientaction)/[`clientLoader`](../../start/framework/route-module#clientloader)
|
|
19
19
|
* functions.
|
|
20
20
|
*/
|
|
21
21
|
getContext?: RouterInit["getContext"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -126,7 +126,9 @@ function HydratedRouter(props) {
|
|
|
126
126
|
}
|
|
127
127
|
let [criticalCss, setCriticalCss] = React$1.useState(process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0);
|
|
128
128
|
React$1.useEffect(() => {
|
|
129
|
-
if (process.env.NODE_ENV === "development")
|
|
129
|
+
if (process.env.NODE_ENV === "development") React$1.startTransition(() => {
|
|
130
|
+
setCriticalCss(void 0);
|
|
131
|
+
});
|
|
130
132
|
}, []);
|
|
131
133
|
React$1.useEffect(() => {
|
|
132
134
|
if (process.env.NODE_ENV === "development" && criticalCss === void 0) document.querySelectorAll(`[${CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
|
|
@@ -884,6 +884,36 @@ type UseRoute<RouteId extends keyof RouteModules | unknown> = {
|
|
|
884
884
|
loaderData: RouteId extends keyof RouteModules ? GetLoaderData<RouteModules[RouteId]> | undefined : unknown;
|
|
885
885
|
actionData: RouteId extends keyof RouteModules ? GetActionData<RouteModules[RouteId]> | undefined : unknown;
|
|
886
886
|
};
|
|
887
|
+
/**
|
|
888
|
+
* Returns the current route's `handle`, `loaderData`, and `actionData`, or
|
|
889
|
+
* those of a matched route identified by `routeId`.
|
|
890
|
+
*
|
|
891
|
+
* Omit `routeId` to read the current route. Pass a route ID to infer the
|
|
892
|
+
* fields from registered route module types. Without an ID, the fields
|
|
893
|
+
* are typed as `unknown`.
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* import { unstable_useRoute as useRoute } from "react-router";
|
|
897
|
+
*
|
|
898
|
+
* let currentRoute = useRoute();
|
|
899
|
+
* let rootRoute = useRoute("root");
|
|
900
|
+
*
|
|
901
|
+
* // A registered non-root route may not currently be matched:
|
|
902
|
+
* let dashboard = useRoute("routes/dashboard");
|
|
903
|
+
* if (dashboard) {
|
|
904
|
+
* console.log(dashboard.handle, dashboard.loaderData);
|
|
905
|
+
* }
|
|
906
|
+
*
|
|
907
|
+
* @name unstable_useRoute
|
|
908
|
+
* @public
|
|
909
|
+
* @category Hooks
|
|
910
|
+
* @mode framework
|
|
911
|
+
* @mode data
|
|
912
|
+
* @param args An optional route ID. Omit it to read the current route.
|
|
913
|
+
* @returns An object with the route's `handle`, `loaderData`, and
|
|
914
|
+
* `actionData`, or `undefined` if the specified route is not matched.
|
|
915
|
+
* Individual fields can be `undefined` when the handle or data is unavailable.
|
|
916
|
+
*/
|
|
887
917
|
declare function useRoute<Args extends UseRouteArgs>(...args: Args): UseRouteResult<Args>;
|
|
888
918
|
/**
|
|
889
919
|
* A single route match returned from {@link unstable_useRouterState}. Mirrors
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import { createPath, invariant, parsePath, warning } from "./router/history.js";
|
|
12
|
-
import { convertRouteMatchToUiMatch, decodePath, getResolveToMatches, getRoutePattern, isBrowser, isRouteErrorResponse, joinPaths, matchPath, matchRoutes, parseToInfo, resolveTo, stripBasename } from "./router/utils.js";
|
|
13
12
|
import { getNavigatorCurrentUrl, validateNavigationTarget } from "./router/navigation.js";
|
|
13
|
+
import { convertRouteMatchToUiMatch, decodePath, getResolveToMatches, getRoutePattern, isBrowser, isRouteErrorResponse, joinPaths, matchPath, matchRoutes, parseToInfo, resolveTo, stripBasename } from "./router/utils.js";
|
|
14
14
|
import { IDLE_BLOCKER, hasInvalidProtocol } from "./router/router.js";
|
|
15
|
-
import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
|
|
15
|
+
import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCErrorAlreadyReportedContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
|
|
16
16
|
import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "./errors.js";
|
|
17
17
|
import * as React$1 from "react";
|
|
18
18
|
//#region lib/hooks.tsx
|
|
@@ -620,6 +620,7 @@ function useRoutesImpl(routes, locationArg, dataRouterOpts) {
|
|
|
620
620
|
}
|
|
621
621
|
function DefaultErrorComponent() {
|
|
622
622
|
let error = useRouteError();
|
|
623
|
+
React$1.useContext(RSCErrorAlreadyReportedContext);
|
|
623
624
|
let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
|
|
624
625
|
let stack = error instanceof Error ? error.stack : null;
|
|
625
626
|
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React$1.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React$1.createElement("pre", { style: {
|
|
@@ -1254,13 +1255,21 @@ function useBlocker(shouldBlock) {
|
|
|
1254
1255
|
historyAction
|
|
1255
1256
|
});
|
|
1256
1257
|
}, [basename, shouldBlock]);
|
|
1258
|
+
let activeBlockerKey = React$1.useRef("");
|
|
1259
|
+
let activeBlockerRouter = React$1.useRef(null);
|
|
1257
1260
|
React$1.useEffect(() => {
|
|
1258
1261
|
let key = String(++blockerId);
|
|
1262
|
+
activeBlockerKey.current = key;
|
|
1263
|
+
activeBlockerRouter.current = router;
|
|
1259
1264
|
setBlockerKey(key);
|
|
1260
|
-
return () =>
|
|
1265
|
+
return () => {
|
|
1266
|
+
activeBlockerKey.current = "";
|
|
1267
|
+
activeBlockerRouter.current = null;
|
|
1268
|
+
router.deleteBlocker(key);
|
|
1269
|
+
};
|
|
1261
1270
|
}, [router]);
|
|
1262
|
-
React$1.
|
|
1263
|
-
if (blockerKey !== "") router.getBlocker(blockerKey, blockerFunction);
|
|
1271
|
+
React$1.useLayoutEffect(() => {
|
|
1272
|
+
if (blockerKey !== "" && blockerKey === activeBlockerKey.current && router === activeBlockerRouter.current) router.getBlocker(blockerKey, blockerFunction);
|
|
1264
1273
|
}, [
|
|
1265
1274
|
router,
|
|
1266
1275
|
blockerKey,
|
|
@@ -1292,6 +1301,36 @@ function warningOnce(key, cond, message) {
|
|
|
1292
1301
|
warning(false, message);
|
|
1293
1302
|
}
|
|
1294
1303
|
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Returns the current route's `handle`, `loaderData`, and `actionData`, or
|
|
1306
|
+
* those of a matched route identified by `routeId`.
|
|
1307
|
+
*
|
|
1308
|
+
* Omit `routeId` to read the current route. Pass a route ID to infer the
|
|
1309
|
+
* fields from registered route module types. Without an ID, the fields
|
|
1310
|
+
* are typed as `unknown`.
|
|
1311
|
+
*
|
|
1312
|
+
* @example
|
|
1313
|
+
* import { unstable_useRoute as useRoute } from "react-router";
|
|
1314
|
+
*
|
|
1315
|
+
* let currentRoute = useRoute();
|
|
1316
|
+
* let rootRoute = useRoute("root");
|
|
1317
|
+
*
|
|
1318
|
+
* // A registered non-root route may not currently be matched:
|
|
1319
|
+
* let dashboard = useRoute("routes/dashboard");
|
|
1320
|
+
* if (dashboard) {
|
|
1321
|
+
* console.log(dashboard.handle, dashboard.loaderData);
|
|
1322
|
+
* }
|
|
1323
|
+
*
|
|
1324
|
+
* @name unstable_useRoute
|
|
1325
|
+
* @public
|
|
1326
|
+
* @category Hooks
|
|
1327
|
+
* @mode framework
|
|
1328
|
+
* @mode data
|
|
1329
|
+
* @param args An optional route ID. Omit it to read the current route.
|
|
1330
|
+
* @returns An object with the route's `handle`, `loaderData`, and
|
|
1331
|
+
* `actionData`, or `undefined` if the specified route is not matched.
|
|
1332
|
+
* Individual fields can be `undefined` when the handle or data is unavailable.
|
|
1333
|
+
*/
|
|
1295
1334
|
function useRoute(...args) {
|
|
1296
1335
|
const currentRouteId = useCurrentRouteId("useRoute");
|
|
1297
1336
|
const id = args[0] ?? currentRouteId;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -44,14 +44,14 @@ function href(path, ...args) {
|
|
|
44
44
|
let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
|
|
45
45
|
const isRequired = questionMark === void 0;
|
|
46
46
|
const value = params?.[param];
|
|
47
|
-
if (isRequired && value
|
|
47
|
+
if (isRequired && value == null) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
|
|
48
48
|
return value == null ? "" : "/" + encodePathParam(stringify(value));
|
|
49
49
|
});
|
|
50
50
|
if (path.endsWith("*")) {
|
|
51
51
|
const value = params?.["*"];
|
|
52
|
-
if (value
|
|
52
|
+
if (value != null) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
|
|
53
53
|
}
|
|
54
|
-
return result || "/";
|
|
54
|
+
return result.replace(/^\/{2,}/, "/") || "/";
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Removes a trailing splat and any number of slashes from the end of the path.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -111,11 +111,12 @@ function createMemoryHistory(options = {}) {
|
|
|
111
111
|
action = "POP";
|
|
112
112
|
let nextIndex = clampIndex(index + delta);
|
|
113
113
|
let nextLocation = entries[nextIndex];
|
|
114
|
+
let actualDelta = nextIndex - index;
|
|
114
115
|
index = nextIndex;
|
|
115
116
|
if (listener) listener({
|
|
116
117
|
action,
|
|
117
118
|
location: nextLocation,
|
|
118
|
-
delta
|
|
119
|
+
delta: actualDelta
|
|
119
120
|
});
|
|
120
121
|
},
|
|
121
122
|
listen(fn) {
|
|
@@ -164,11 +165,16 @@ function createHashHistory(options = {}) {
|
|
|
164
165
|
function createHashLocation(window, globalHistory) {
|
|
165
166
|
let { pathname = "/", search = "", hash = "" } = parsePath(window.location.hash.substring(1));
|
|
166
167
|
if (!pathname.startsWith("/") && !pathname.startsWith(".")) pathname = "/" + pathname;
|
|
167
|
-
|
|
168
|
+
let maskedLocation = globalHistory.state?.masked;
|
|
169
|
+
return createLocation("", maskedLocation || {
|
|
168
170
|
pathname,
|
|
169
171
|
search,
|
|
170
172
|
hash
|
|
171
|
-
}, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default"
|
|
173
|
+
}, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default", maskedLocation ? {
|
|
174
|
+
pathname,
|
|
175
|
+
search,
|
|
176
|
+
hash
|
|
177
|
+
} : void 0);
|
|
172
178
|
}
|
|
173
179
|
function createHashHref(window, to) {
|
|
174
180
|
let base = window.document.querySelector("base");
|