react-router 7.18.0 → 8.0.0-pre.1
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/dist/development/dom-export.d.ts +6 -172
- package/dist/development/dom-export.js +12 -1009
- package/dist/development/index-react-server-client.d.ts +7 -4
- package/dist/development/index-react-server-client.js +8 -52
- package/dist/development/index-react-server.d.ts +1650 -1641
- package/dist/development/index-react-server.js +2882 -3664
- package/dist/development/index.d.ts +42 -1476
- package/dist/development/index.js +36 -2553
- package/dist/development/lib/actions.js +50 -0
- package/dist/development/lib/components.d.ts +1030 -0
- package/dist/development/lib/components.js +841 -0
- package/dist/development/lib/context.d.ts +83 -0
- package/dist/development/lib/context.js +41 -0
- package/dist/development/lib/dom/dom.d.ts +119 -0
- package/dist/development/lib/dom/dom.js +143 -0
- package/dist/development/lib/dom/lib.d.ts +2053 -0
- package/dist/development/lib/dom/lib.js +1271 -0
- package/dist/development/lib/dom/server.d.ts +138 -0
- package/dist/development/lib/dom/server.js +301 -0
- package/dist/development/lib/dom/ssr/components.d.ts +198 -0
- package/dist/development/lib/dom/ssr/components.js +589 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
- package/dist/development/lib/dom/ssr/fallback.js +33 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +180 -0
- package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/development/lib/dom/ssr/hydration.js +29 -0
- package/dist/development/lib/dom/ssr/invariant.js +16 -0
- package/dist/development/lib/dom/ssr/links.js +170 -0
- package/dist/development/lib/dom/ssr/markup.js +24 -0
- package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/development/lib/dom/ssr/routeModules.js +31 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/development/lib/dom/ssr/routes.js +303 -0
- package/dist/development/lib/dom/ssr/server.d.ts +48 -0
- package/dist/development/lib/dom/ssr/server.js +69 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +345 -0
- package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/development/lib/dom-export/hydrated-router.js +150 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +947 -0
- package/dist/development/lib/hooks.js +1388 -0
- package/dist/development/lib/href.d.ts +20 -0
- package/dist/development/lib/href.js +50 -0
- package/dist/development/lib/router/history.d.ts +258 -0
- package/dist/development/lib/router/history.js +372 -0
- package/dist/development/lib/router/instrumentation.d.ts +86 -0
- package/dist/development/lib/router/instrumentation.js +213 -0
- package/dist/development/lib/router/links.d.ts +114 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2988 -0
- package/dist/development/lib/router/url.js +18 -0
- package/dist/development/lib/router/utils.d.ts +948 -0
- package/dist/development/lib/router/utils.js +810 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +603 -0
- package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/development/lib/rsc/errorBoundaries.js +90 -0
- package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/development/lib/rsc/html-stream/browser.js +74 -0
- package/dist/development/lib/rsc/html-stream/server.js +78 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/development/lib/rsc/server.ssr.js +404 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.js +139 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -0
- package/dist/development/lib/server-runtime/data.d.ts +13 -0
- package/dist/development/lib/server-runtime/data.js +25 -0
- package/dist/development/lib/server-runtime/dev.d.ts +9 -0
- package/dist/development/lib/server-runtime/dev.js +26 -0
- package/dist/development/lib/server-runtime/entry.js +20 -0
- package/dist/development/lib/server-runtime/errors.js +75 -0
- package/dist/development/lib/server-runtime/headers.js +73 -0
- package/dist/development/lib/server-runtime/invariant.js +19 -0
- package/dist/development/lib/server-runtime/mode.d.ts +12 -0
- package/dist/development/lib/server-runtime/mode.js +25 -0
- package/dist/development/lib/server-runtime/routeMatching.js +28 -0
- package/dist/development/lib/server-runtime/routes.d.ts +13 -0
- package/dist/development/lib/server-runtime/routes.js +74 -0
- package/dist/development/lib/server-runtime/server.d.ts +10 -0
- package/dist/development/lib/server-runtime/server.js +345 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/development/lib/server-runtime/sessions.js +98 -0
- package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/development/lib/server-runtime/single-fetch.js +215 -0
- package/dist/development/lib/server-runtime/urls.js +28 -0
- package/dist/development/lib/server-runtime/warnings.js +20 -0
- package/dist/development/lib/types/future.d.ts +9 -0
- package/dist/development/lib/types/internal.d.ts +26 -177
- package/dist/development/lib/types/internal.js +3 -2
- package/dist/development/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
- package/dist/development/lib/types/route-data.d.ts +113 -0
- package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/development/lib/types/route-module.d.ts +19 -0
- package/dist/development/lib/types/serializes-to.d.ts +13 -0
- package/dist/development/lib/types/utils.d.ts +11 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +179 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +39 -0
- package/dist/production/dom-export.d.ts +6 -172
- package/dist/production/dom-export.js +12 -1009
- package/dist/production/index-react-server-client.d.ts +7 -4
- package/dist/production/index-react-server-client.js +8 -52
- package/dist/production/index-react-server.d.ts +1650 -1641
- package/dist/production/index-react-server.js +2873 -3664
- package/dist/production/index.d.ts +42 -1476
- package/dist/production/index.js +36 -2553
- package/dist/production/lib/actions.js +50 -0
- package/dist/production/lib/components.d.ts +1030 -0
- package/dist/production/lib/components.js +841 -0
- package/dist/production/lib/context.d.ts +83 -0
- package/dist/production/lib/context.js +41 -0
- package/dist/production/lib/dom/dom.d.ts +119 -0
- package/dist/production/lib/dom/dom.js +143 -0
- package/dist/production/lib/dom/lib.d.ts +2053 -0
- package/dist/production/lib/dom/lib.js +1271 -0
- package/dist/production/lib/dom/server.d.ts +138 -0
- package/dist/production/lib/dom/server.js +301 -0
- package/dist/production/lib/dom/ssr/components.d.ts +198 -0
- package/dist/production/lib/dom/ssr/components.js +589 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
- package/dist/production/lib/dom/ssr/fallback.js +23 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +180 -0
- package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/production/lib/dom/ssr/hydration.js +29 -0
- package/dist/production/lib/dom/ssr/invariant.js +16 -0
- package/dist/production/lib/dom/ssr/links.js +170 -0
- package/dist/production/lib/dom/ssr/markup.js +24 -0
- package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/production/lib/dom/ssr/routeModules.js +31 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/production/lib/dom/ssr/routes.js +303 -0
- package/dist/production/lib/dom/ssr/server.d.ts +48 -0
- package/dist/production/lib/dom/ssr/server.js +69 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +345 -0
- package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/production/lib/dom-export/hydrated-router.js +150 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +947 -0
- package/dist/production/lib/hooks.js +1373 -0
- package/dist/production/lib/href.d.ts +20 -0
- package/dist/production/lib/href.js +50 -0
- package/dist/production/lib/router/history.d.ts +258 -0
- package/dist/production/lib/router/history.js +372 -0
- package/dist/production/lib/router/instrumentation.d.ts +86 -0
- package/dist/production/lib/router/instrumentation.js +213 -0
- package/dist/production/lib/router/links.d.ts +114 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2988 -0
- package/dist/production/lib/router/url.js +18 -0
- package/dist/production/lib/router/utils.d.ts +948 -0
- package/dist/production/lib/router/utils.js +801 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +603 -0
- package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/production/lib/rsc/errorBoundaries.js +90 -0
- package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/production/lib/rsc/html-stream/browser.js +74 -0
- package/dist/production/lib/rsc/html-stream/server.js +78 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/production/lib/rsc/server.ssr.js +404 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.js +139 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -0
- package/dist/production/lib/server-runtime/data.d.ts +13 -0
- package/dist/production/lib/server-runtime/data.js +25 -0
- package/dist/production/lib/server-runtime/dev.d.ts +9 -0
- package/dist/production/lib/server-runtime/dev.js +26 -0
- package/dist/production/lib/server-runtime/entry.js +20 -0
- package/dist/production/lib/server-runtime/errors.js +75 -0
- package/dist/production/lib/server-runtime/headers.js +73 -0
- package/dist/production/lib/server-runtime/invariant.js +19 -0
- package/dist/production/lib/server-runtime/mode.d.ts +12 -0
- package/dist/production/lib/server-runtime/mode.js +25 -0
- package/dist/production/lib/server-runtime/routeMatching.js +28 -0
- package/dist/production/lib/server-runtime/routes.d.ts +13 -0
- package/dist/production/lib/server-runtime/routes.js +74 -0
- package/dist/production/lib/server-runtime/server.d.ts +10 -0
- package/dist/production/lib/server-runtime/server.js +345 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/production/lib/server-runtime/sessions.js +98 -0
- package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/production/lib/server-runtime/single-fetch.js +215 -0
- package/dist/production/lib/server-runtime/urls.js +28 -0
- package/dist/production/lib/server-runtime/warnings.js +20 -0
- package/dist/production/lib/types/future.d.ts +9 -0
- package/dist/production/lib/types/internal.d.ts +26 -177
- package/dist/production/lib/types/internal.js +3 -2
- package/dist/production/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
- package/dist/production/lib/types/route-data.d.ts +113 -0
- package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/production/lib/types/route-module.d.ts +19 -0
- package/dist/production/lib/types/serializes-to.d.ts +13 -0
- package/dist/production/lib/types/utils.d.ts +11 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +179 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +39 -0
- package/docs/explanation/code-splitting.md +16 -0
- package/docs/how-to/middleware.md +6 -41
- package/docs/how-to/react-server-components.md +1 -1
- package/docs/upgrading/future.md +0 -249
- package/package.json +43 -87
- package/dist/development/browser-B2PdsXXH.d.ts +0 -318
- package/dist/development/browser-DBmQ1yAR.d.mts +0 -318
- package/dist/development/chunk-4ZMWKKQ3.mjs +0 -11606
- package/dist/development/chunk-E4MTK73K.mjs +0 -2517
- package/dist/development/chunk-U7ORXROY.js +0 -10307
- package/dist/development/chunk-WW7PN6QI.js +0 -188
- package/dist/development/chunk-YL5M26XI.js +0 -1366
- package/dist/development/context-CeD5LmaF.d.mts +0 -1779
- package/dist/development/data-CjO11-hU.d.ts +0 -1740
- package/dist/development/data-DEjBmEfD.d.mts +0 -1740
- package/dist/development/dom-export.d.mts +0 -172
- package/dist/development/dom-export.mjs +0 -1010
- package/dist/development/index-react-server-client-3ykjivgQ.d.ts +0 -3677
- package/dist/development/index-react-server-client-CACgcj2J.d.mts +0 -2614
- package/dist/development/index-react-server-client.d.mts +0 -4
- package/dist/development/index-react-server-client.mjs +0 -59
- package/dist/development/index-react-server.d.mts +0 -2711
- package/dist/development/index-react-server.mjs +0 -3803
- package/dist/development/index.d.mts +0 -1479
- package/dist/development/index.mjs +0 -275
- package/dist/development/instrumentation-Dkmpzd13.d.ts +0 -715
- package/dist/development/lib/types/internal.d.mts +0 -184
- package/dist/development/lib/types/internal.mjs +0 -10
- package/dist/development/register-CmkRspdl.d.mts +0 -30
- package/dist/production/browser-B2PdsXXH.d.ts +0 -318
- package/dist/production/browser-DBmQ1yAR.d.mts +0 -318
- package/dist/production/chunk-3Z6WS2WZ.js +0 -188
- package/dist/production/chunk-BIP66BKV.js +0 -1366
- package/dist/production/chunk-EGOTSXNH.mjs +0 -2517
- package/dist/production/chunk-IUPBOWYO.js +0 -10307
- package/dist/production/chunk-M7NGGUU6.mjs +0 -11606
- package/dist/production/context-CeD5LmaF.d.mts +0 -1779
- package/dist/production/data-CjO11-hU.d.ts +0 -1740
- package/dist/production/data-DEjBmEfD.d.mts +0 -1740
- package/dist/production/dom-export.d.mts +0 -172
- package/dist/production/dom-export.mjs +0 -1010
- package/dist/production/index-react-server-client-3ykjivgQ.d.ts +0 -3677
- package/dist/production/index-react-server-client-CACgcj2J.d.mts +0 -2614
- package/dist/production/index-react-server-client.d.mts +0 -4
- package/dist/production/index-react-server-client.mjs +0 -59
- package/dist/production/index-react-server.d.mts +0 -2711
- package/dist/production/index-react-server.mjs +0 -3803
- package/dist/production/index.d.mts +0 -1479
- package/dist/production/index.mjs +0 -275
- package/dist/production/instrumentation-Dkmpzd13.d.ts +0 -715
- package/dist/production/lib/types/internal.d.mts +0 -184
- package/dist/production/lib/types/internal.mjs +0 -10
- package/dist/production/register-CmkRspdl.d.mts +0 -30
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
|
|
2
|
+
import { FormEncType, HTMLFormMethod, LoaderFunctionArgs, RouterContextProvider } from "./utils.js";
|
|
3
|
+
//#region lib/router/instrumentation.d.ts
|
|
4
|
+
type ServerInstrumentation = {
|
|
5
|
+
handler?: InstrumentRequestHandlerFunction;
|
|
6
|
+
route?: InstrumentRouteFunction;
|
|
7
|
+
};
|
|
8
|
+
type ClientInstrumentation = {
|
|
9
|
+
router?: InstrumentRouterFunction;
|
|
10
|
+
route?: InstrumentRouteFunction;
|
|
11
|
+
};
|
|
12
|
+
type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
|
|
13
|
+
type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
|
|
14
|
+
type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
|
|
15
|
+
type InstrumentationHandlerResult = {
|
|
16
|
+
status: "success";
|
|
17
|
+
error: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
status: "error";
|
|
20
|
+
error: Error;
|
|
21
|
+
};
|
|
22
|
+
type InstrumentFunction<T> = (handler: () => Promise<InstrumentationHandlerResult>, info: T) => Promise<void>;
|
|
23
|
+
type ReadonlyRequest = {
|
|
24
|
+
method: string;
|
|
25
|
+
url: string;
|
|
26
|
+
headers: Pick<Headers, "get">;
|
|
27
|
+
};
|
|
28
|
+
type ReadonlyContext = Pick<RouterContextProvider, "get">;
|
|
29
|
+
type InstrumentableRoute = {
|
|
30
|
+
id: string;
|
|
31
|
+
index: boolean | undefined;
|
|
32
|
+
path: string | undefined;
|
|
33
|
+
instrument(instrumentations: RouteInstrumentations): void;
|
|
34
|
+
};
|
|
35
|
+
type RouteInstrumentations = {
|
|
36
|
+
lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
37
|
+
"lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
38
|
+
"lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
39
|
+
"lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
40
|
+
middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
41
|
+
loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
42
|
+
action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
43
|
+
};
|
|
44
|
+
type RouteLazyInstrumentationInfo = undefined;
|
|
45
|
+
type RouteHandlerInstrumentationInfo = Readonly<{
|
|
46
|
+
request: ReadonlyRequest;
|
|
47
|
+
params: LoaderFunctionArgs["params"];
|
|
48
|
+
pattern: string;
|
|
49
|
+
context: ReadonlyContext;
|
|
50
|
+
}>;
|
|
51
|
+
type InstrumentableRouter = {
|
|
52
|
+
instrument(instrumentations: RouterInstrumentations): void;
|
|
53
|
+
};
|
|
54
|
+
type RouterInstrumentations = {
|
|
55
|
+
navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
|
|
56
|
+
fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
|
|
57
|
+
};
|
|
58
|
+
type RouterNavigationInstrumentationInfo = Readonly<{
|
|
59
|
+
to: string | number;
|
|
60
|
+
currentUrl: string;
|
|
61
|
+
formMethod?: HTMLFormMethod;
|
|
62
|
+
formEncType?: FormEncType;
|
|
63
|
+
formData?: FormData;
|
|
64
|
+
body?: any;
|
|
65
|
+
}>;
|
|
66
|
+
type RouterFetchInstrumentationInfo = Readonly<{
|
|
67
|
+
href: string;
|
|
68
|
+
currentUrl: string;
|
|
69
|
+
fetcherKey: string;
|
|
70
|
+
formMethod?: HTMLFormMethod;
|
|
71
|
+
formEncType?: FormEncType;
|
|
72
|
+
formData?: FormData;
|
|
73
|
+
body?: any;
|
|
74
|
+
}>;
|
|
75
|
+
type InstrumentableRequestHandler = {
|
|
76
|
+
instrument(instrumentations: RequestHandlerInstrumentations): void;
|
|
77
|
+
};
|
|
78
|
+
type RequestHandlerInstrumentations = {
|
|
79
|
+
request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
|
|
80
|
+
};
|
|
81
|
+
type RequestHandlerInstrumentationInfo = Readonly<{
|
|
82
|
+
request: ReadonlyRequest;
|
|
83
|
+
context: ReadonlyContext | undefined;
|
|
84
|
+
}>;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationHandlerResult, ServerInstrumentation };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.1
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { createPath, invariant } from "./history.js";
|
|
12
|
+
//#region lib/router/instrumentation.ts
|
|
13
|
+
const UninstrumentedSymbol = Symbol("Uninstrumented");
|
|
14
|
+
function getRouteInstrumentationUpdates(fns, route) {
|
|
15
|
+
let aggregated = {
|
|
16
|
+
lazy: [],
|
|
17
|
+
"lazy.loader": [],
|
|
18
|
+
"lazy.action": [],
|
|
19
|
+
"lazy.middleware": [],
|
|
20
|
+
middleware: [],
|
|
21
|
+
loader: [],
|
|
22
|
+
action: []
|
|
23
|
+
};
|
|
24
|
+
fns.forEach((fn) => fn({
|
|
25
|
+
id: route.id,
|
|
26
|
+
index: route.index,
|
|
27
|
+
path: route.path,
|
|
28
|
+
instrument(i) {
|
|
29
|
+
let keys = Object.keys(aggregated);
|
|
30
|
+
for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
let updates = {};
|
|
34
|
+
if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
|
|
35
|
+
let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
|
|
36
|
+
if (instrumented) updates.lazy = instrumented;
|
|
37
|
+
}
|
|
38
|
+
if (typeof route.lazy === "object") {
|
|
39
|
+
let lazyObject = route.lazy;
|
|
40
|
+
[
|
|
41
|
+
"middleware",
|
|
42
|
+
"loader",
|
|
43
|
+
"action"
|
|
44
|
+
].forEach((key) => {
|
|
45
|
+
let lazyFn = lazyObject[key];
|
|
46
|
+
let instrumentations = aggregated[`lazy.${key}`];
|
|
47
|
+
if (typeof lazyFn === "function" && instrumentations.length > 0) {
|
|
48
|
+
let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
|
|
49
|
+
if (instrumented) updates.lazy = Object.assign(updates.lazy || {}, { [key]: instrumented });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
["loader", "action"].forEach((key) => {
|
|
54
|
+
let handler = route[key];
|
|
55
|
+
if (typeof handler === "function" && aggregated[key].length > 0) {
|
|
56
|
+
let original = handler[UninstrumentedSymbol] ?? handler;
|
|
57
|
+
let instrumented = wrapImpl(aggregated[key], original, (...args) => getHandlerInfo(args[0]));
|
|
58
|
+
if (instrumented) {
|
|
59
|
+
if (key === "loader" && original.hydrate === true) instrumented.hydrate = true;
|
|
60
|
+
instrumented[UninstrumentedSymbol] = original;
|
|
61
|
+
updates[key] = instrumented;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) updates.middleware = route.middleware.map((middleware) => {
|
|
66
|
+
let original = middleware[UninstrumentedSymbol] ?? middleware;
|
|
67
|
+
let instrumented = wrapImpl(aggregated.middleware, original, (...args) => getHandlerInfo(args[0]));
|
|
68
|
+
if (instrumented) {
|
|
69
|
+
instrumented[UninstrumentedSymbol] = original;
|
|
70
|
+
return instrumented;
|
|
71
|
+
}
|
|
72
|
+
return middleware;
|
|
73
|
+
});
|
|
74
|
+
return updates;
|
|
75
|
+
}
|
|
76
|
+
function instrumentClientSideRouter(router, fns) {
|
|
77
|
+
let aggregated = {
|
|
78
|
+
navigate: [],
|
|
79
|
+
fetch: []
|
|
80
|
+
};
|
|
81
|
+
fns.forEach((fn) => fn({ instrument(i) {
|
|
82
|
+
let keys = Object.keys(i);
|
|
83
|
+
for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
|
|
84
|
+
} }));
|
|
85
|
+
if (aggregated.navigate.length > 0) {
|
|
86
|
+
let navigate = router.navigate[UninstrumentedSymbol] ?? router.navigate;
|
|
87
|
+
let instrumentedNavigate = wrapImpl(aggregated.navigate, navigate, (...args) => {
|
|
88
|
+
let [to, opts] = args;
|
|
89
|
+
return {
|
|
90
|
+
to: typeof to === "number" || typeof to === "string" ? to : to ? createPath(to) : ".",
|
|
91
|
+
...getRouterInfo(router, opts ?? {})
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
if (instrumentedNavigate) {
|
|
95
|
+
instrumentedNavigate[UninstrumentedSymbol] = navigate;
|
|
96
|
+
router.navigate = instrumentedNavigate;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (aggregated.fetch.length > 0) {
|
|
100
|
+
let fetch = router.fetch[UninstrumentedSymbol] ?? router.fetch;
|
|
101
|
+
let instrumentedFetch = wrapImpl(aggregated.fetch, fetch, (...args) => {
|
|
102
|
+
let [key, , href, opts] = args;
|
|
103
|
+
return {
|
|
104
|
+
href: href ?? ".",
|
|
105
|
+
fetcherKey: key,
|
|
106
|
+
...getRouterInfo(router, opts ?? {})
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
if (instrumentedFetch) {
|
|
110
|
+
instrumentedFetch[UninstrumentedSymbol] = fetch;
|
|
111
|
+
router.fetch = instrumentedFetch;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return router;
|
|
115
|
+
}
|
|
116
|
+
function instrumentHandler(handler, fns) {
|
|
117
|
+
let aggregated = { request: [] };
|
|
118
|
+
fns.forEach((fn) => fn({ instrument(i) {
|
|
119
|
+
let keys = Object.keys(i);
|
|
120
|
+
for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
|
|
121
|
+
} }));
|
|
122
|
+
let instrumentedHandler = handler;
|
|
123
|
+
if (aggregated.request.length > 0) instrumentedHandler = wrapImpl(aggregated.request, handler, (...args) => {
|
|
124
|
+
let [request, context] = args;
|
|
125
|
+
return {
|
|
126
|
+
request: getReadonlyRequest(request),
|
|
127
|
+
context: context != null ? getReadonlyContext(context) : context
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
return instrumentedHandler;
|
|
131
|
+
}
|
|
132
|
+
function wrapImpl(impls, handler, getInfo) {
|
|
133
|
+
if (impls.length === 0) return null;
|
|
134
|
+
return async (...args) => {
|
|
135
|
+
let result = await recurseRight(impls, getInfo(...args), () => handler(...args), impls.length - 1);
|
|
136
|
+
if (result.type === "error") throw result.value;
|
|
137
|
+
return result.value;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async function recurseRight(impls, info, handler, index) {
|
|
141
|
+
let impl = impls[index];
|
|
142
|
+
let result;
|
|
143
|
+
if (!impl) try {
|
|
144
|
+
result = {
|
|
145
|
+
type: "success",
|
|
146
|
+
value: await handler()
|
|
147
|
+
};
|
|
148
|
+
} catch (e) {
|
|
149
|
+
result = {
|
|
150
|
+
type: "error",
|
|
151
|
+
value: e
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
let handlerPromise = void 0;
|
|
156
|
+
let callHandler = async () => {
|
|
157
|
+
if (handlerPromise) console.error("You cannot call instrumented handlers more than once");
|
|
158
|
+
else handlerPromise = recurseRight(impls, info, handler, index - 1);
|
|
159
|
+
result = await handlerPromise;
|
|
160
|
+
invariant(result, "Expected a result");
|
|
161
|
+
if (result.type === "error" && result.value instanceof Error) return {
|
|
162
|
+
status: "error",
|
|
163
|
+
error: result.value
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
status: "success",
|
|
167
|
+
error: void 0
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
try {
|
|
171
|
+
await impl(callHandler, info);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
console.error("An instrumentation function threw an error:", e);
|
|
174
|
+
}
|
|
175
|
+
if (!handlerPromise) await callHandler();
|
|
176
|
+
await handlerPromise;
|
|
177
|
+
}
|
|
178
|
+
if (result) return result;
|
|
179
|
+
return {
|
|
180
|
+
type: "error",
|
|
181
|
+
value: /* @__PURE__ */ new Error("No result assigned in instrumentation chain.")
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function getHandlerInfo(args) {
|
|
185
|
+
let { request, context, params, pattern } = args;
|
|
186
|
+
return {
|
|
187
|
+
request: getReadonlyRequest(request),
|
|
188
|
+
params: { ...params },
|
|
189
|
+
pattern,
|
|
190
|
+
context: getReadonlyContext(context)
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function getRouterInfo(router, opts) {
|
|
194
|
+
return {
|
|
195
|
+
currentUrl: createPath(router.state.location),
|
|
196
|
+
..."formMethod" in opts ? { formMethod: opts.formMethod } : {},
|
|
197
|
+
..."formEncType" in opts ? { formEncType: opts.formEncType } : {},
|
|
198
|
+
..."formData" in opts ? { formData: opts.formData } : {},
|
|
199
|
+
..."body" in opts ? { body: opts.body } : {}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function getReadonlyRequest(request) {
|
|
203
|
+
return {
|
|
204
|
+
method: request.method,
|
|
205
|
+
url: request.url,
|
|
206
|
+
headers: { get: (...args) => request.headers.get(...args) }
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function getReadonlyContext(context) {
|
|
210
|
+
return { get: (ctx) => context.get(ctx) };
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
export { getRouteInstrumentationUpdates, instrumentClientSideRouter, instrumentHandler };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
//#region lib/router/links.d.ts
|
|
3
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
4
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
5
|
+
interface HtmlLinkProps {
|
|
6
|
+
/**
|
|
7
|
+
* Address of the hyperlink
|
|
8
|
+
*/
|
|
9
|
+
href?: string;
|
|
10
|
+
/**
|
|
11
|
+
* How the element handles crossorigin requests
|
|
12
|
+
*/
|
|
13
|
+
crossOrigin?: "anonymous" | "use-credentials";
|
|
14
|
+
/**
|
|
15
|
+
* Relationship between the document containing the hyperlink and the destination resource
|
|
16
|
+
*/
|
|
17
|
+
rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
|
|
18
|
+
/**
|
|
19
|
+
* Applicable media: "screen", "print", "(max-width: 764px)"
|
|
20
|
+
*/
|
|
21
|
+
media?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Integrity metadata used in Subresource Integrity checks
|
|
24
|
+
*/
|
|
25
|
+
integrity?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Language of the linked resource
|
|
28
|
+
*/
|
|
29
|
+
hrefLang?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Hint for the type of the referenced resource
|
|
32
|
+
*/
|
|
33
|
+
type?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Referrer policy for fetches initiated by the element
|
|
36
|
+
*/
|
|
37
|
+
referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
|
|
38
|
+
/**
|
|
39
|
+
* Sizes of the icons (for rel="icon")
|
|
40
|
+
*/
|
|
41
|
+
sizes?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Potential destination for a preload request (for rel="preload" and rel="modulepreload")
|
|
44
|
+
*/
|
|
45
|
+
as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
|
|
46
|
+
/**
|
|
47
|
+
* Color to use when customizing a site's icon (for rel="mask-icon")
|
|
48
|
+
*/
|
|
49
|
+
color?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the link is disabled
|
|
52
|
+
*/
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
|
|
56
|
+
*/
|
|
57
|
+
title?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Images to use in different situations, e.g., high-resolution displays,
|
|
60
|
+
* small monitors, etc. (for rel="preload")
|
|
61
|
+
*/
|
|
62
|
+
imageSrcSet?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Image sizes for different page layouts (for rel="preload")
|
|
65
|
+
*/
|
|
66
|
+
imageSizes?: string;
|
|
67
|
+
}
|
|
68
|
+
interface HtmlLinkPreloadImage extends HtmlLinkProps {
|
|
69
|
+
/**
|
|
70
|
+
* Relationship between the document containing the hyperlink and the destination resource
|
|
71
|
+
*/
|
|
72
|
+
rel: "preload";
|
|
73
|
+
/**
|
|
74
|
+
* Potential destination for a preload request (for rel="preload" and rel="modulepreload")
|
|
75
|
+
*/
|
|
76
|
+
as: "image";
|
|
77
|
+
/**
|
|
78
|
+
* Address of the hyperlink
|
|
79
|
+
*/
|
|
80
|
+
href?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Images to use in different situations, e.g., high-resolution displays,
|
|
83
|
+
* small monitors, etc. (for rel="preload")
|
|
84
|
+
*/
|
|
85
|
+
imageSrcSet: string;
|
|
86
|
+
/**
|
|
87
|
+
* Image sizes for different page layouts (for rel="preload")
|
|
88
|
+
*/
|
|
89
|
+
imageSizes?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents a `<link>` element.
|
|
93
|
+
*
|
|
94
|
+
* WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
|
|
95
|
+
*/
|
|
96
|
+
type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
|
|
97
|
+
imageSizes?: never;
|
|
98
|
+
});
|
|
99
|
+
interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
|
|
100
|
+
/**
|
|
101
|
+
* A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
|
102
|
+
* attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
103
|
+
* element. If not provided in Framework Mode, it will default to any
|
|
104
|
+
* {@link ServerRouter | `<ServerRouter nonce>`} prop.
|
|
105
|
+
*/
|
|
106
|
+
nonce?: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* The absolute path of the page to prefetch, e.g. `/absolute/path`.
|
|
109
|
+
*/
|
|
110
|
+
page: string;
|
|
111
|
+
}
|
|
112
|
+
type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { HtmlLinkDescriptor, LinkDescriptor, PageLinkDescriptor };
|