react-router 8.5.1 → 8.5.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 +29 -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 +43 -37
- package/dist/development/index-react-server.js +64 -6
- 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 +25 -29
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.js +13 -4
- package/dist/development/lib/dom/lib.d.ts +2 -2
- package/dist/development/lib/dom/lib.js +11 -4
- package/dist/development/lib/dom/server.js +1 -1
- package/dist/development/lib/dom/ssr/components.js +1 -1
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/development/lib/dom/ssr/fallback.js +1 -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 +1 -1
- package/dist/development/lib/dom/ssr/routes.js +1 -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.js +9 -4
- package/dist/development/lib/href.js +4 -4
- package/dist/development/lib/router/history.js +1 -1
- 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 +5 -2
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +6 -5
- package/dist/development/lib/router/utils.js +17 -8
- package/dist/development/lib/rsc/browser.js +26 -3
- package/dist/development/lib/rsc/errorBoundaries.js +1 -1
- 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 +2 -0
- package/dist/development/lib/rsc/server.ssr.js +1 -1
- 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 +1 -1
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions.js +1 -1
- 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 +1 -1
- 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 +75 -66
- 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 +43 -37
- package/dist/production/index-react-server.js +64 -6
- 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 +25 -29
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.js +13 -4
- package/dist/production/lib/dom/lib.d.ts +2 -2
- package/dist/production/lib/dom/lib.js +11 -4
- package/dist/production/lib/dom/server.js +1 -1
- package/dist/production/lib/dom/ssr/components.js +1 -1
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -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 +1 -1
- package/dist/production/lib/dom/ssr/routes.js +1 -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.js +9 -4
- package/dist/production/lib/href.js +4 -4
- package/dist/production/lib/router/history.js +1 -1
- 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 +5 -2
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +6 -5
- package/dist/production/lib/router/utils.js +17 -8
- package/dist/production/lib/rsc/browser.js +26 -3
- package/dist/production/lib/rsc/errorBoundaries.js +1 -1
- 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 +2 -0
- package/dist/production/lib/rsc/server.ssr.js +1 -1
- 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 +1 -1
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions.js +1 -1
- 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 +1 -1
- 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 +75 -66
- 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.2
|
|
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,
|
|
@@ -562,7 +565,9 @@ function ScrollRestoration({ getKey, storageKey, ...props }) {
|
|
|
562
565
|
if (typeof storedY === "number") window.scrollTo(0, storedY);
|
|
563
566
|
} catch (error) {
|
|
564
567
|
console.error(error);
|
|
565
|
-
|
|
568
|
+
try {
|
|
569
|
+
sessionStorage.removeItem(storageKey);
|
|
570
|
+
} catch {}
|
|
566
571
|
}
|
|
567
572
|
}).toString();
|
|
568
573
|
if (props.nonce == null && remixContext?.nonce) props.nonce = remixContext.nonce;
|
|
@@ -872,7 +877,9 @@ function useFormAction(action, { relative } = {}) {
|
|
|
872
877
|
}
|
|
873
878
|
if ((!action || action === ".") && match.route.index) path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
874
879
|
if (basename !== "/") path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
875
|
-
|
|
880
|
+
let formAction = createPath(path);
|
|
881
|
+
validateDocumentNavigationTarget(formAction);
|
|
882
|
+
return formAction;
|
|
876
883
|
}
|
|
877
884
|
/**
|
|
878
885
|
* Useful for creating complex, dynamic user interfaces that require multiple,
|
|
@@ -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
|
};
|
|
@@ -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.2
|
|
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());
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -9,8 +9,8 @@
|
|
|
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
15
|
import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
|
|
16
16
|
import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "./errors.js";
|
|
@@ -1254,13 +1254,18 @@ function useBlocker(shouldBlock) {
|
|
|
1254
1254
|
historyAction
|
|
1255
1255
|
});
|
|
1256
1256
|
}, [basename, shouldBlock]);
|
|
1257
|
+
let activeBlockerKey = React$1.useRef("");
|
|
1257
1258
|
React$1.useEffect(() => {
|
|
1258
1259
|
let key = String(++blockerId);
|
|
1260
|
+
activeBlockerKey.current = key;
|
|
1259
1261
|
setBlockerKey(key);
|
|
1260
|
-
return () =>
|
|
1262
|
+
return () => {
|
|
1263
|
+
activeBlockerKey.current = "";
|
|
1264
|
+
router.deleteBlocker(key);
|
|
1265
|
+
};
|
|
1261
1266
|
}, [router]);
|
|
1262
1267
|
React$1.useEffect(() => {
|
|
1263
|
-
if (blockerKey !== "") router.getBlocker(blockerKey, blockerFunction);
|
|
1268
|
+
if (blockerKey !== "" && blockerKey === activeBlockerKey.current) router.getBlocker(blockerKey, blockerFunction);
|
|
1264
1269
|
}, [
|
|
1265
1270
|
router,
|
|
1266
1271
|
blockerKey,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
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.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
+
import { ABSOLUTE_URL_REGEX } from "./url.js";
|
|
11
12
|
//#region lib/router/navigation.ts
|
|
12
13
|
const DEFAULT_NAVIGATION_URL = new URL("http://localhost");
|
|
13
14
|
function getNavigatorCurrentUrl(navigator) {
|
|
@@ -27,6 +28,20 @@ function isExplicitUrl(destination, target) {
|
|
|
27
28
|
if (!destination.toLowerCase().startsWith(protocol)) return false;
|
|
28
29
|
return target.host === "" || destination.slice(protocol.length).startsWith("//");
|
|
29
30
|
}
|
|
31
|
+
function validateDocumentNavigationTarget(destination) {
|
|
32
|
+
let normalized = destination.replace(/[\t\n\r]/g, "");
|
|
33
|
+
let start = 0;
|
|
34
|
+
while (normalized.charCodeAt(start) <= 32) start++;
|
|
35
|
+
normalized = normalized.slice(start);
|
|
36
|
+
if (!ABSOLUTE_URL_REGEX.test(normalized)) return;
|
|
37
|
+
let target;
|
|
38
|
+
try {
|
|
39
|
+
target = new URL(destination, DEFAULT_NAVIGATION_URL);
|
|
40
|
+
} catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!isExplicitUrl(destination, target)) throw new Error("External navigation is not allowed");
|
|
44
|
+
}
|
|
30
45
|
function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
|
|
31
46
|
let originalUrl = null;
|
|
32
47
|
try {
|
|
@@ -42,4 +57,4 @@ function validateNavigationTarget(original, resolved, currentUrl, externalPolicy
|
|
|
42
57
|
}
|
|
43
58
|
}
|
|
44
59
|
//#endregion
|
|
45
|
-
export { getNavigatorCurrentUrl, validateNavigationTarget };
|
|
60
|
+
export { getNavigatorCurrentUrl, validateDocumentNavigationTarget, validateNavigationTarget };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
|
|
12
12
|
import { createBrowserURLImpl, createLocation, createPath, invariant, parsePath, warning } from "./history.js";
|
|
13
|
+
import { validateNavigationTarget } from "./navigation.js";
|
|
13
14
|
import { DiscoveryCancelledError, ErrorResponseImpl, RouterContextProvider, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createDataFunctionUrl, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, prependBasename, removeDoubleSlashes, resolveTo, stripBasename } from "./utils.js";
|
|
14
15
|
import { consumeInstrumentationClientResultMetaReceiver, getRouteInstrumentationUpdates, instrumentClientSideRouter } from "./instrumentation.js";
|
|
15
16
|
import { V6RegExMatcher } from "./matcher.js";
|
|
16
17
|
import { getRoutePatternMatcher } from "./matcher-route-pattern.preload.js";
|
|
17
|
-
import { validateNavigationTarget } from "./navigation.js";
|
|
18
18
|
//#region lib/router/router.ts
|
|
19
19
|
const validMutationMethodsArr = [
|
|
20
20
|
"POST",
|
|
@@ -573,6 +573,7 @@ function createRouter(init) {
|
|
|
573
573
|
}
|
|
574
574
|
matches = actionResult.matches || matches;
|
|
575
575
|
pendingActionResult = actionResult.pendingActionResult;
|
|
576
|
+
historyAction = pendingAction;
|
|
576
577
|
loadingNavigation = getLoadingNavigation(location, matches, historyAction, opts.submission);
|
|
577
578
|
flushSync = false;
|
|
578
579
|
fogOfWar.active = false;
|
|
@@ -851,6 +852,7 @@ function createRouter(init) {
|
|
|
851
852
|
let flushSync = (opts && opts.flushSync) === true;
|
|
852
853
|
let instrumentationResultMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
|
|
853
854
|
let normalizedPath = normalizeTo(state.location, state.matches, basename, href, routeId, opts?.relative);
|
|
855
|
+
validateNavigationTarget(null, normalizedPath, init.history.createURL("/"), "reject");
|
|
854
856
|
let matches = dataRouteMatcher.match(normalizedPath);
|
|
855
857
|
let fogOfWar = checkFogOfWar(matches, normalizedPath);
|
|
856
858
|
if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
|
|
@@ -2709,6 +2711,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
|
|
2709
2711
|
function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
|
|
2710
2712
|
let location = response.headers.get("Location");
|
|
2711
2713
|
invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
|
2714
|
+
validateNavigationTarget(location, location, new URL(request.url), "allow-explicit");
|
|
2712
2715
|
if (!isAbsoluteUrl(location)) {
|
|
2713
2716
|
let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
|
|
2714
2717
|
location = normalizeTo(new URL(request.url), trimmedMatches, basename, location);
|
|
@@ -512,7 +512,7 @@ type BaseRouteObject = {
|
|
|
512
512
|
action?: ActionFunction | boolean;
|
|
513
513
|
/**
|
|
514
514
|
* The route shouldRevalidate function.
|
|
515
|
-
* See [`shouldRevalidate`](../../start/data/route-object#
|
|
515
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldrevalidate).
|
|
516
516
|
*/
|
|
517
517
|
shouldRevalidate?: ShouldRevalidateFunction;
|
|
518
518
|
/**
|
|
@@ -718,13 +718,14 @@ interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
|
|
|
718
718
|
/**
|
|
719
719
|
* Returns a path with params interpolated.
|
|
720
720
|
*
|
|
721
|
-
*
|
|
722
|
-
* would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
721
|
+
* Named param values are percent-encoded for use in a path segment: characters
|
|
722
|
+
* that would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
723
723
|
* are escaped, while characters that RFC 3986 allows literally in a path
|
|
724
724
|
* segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
|
|
725
725
|
* encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
|
|
726
|
-
* delimiters and must be escaped. Splat (`*`) values are
|
|
727
|
-
*
|
|
726
|
+
* delimiters and must be escaped. Splat (`*`) values are interpolated without
|
|
727
|
+
* per-segment encoding. Leading URL separators and schemes are handled so
|
|
728
|
+
* interpolated values remain paths.
|
|
728
729
|
*
|
|
729
730
|
* See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
|
|
730
731
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { ABSOLUTE_URL_REGEX, PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
|
|
12
12
|
import { invariant, parsePath, warning } from "./history.js";
|
|
13
|
+
import { validateDocumentNavigationTarget } from "./navigation.js";
|
|
13
14
|
import * as React$1 from "react";
|
|
14
15
|
//#region lib/router/utils.ts
|
|
15
16
|
/**
|
|
@@ -413,13 +414,14 @@ function encodePathParam(value) {
|
|
|
413
414
|
/**
|
|
414
415
|
* Returns a path with params interpolated.
|
|
415
416
|
*
|
|
416
|
-
*
|
|
417
|
-
* would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
417
|
+
* Named param values are percent-encoded for use in a path segment: characters
|
|
418
|
+
* that would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
418
419
|
* are escaped, while characters that RFC 3986 allows literally in a path
|
|
419
420
|
* segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
|
|
420
421
|
* encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
|
|
421
|
-
* delimiters and must be escaped. Splat (`*`) values are
|
|
422
|
-
*
|
|
422
|
+
* delimiters and must be escaped. Splat (`*`) values are interpolated without
|
|
423
|
+
* per-segment encoding. Leading URL separators and schemes are handled so
|
|
424
|
+
* interpolated values remain paths.
|
|
423
425
|
*
|
|
424
426
|
* See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
|
|
425
427
|
*
|
|
@@ -444,7 +446,7 @@ function generatePath(originalPath, params = {}) {
|
|
|
444
446
|
}
|
|
445
447
|
const prefix = path.startsWith("/") ? "/" : "";
|
|
446
448
|
const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
|
|
447
|
-
|
|
449
|
+
let result = (prefix + path.split(/\/+/).map((segment, index, array) => {
|
|
448
450
|
if (index === array.length - 1 && segment === "*") return stringify(params["*"]);
|
|
449
451
|
const keyMatch = segment.match(/^:([\w-]+)(\??)(.*)/);
|
|
450
452
|
if (keyMatch) {
|
|
@@ -454,7 +456,10 @@ function generatePath(originalPath, params = {}) {
|
|
|
454
456
|
return encodePathParam(stringify(param)) + suffix;
|
|
455
457
|
}
|
|
456
458
|
return segment.replace(/\?$/g, "");
|
|
457
|
-
}).filter((segment) => !!segment).join("/");
|
|
459
|
+
}).filter((segment) => !!segment).join("/")).replace(/^[\\/]{2,}/, "/");
|
|
460
|
+
if (!prefix && (path.startsWith(":") || path === "*")) result = result.replace(/^([a-z][a-z0-9+.-]*):/i, "$1%3A");
|
|
461
|
+
validateDocumentNavigationTarget(result);
|
|
462
|
+
return result;
|
|
458
463
|
}
|
|
459
464
|
/**
|
|
460
465
|
* Performs pattern matching on a URL pathname and returns information about
|
|
@@ -696,11 +701,15 @@ function data(data, init) {
|
|
|
696
701
|
* header.
|
|
697
702
|
*/
|
|
698
703
|
const redirect = (url, init = 302) => {
|
|
704
|
+
validateDocumentNavigationTarget(url);
|
|
699
705
|
let responseInit = init;
|
|
700
706
|
if (typeof responseInit === "number") responseInit = { status: responseInit };
|
|
701
|
-
else if (typeof responseInit.status === "undefined") responseInit.status = 302;
|
|
702
707
|
let headers = new Headers(responseInit.headers);
|
|
703
708
|
headers.set("Location", url);
|
|
709
|
+
if (typeof responseInit.status === "undefined") responseInit = {
|
|
710
|
+
...responseInit,
|
|
711
|
+
status: 302
|
|
712
|
+
};
|
|
704
713
|
return new Response(null, {
|
|
705
714
|
...responseInit,
|
|
706
715
|
headers
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { PROTOCOL_RELATIVE_URL_REGEX } from "../router/url.js";
|
|
12
12
|
import { createBrowserHistory, createPath, invariant } from "../router/history.js";
|
|
13
|
-
import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
|
|
14
13
|
import { validateNavigationTarget } from "../router/navigation.js";
|
|
14
|
+
import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
|
|
15
15
|
import { createRouter, hasInvalidProtocol, isMutationMethod } from "../router/router.js";
|
|
16
16
|
import { RSCRouterContext } from "../context.js";
|
|
17
17
|
import { createRequestInit } from "../dom/ssr/data.js";
|
|
@@ -163,6 +163,7 @@ function createRouterFromPayload({ fetchImplementation, createFromReadableStream
|
|
|
163
163
|
invariant(match, "Route not found in payload");
|
|
164
164
|
return {
|
|
165
165
|
clientLoader: match.clientLoader,
|
|
166
|
+
clientMiddleware: match.clientMiddleware,
|
|
166
167
|
hasLoader: match.hasLoader,
|
|
167
168
|
hasHydrateFallback: match.hydrateFallbackElement != null
|
|
168
169
|
};
|
|
@@ -207,10 +208,11 @@ function createRouterFromPayload({ fetchImplementation, createFromReadableStream
|
|
|
207
208
|
return routes.map((route) => {
|
|
208
209
|
const routeUpdate = routeUpdateByRouteId.get(route.id);
|
|
209
210
|
if (routeUpdate) {
|
|
210
|
-
const { routeModule, hasAction, hasComponent, hasLoader } = routeUpdate;
|
|
211
|
+
const { routeModule, hasAction, hasComponent, hasLoader, hasClientMiddleware } = routeUpdate;
|
|
211
212
|
const newRoute = createRouteFromServerManifest({
|
|
212
213
|
clientAction: routeModule.clientAction,
|
|
213
214
|
clientLoader: routeModule.clientLoader,
|
|
215
|
+
clientMiddleware: hasClientMiddleware ? routeModule.clientMiddleware ?? route.middleware : void 0,
|
|
214
216
|
element: route.element,
|
|
215
217
|
errorElement: route.errorElement,
|
|
216
218
|
handle: route.handle,
|
|
@@ -389,6 +391,26 @@ function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementatio
|
|
|
389
391
|
routes,
|
|
390
392
|
router
|
|
391
393
|
]);
|
|
394
|
+
React$1.useLayoutEffect(() => {
|
|
395
|
+
if (state.initialized) return;
|
|
396
|
+
let unsubscribe = () => {};
|
|
397
|
+
unsubscribe = router.subscribe((newState) => {
|
|
398
|
+
if (newState.initialized) {
|
|
399
|
+
unsubscribe();
|
|
400
|
+
React$1.startTransition(() => {
|
|
401
|
+
setState((current) => current.state.initialized ? current : {
|
|
402
|
+
...current,
|
|
403
|
+
state: newState
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
return unsubscribe;
|
|
409
|
+
}, [
|
|
410
|
+
router.subscribe,
|
|
411
|
+
router,
|
|
412
|
+
state.initialized
|
|
413
|
+
]);
|
|
392
414
|
const transitionEnabledRouter = React$1.useMemo(() => ({
|
|
393
415
|
...router,
|
|
394
416
|
state,
|
|
@@ -508,6 +530,7 @@ function createRouteFromServerManifest(match, payload) {
|
|
|
508
530
|
throw noActionDefinedError("action", match.id);
|
|
509
531
|
},
|
|
510
532
|
path: match.path,
|
|
533
|
+
middleware: match.clientMiddleware,
|
|
511
534
|
shouldRevalidate: match.shouldRevalidate,
|
|
512
535
|
hasLoader: true,
|
|
513
536
|
hasClientLoader: match.clientLoader != null,
|
|
@@ -11,6 +11,7 @@ type RSCRouteConfigEntryBase = {
|
|
|
11
11
|
action?: ActionFunction;
|
|
12
12
|
clientAction?: ClientActionFunction;
|
|
13
13
|
clientLoader?: ClientLoaderFunction;
|
|
14
|
+
clientMiddleware?: MiddlewareFunction<any>[];
|
|
14
15
|
ErrorBoundary?: React$1.ComponentType<any>;
|
|
15
16
|
handle?: any;
|
|
16
17
|
headers?: HeadersFunction;
|
|
@@ -42,6 +43,7 @@ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
|
|
|
42
43
|
type RSCRouteManifest = {
|
|
43
44
|
clientAction?: ClientActionFunction;
|
|
44
45
|
clientLoader?: ClientLoaderFunction;
|
|
46
|
+
clientMiddleware?: MiddlewareFunction<any>[];
|
|
45
47
|
element?: React$1.ReactElement | false;
|
|
46
48
|
errorElement?: React$1.ReactElement;
|
|
47
49
|
handle?: any;
|