react-router 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- 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 +32 -7
- package/dist/development/index-react-server.js +180 -152
- package/dist/development/index.d.ts +2 -3
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/components.js +1 -1
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.js +1 -1
- package/dist/development/lib/dom/lib.js +2 -2
- 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.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/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.js +1 -1
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.js +1 -1
- package/dist/development/lib/href.js +1 -1
- package/dist/development/lib/router/history.js +1 -1
- package/dist/development/lib/router/instrumentation.d.ts +33 -8
- package/dist/development/lib/router/instrumentation.js +176 -99
- package/dist/development/lib/router/router.js +19 -19
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.js +17 -2
- package/dist/development/lib/rsc/browser.js +3 -4
- 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.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 +12 -5
- 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/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
- 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 +32 -7
- package/dist/production/index-react-server.js +180 -152
- package/dist/production/index.d.ts +2 -3
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/components.js +1 -1
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.js +1 -1
- package/dist/production/lib/dom/lib.js +2 -2
- 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.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/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.js +1 -1
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.js +1 -1
- package/dist/production/lib/href.js +1 -1
- package/dist/production/lib/router/history.js +1 -1
- package/dist/production/lib/router/instrumentation.d.ts +33 -8
- package/dist/production/lib/router/instrumentation.js +176 -99
- package/dist/production/lib/router/router.js +19 -19
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.js +17 -2
- package/dist/production/lib/rsc/browser.js +3 -4
- 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.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 +12 -5
- 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/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/how-to/instrumentation.md +131 -26
- package/docs/how-to/middleware.md +1 -1
- package/docs/how-to/route-module-type-safety.md +1 -16
- package/docs/upgrading/component-routes.md +1 -1
- package/docs/upgrading/router-provider.md +1 -1
- package/package.json +1 -1
- package/dist/development/lib/server-runtime/data.d.ts +0 -13
- package/dist/production/lib/server-runtime/data.d.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# `react-router`
|
|
2
2
|
|
|
3
|
+
## v8.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Return route metadata from server request, client navigation, and client fetcher instrumentations ([#15235](https://github.com/remix-run/react-router/pull/15235))
|
|
8
|
+
- Adds result metadata after instrumented calls complete, including the URL, matched route pattern, and params
|
|
9
|
+
- Adds known HTTP status codes to server request handler instrumentation results
|
|
10
|
+
|
|
11
|
+
## v8.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Remove the obsolete `AppLoadContext` type export accidentally left over from v7 now that middleware is always enabled and server request context is provided through `RouterContextProvider`. ([#15207](https://github.com/remix-run/react-router/pull/15207))
|
|
16
|
+
|
|
3
17
|
## v8.0.0
|
|
4
18
|
|
|
5
19
|
### Major Changes
|
|
@@ -1009,6 +1009,19 @@ type ClientInstrumentation = {
|
|
|
1009
1009
|
type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
|
|
1010
1010
|
type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
|
|
1011
1011
|
type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
|
|
1012
|
+
/**
|
|
1013
|
+
* Route metadata available after React Router has matched an instrumented
|
|
1014
|
+
* request, navigation, or fetcher call.
|
|
1015
|
+
*/
|
|
1016
|
+
type InstrumentationResultMeta = {
|
|
1017
|
+
url: LoaderFunctionArgs["url"];
|
|
1018
|
+
pattern: string;
|
|
1019
|
+
params: LoaderFunctionArgs["params"];
|
|
1020
|
+
};
|
|
1021
|
+
/**
|
|
1022
|
+
* Result returned by route-level instrumented handler calls, such as
|
|
1023
|
+
* instrumented loaders, actions, middleware, and lazy route functions.
|
|
1024
|
+
*/
|
|
1012
1025
|
type InstrumentationHandlerResult = {
|
|
1013
1026
|
status: "success";
|
|
1014
1027
|
error: undefined;
|
|
@@ -1016,7 +1029,21 @@ type InstrumentationHandlerResult = {
|
|
|
1016
1029
|
status: "error";
|
|
1017
1030
|
error: Error;
|
|
1018
1031
|
};
|
|
1019
|
-
|
|
1032
|
+
/**
|
|
1033
|
+
* Result returned by client-side router instrumented navigation and fetcher
|
|
1034
|
+
* calls.
|
|
1035
|
+
*/
|
|
1036
|
+
type InstrumentationClientRouterResult = InstrumentationHandlerResult & {
|
|
1037
|
+
meta: InstrumentationResultMeta | undefined;
|
|
1038
|
+
};
|
|
1039
|
+
/**
|
|
1040
|
+
* Result returned by server request handler instrumentation.
|
|
1041
|
+
*/
|
|
1042
|
+
type InstrumentationServerHandlerResult = InstrumentationHandlerResult & {
|
|
1043
|
+
statusCode: number;
|
|
1044
|
+
meta: InstrumentationResultMeta | undefined;
|
|
1045
|
+
};
|
|
1046
|
+
type InstrumentFunction<T, TInnerResult = InstrumentationHandlerResult> = (handler: () => Promise<TInnerResult>, info: T) => Promise<void>;
|
|
1020
1047
|
type ReadonlyRequest = {
|
|
1021
1048
|
method: string;
|
|
1022
1049
|
url: string;
|
|
@@ -1039,18 +1066,16 @@ type RouteInstrumentations = {
|
|
|
1039
1066
|
action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
1040
1067
|
};
|
|
1041
1068
|
type RouteLazyInstrumentationInfo = undefined;
|
|
1042
|
-
type RouteHandlerInstrumentationInfo = Readonly<{
|
|
1069
|
+
type RouteHandlerInstrumentationInfo = Readonly<Omit<LoaderFunctionArgs, "request" | "context"> & {
|
|
1043
1070
|
request: ReadonlyRequest;
|
|
1044
|
-
params: LoaderFunctionArgs["params"];
|
|
1045
|
-
pattern: string;
|
|
1046
1071
|
context: ReadonlyContext;
|
|
1047
1072
|
}>;
|
|
1048
1073
|
type InstrumentableRouter = {
|
|
1049
1074
|
instrument(instrumentations: RouterInstrumentations): void;
|
|
1050
1075
|
};
|
|
1051
1076
|
type RouterInstrumentations = {
|
|
1052
|
-
navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
|
|
1053
|
-
fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
|
|
1077
|
+
navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo, InstrumentationClientRouterResult>;
|
|
1078
|
+
fetch?: InstrumentFunction<RouterFetchInstrumentationInfo, InstrumentationClientRouterResult>;
|
|
1054
1079
|
};
|
|
1055
1080
|
type RouterNavigationInstrumentationInfo = Readonly<{
|
|
1056
1081
|
to: string | number;
|
|
@@ -1073,7 +1098,7 @@ type InstrumentableRequestHandler = {
|
|
|
1073
1098
|
instrument(instrumentations: RequestHandlerInstrumentations): void;
|
|
1074
1099
|
};
|
|
1075
1100
|
type RequestHandlerInstrumentations = {
|
|
1076
|
-
request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
|
|
1101
|
+
request?: InstrumentFunction<RequestHandlerInstrumentationInfo, InstrumentationServerHandlerResult>;
|
|
1077
1102
|
};
|
|
1078
1103
|
type RequestHandlerInstrumentationInfo = Readonly<{
|
|
1079
1104
|
request: ReadonlyRequest;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.1.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -77,142 +77,6 @@ function parsePath(path) {
|
|
|
77
77
|
return parsedPath;
|
|
78
78
|
}
|
|
79
79
|
//#endregion
|
|
80
|
-
//#region lib/router/instrumentation.ts
|
|
81
|
-
const UninstrumentedSymbol = Symbol("Uninstrumented");
|
|
82
|
-
function getRouteInstrumentationUpdates(fns, route) {
|
|
83
|
-
let aggregated = {
|
|
84
|
-
lazy: [],
|
|
85
|
-
"lazy.loader": [],
|
|
86
|
-
"lazy.action": [],
|
|
87
|
-
"lazy.middleware": [],
|
|
88
|
-
middleware: [],
|
|
89
|
-
loader: [],
|
|
90
|
-
action: []
|
|
91
|
-
};
|
|
92
|
-
fns.forEach((fn) => fn({
|
|
93
|
-
id: route.id,
|
|
94
|
-
index: route.index,
|
|
95
|
-
path: route.path,
|
|
96
|
-
instrument(i) {
|
|
97
|
-
let keys = Object.keys(aggregated);
|
|
98
|
-
for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
|
|
99
|
-
}
|
|
100
|
-
}));
|
|
101
|
-
let updates = {};
|
|
102
|
-
if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
|
|
103
|
-
let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
|
|
104
|
-
if (instrumented) updates.lazy = instrumented;
|
|
105
|
-
}
|
|
106
|
-
if (typeof route.lazy === "object") {
|
|
107
|
-
let lazyObject = route.lazy;
|
|
108
|
-
[
|
|
109
|
-
"middleware",
|
|
110
|
-
"loader",
|
|
111
|
-
"action"
|
|
112
|
-
].forEach((key) => {
|
|
113
|
-
let lazyFn = lazyObject[key];
|
|
114
|
-
let instrumentations = aggregated[`lazy.${key}`];
|
|
115
|
-
if (typeof lazyFn === "function" && instrumentations.length > 0) {
|
|
116
|
-
let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
|
|
117
|
-
if (instrumented) updates.lazy = Object.assign(updates.lazy || {}, { [key]: instrumented });
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
["loader", "action"].forEach((key) => {
|
|
122
|
-
let handler = route[key];
|
|
123
|
-
if (typeof handler === "function" && aggregated[key].length > 0) {
|
|
124
|
-
let original = handler[UninstrumentedSymbol] ?? handler;
|
|
125
|
-
let instrumented = wrapImpl(aggregated[key], original, (...args) => getHandlerInfo(args[0]));
|
|
126
|
-
if (instrumented) {
|
|
127
|
-
if (key === "loader" && original.hydrate === true) instrumented.hydrate = true;
|
|
128
|
-
instrumented[UninstrumentedSymbol] = original;
|
|
129
|
-
updates[key] = instrumented;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) updates.middleware = route.middleware.map((middleware) => {
|
|
134
|
-
let original = middleware[UninstrumentedSymbol] ?? middleware;
|
|
135
|
-
let instrumented = wrapImpl(aggregated.middleware, original, (...args) => getHandlerInfo(args[0]));
|
|
136
|
-
if (instrumented) {
|
|
137
|
-
instrumented[UninstrumentedSymbol] = original;
|
|
138
|
-
return instrumented;
|
|
139
|
-
}
|
|
140
|
-
return middleware;
|
|
141
|
-
});
|
|
142
|
-
return updates;
|
|
143
|
-
}
|
|
144
|
-
function wrapImpl(impls, handler, getInfo) {
|
|
145
|
-
if (impls.length === 0) return null;
|
|
146
|
-
return async (...args) => {
|
|
147
|
-
let result = await recurseRight(impls, getInfo(...args), () => handler(...args), impls.length - 1);
|
|
148
|
-
if (result.type === "error") throw result.value;
|
|
149
|
-
return result.value;
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
async function recurseRight(impls, info, handler, index) {
|
|
153
|
-
let impl = impls[index];
|
|
154
|
-
let result;
|
|
155
|
-
if (!impl) try {
|
|
156
|
-
result = {
|
|
157
|
-
type: "success",
|
|
158
|
-
value: await handler()
|
|
159
|
-
};
|
|
160
|
-
} catch (e) {
|
|
161
|
-
result = {
|
|
162
|
-
type: "error",
|
|
163
|
-
value: e
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
let handlerPromise = void 0;
|
|
168
|
-
let callHandler = async () => {
|
|
169
|
-
if (handlerPromise) console.error("You cannot call instrumented handlers more than once");
|
|
170
|
-
else handlerPromise = recurseRight(impls, info, handler, index - 1);
|
|
171
|
-
result = await handlerPromise;
|
|
172
|
-
invariant$1(result, "Expected a result");
|
|
173
|
-
if (result.type === "error" && result.value instanceof Error) return {
|
|
174
|
-
status: "error",
|
|
175
|
-
error: result.value
|
|
176
|
-
};
|
|
177
|
-
return {
|
|
178
|
-
status: "success",
|
|
179
|
-
error: void 0
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
try {
|
|
183
|
-
await impl(callHandler, info);
|
|
184
|
-
} catch (e) {
|
|
185
|
-
console.error("An instrumentation function threw an error:", e);
|
|
186
|
-
}
|
|
187
|
-
if (!handlerPromise) await callHandler();
|
|
188
|
-
await handlerPromise;
|
|
189
|
-
}
|
|
190
|
-
if (result) return result;
|
|
191
|
-
return {
|
|
192
|
-
type: "error",
|
|
193
|
-
value: /* @__PURE__ */ new Error("No result assigned in instrumentation chain.")
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function getHandlerInfo(args) {
|
|
197
|
-
let { request, context, params, pattern } = args;
|
|
198
|
-
return {
|
|
199
|
-
request: getReadonlyRequest(request),
|
|
200
|
-
params: { ...params },
|
|
201
|
-
pattern,
|
|
202
|
-
context: getReadonlyContext(context)
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
function getReadonlyRequest(request) {
|
|
206
|
-
return {
|
|
207
|
-
method: request.method,
|
|
208
|
-
url: request.url,
|
|
209
|
-
headers: { get: (...args) => request.headers.get(...args) }
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function getReadonlyContext(context) {
|
|
213
|
-
return { get: (ctx) => context.get(ctx) };
|
|
214
|
-
}
|
|
215
|
-
//#endregion
|
|
216
80
|
//#region lib/router/utils.ts
|
|
217
81
|
/**
|
|
218
82
|
* Creates a type-safe {@link RouterContext} object that can be used to
|
|
@@ -941,8 +805,187 @@ function isRouteErrorResponse(error) {
|
|
|
941
805
|
function getRoutePattern(matches) {
|
|
942
806
|
return joinPaths(matches.map((m) => m.route.path).filter(Boolean)) || "/";
|
|
943
807
|
}
|
|
808
|
+
function createDataFunctionUrl(request, path) {
|
|
809
|
+
let url = new URL(typeof request === "string" || request instanceof URL ? request : request.url);
|
|
810
|
+
let parsed = typeof path === "string" ? parsePath(path) : path;
|
|
811
|
+
url.pathname = parsed.pathname || "/";
|
|
812
|
+
if (parsed.search) {
|
|
813
|
+
let searchParams = new URLSearchParams(parsed.search);
|
|
814
|
+
let indexValues = searchParams.getAll("index");
|
|
815
|
+
searchParams.delete("index");
|
|
816
|
+
for (let value of indexValues.filter(Boolean)) searchParams.append("index", value);
|
|
817
|
+
let search = searchParams.toString();
|
|
818
|
+
url.search = search ? `?${search}` : "";
|
|
819
|
+
} else url.search = "";
|
|
820
|
+
url.hash = parsed.hash || "";
|
|
821
|
+
return url;
|
|
822
|
+
}
|
|
944
823
|
typeof window !== "undefined" && typeof window.document !== "undefined" && window.document.createElement;
|
|
945
824
|
//#endregion
|
|
825
|
+
//#region lib/router/instrumentation.ts
|
|
826
|
+
const UninstrumentedSymbol = Symbol("Uninstrumented");
|
|
827
|
+
function getRouteInstrumentationUpdates(fns, route) {
|
|
828
|
+
let aggregated = {
|
|
829
|
+
lazy: [],
|
|
830
|
+
"lazy.loader": [],
|
|
831
|
+
"lazy.action": [],
|
|
832
|
+
"lazy.middleware": [],
|
|
833
|
+
middleware: [],
|
|
834
|
+
loader: [],
|
|
835
|
+
action: []
|
|
836
|
+
};
|
|
837
|
+
fns.forEach((fn) => fn({
|
|
838
|
+
id: route.id,
|
|
839
|
+
index: route.index,
|
|
840
|
+
path: route.path,
|
|
841
|
+
instrument(i) {
|
|
842
|
+
if (i.lazy != null) aggregated.lazy.push(i.lazy);
|
|
843
|
+
if (i["lazy.loader"] != null) aggregated["lazy.loader"].push(i["lazy.loader"]);
|
|
844
|
+
if (i["lazy.action"] != null) aggregated["lazy.action"].push(i["lazy.action"]);
|
|
845
|
+
if (i["lazy.middleware"] != null) aggregated["lazy.middleware"].push(i["lazy.middleware"]);
|
|
846
|
+
if (i.middleware != null) aggregated.middleware.push(i.middleware);
|
|
847
|
+
if (i.loader != null) aggregated.loader.push(i.loader);
|
|
848
|
+
if (i.action != null) aggregated.action.push(i.action);
|
|
849
|
+
}
|
|
850
|
+
}));
|
|
851
|
+
let updates = {};
|
|
852
|
+
if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
|
|
853
|
+
let lazy = route.lazy;
|
|
854
|
+
updates.lazy = async (...args) => {
|
|
855
|
+
return throwOrReturnResult(await recurseRight(aggregated.lazy, void 0, () => lazy(...args), getInstrumentationInnerResult));
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
if (typeof route.lazy === "object") {
|
|
859
|
+
let lazyObject = route.lazy;
|
|
860
|
+
if (typeof lazyObject.middleware === "function" && aggregated["lazy.middleware"].length > 0) {
|
|
861
|
+
let middleware = lazyObject.middleware;
|
|
862
|
+
updates.lazy = Object.assign(updates.lazy || {}, { middleware: async (...args) => {
|
|
863
|
+
return throwOrReturnResult(await recurseRight(aggregated["lazy.middleware"], void 0, () => middleware(...args), getInstrumentationInnerResult));
|
|
864
|
+
} });
|
|
865
|
+
}
|
|
866
|
+
if (typeof lazyObject.loader === "function" && aggregated["lazy.loader"].length > 0) {
|
|
867
|
+
let loader = lazyObject.loader;
|
|
868
|
+
updates.lazy = Object.assign(updates.lazy || {}, { loader: async (...args) => {
|
|
869
|
+
return throwOrReturnResult(await recurseRight(aggregated["lazy.loader"], void 0, () => loader(...args), getInstrumentationInnerResult));
|
|
870
|
+
} });
|
|
871
|
+
}
|
|
872
|
+
if (typeof lazyObject.action === "function" && aggregated["lazy.action"].length > 0) {
|
|
873
|
+
let action = lazyObject.action;
|
|
874
|
+
updates.lazy = Object.assign(updates.lazy || {}, { action: async (...args) => {
|
|
875
|
+
return throwOrReturnResult(await recurseRight(aggregated["lazy.action"], void 0, () => action(...args), getInstrumentationInnerResult));
|
|
876
|
+
} });
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
if (typeof route.loader === "function" && aggregated.loader.length > 0) {
|
|
880
|
+
let original = getUninstrumentedHandler(route.loader);
|
|
881
|
+
let instrumented = async (...args) => {
|
|
882
|
+
return throwOrReturnResult(await recurseRight(aggregated.loader, getHandlerInfo(args[0]), () => original(...args), getInstrumentationInnerResult));
|
|
883
|
+
};
|
|
884
|
+
if (original.hydrate === true) instrumented.hydrate = true;
|
|
885
|
+
setUninstrumentedHandler(instrumented, original);
|
|
886
|
+
updates.loader = instrumented;
|
|
887
|
+
}
|
|
888
|
+
if (typeof route.action === "function" && aggregated.action.length > 0) {
|
|
889
|
+
let original = getUninstrumentedHandler(route.action);
|
|
890
|
+
let instrumented = async (...args) => {
|
|
891
|
+
return throwOrReturnResult(await recurseRight(aggregated.action, getHandlerInfo(args[0]), () => original(...args), getInstrumentationInnerResult));
|
|
892
|
+
};
|
|
893
|
+
setUninstrumentedHandler(instrumented, original);
|
|
894
|
+
updates.action = instrumented;
|
|
895
|
+
}
|
|
896
|
+
if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) updates.middleware = route.middleware.map((middleware) => {
|
|
897
|
+
let original = getUninstrumentedHandler(middleware);
|
|
898
|
+
let instrumented = async (...args) => {
|
|
899
|
+
return throwOrReturnResult(await recurseRight(aggregated.middleware, getHandlerInfo(args[0]), () => original(...args), getInstrumentationInnerResult));
|
|
900
|
+
};
|
|
901
|
+
setUninstrumentedHandler(instrumented, original);
|
|
902
|
+
return instrumented;
|
|
903
|
+
});
|
|
904
|
+
return updates;
|
|
905
|
+
}
|
|
906
|
+
function getUninstrumentedHandler(handler) {
|
|
907
|
+
return handler[UninstrumentedSymbol] ?? handler;
|
|
908
|
+
}
|
|
909
|
+
function setUninstrumentedHandler(handler, uninstrumentedHandler) {
|
|
910
|
+
handler[UninstrumentedSymbol] = uninstrumentedHandler;
|
|
911
|
+
}
|
|
912
|
+
function throwOrReturnResult(result) {
|
|
913
|
+
if (result.type === "error") throw result.value;
|
|
914
|
+
return result.value;
|
|
915
|
+
}
|
|
916
|
+
async function recurseRight(impls, info, handler, getInnerResult, state = {
|
|
917
|
+
result: null,
|
|
918
|
+
innerResult: null
|
|
919
|
+
}, index = impls.length - 1) {
|
|
920
|
+
let impl = impls[index];
|
|
921
|
+
if (!impl) {
|
|
922
|
+
try {
|
|
923
|
+
state.result = {
|
|
924
|
+
type: "success",
|
|
925
|
+
value: await handler()
|
|
926
|
+
};
|
|
927
|
+
} catch (e) {
|
|
928
|
+
state.result = {
|
|
929
|
+
type: "error",
|
|
930
|
+
value: e
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
state.innerResult = getInnerResult(state.result, info);
|
|
934
|
+
} else {
|
|
935
|
+
let handlerPromise = void 0;
|
|
936
|
+
let callHandler = async () => {
|
|
937
|
+
if (handlerPromise) console.error("You cannot call instrumented handlers more than once");
|
|
938
|
+
else handlerPromise = recurseRight(impls, info, handler, getInnerResult, state, index - 1);
|
|
939
|
+
await handlerPromise;
|
|
940
|
+
invariant$1(state.innerResult, "Expected an inner result");
|
|
941
|
+
return state.innerResult;
|
|
942
|
+
};
|
|
943
|
+
try {
|
|
944
|
+
await impl(callHandler, info);
|
|
945
|
+
} catch (e) {
|
|
946
|
+
console.error("An instrumentation function threw an error:", e);
|
|
947
|
+
}
|
|
948
|
+
if (!handlerPromise) await callHandler();
|
|
949
|
+
await handlerPromise;
|
|
950
|
+
}
|
|
951
|
+
if (state.result) return state.result;
|
|
952
|
+
state.result = {
|
|
953
|
+
type: "error",
|
|
954
|
+
value: /* @__PURE__ */ new Error("No result assigned in instrumentation chain.")
|
|
955
|
+
};
|
|
956
|
+
state.innerResult = getInnerResult(state.result, info);
|
|
957
|
+
return state.result;
|
|
958
|
+
}
|
|
959
|
+
function getInstrumentationInnerResult(result) {
|
|
960
|
+
if (result.type === "error" && result.value instanceof Error) return {
|
|
961
|
+
status: "error",
|
|
962
|
+
error: result.value
|
|
963
|
+
};
|
|
964
|
+
return {
|
|
965
|
+
status: "success",
|
|
966
|
+
error: void 0
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
function getHandlerInfo(args) {
|
|
970
|
+
let { request, context, params } = args;
|
|
971
|
+
return {
|
|
972
|
+
...args,
|
|
973
|
+
request: getReadonlyRequest(request),
|
|
974
|
+
params: { ...params },
|
|
975
|
+
context: getReadonlyContext(context)
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
function getReadonlyRequest(request) {
|
|
979
|
+
return {
|
|
980
|
+
method: request.method,
|
|
981
|
+
url: request.url,
|
|
982
|
+
headers: { get: (...args) => request.headers.get(...args) }
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function getReadonlyContext(context) {
|
|
986
|
+
return { get: (ctx) => context.get(ctx) };
|
|
987
|
+
}
|
|
988
|
+
//#endregion
|
|
946
989
|
//#region lib/router/router.ts
|
|
947
990
|
const validMutationMethodsArr = [
|
|
948
991
|
"POST",
|
|
@@ -1877,21 +1920,6 @@ function normalizeRelativeRoutingRedirectResponse(response, request, routeId, ma
|
|
|
1877
1920
|
}
|
|
1878
1921
|
return response;
|
|
1879
1922
|
}
|
|
1880
|
-
function createDataFunctionUrl(request, path) {
|
|
1881
|
-
let url = new URL(request.url);
|
|
1882
|
-
let parsed = typeof path === "string" ? parsePath(path) : path;
|
|
1883
|
-
url.pathname = parsed.pathname || "/";
|
|
1884
|
-
if (parsed.search) {
|
|
1885
|
-
let searchParams = new URLSearchParams(parsed.search);
|
|
1886
|
-
let indexValues = searchParams.getAll("index");
|
|
1887
|
-
searchParams.delete("index");
|
|
1888
|
-
for (let value of indexValues.filter(Boolean)) searchParams.append("index", value);
|
|
1889
|
-
let search = searchParams.toString();
|
|
1890
|
-
url.search = search ? `?${search}` : "";
|
|
1891
|
-
} else url.search = "";
|
|
1892
|
-
url.hash = parsed.hash || "";
|
|
1893
|
-
return url;
|
|
1894
|
-
}
|
|
1895
1923
|
function processRouteLoaderData(matches, results, pendingActionResult, isStaticHandler = false, skipLoaderErrorBubbling = false) {
|
|
1896
1924
|
let loaderData = {};
|
|
1897
1925
|
let errors = null;
|
|
@@ -18,7 +18,6 @@ import { FlashSessionData, IsSessionFunction, Session, SessionData, SessionIdSto
|
|
|
18
18
|
import { createCookieSessionStorage } from "./lib/server-runtime/sessions/cookieStorage.js";
|
|
19
19
|
import { createMemorySessionStorage } from "./lib/server-runtime/sessions/memoryStorage.js";
|
|
20
20
|
import { setDevServerHooks } from "./lib/server-runtime/dev.js";
|
|
21
|
-
import { AppLoadContext } from "./lib/server-runtime/data.js";
|
|
22
21
|
import { Future } from "./lib/types/future.js";
|
|
23
22
|
import { unstable_SerializesTo } from "./lib/types/serializes-to.js";
|
|
24
23
|
import { href } from "./lib/href.js";
|
|
@@ -36,10 +35,10 @@ import { createClientRoutes, createClientRoutesWithHMRRevalidationOptOut, should
|
|
|
36
35
|
import { AssetsManifest, EntryContext } from "./lib/dom/ssr/entry.js";
|
|
37
36
|
import { HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, ServerBuild, ServerEntryModule } from "./lib/server-runtime/build.js";
|
|
38
37
|
import { CreateRequestHandlerFunction, RequestHandler, createRequestHandler } from "./lib/server-runtime/server.js";
|
|
39
|
-
import { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationHandlerResult, ServerInstrumentation } from "./lib/router/instrumentation.js";
|
|
38
|
+
import { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationClientRouterResult, InstrumentationHandlerResult, InstrumentationServerHandlerResult, ServerInstrumentation } from "./lib/router/instrumentation.js";
|
|
40
39
|
|
|
41
40
|
//#region index.d.ts
|
|
42
41
|
declare const unstable_getRequest: typeof getRequest;
|
|
43
42
|
declare const unstable_matchRSCServerRequest: typeof matchRSCServerRequest;
|
|
44
43
|
//#endregion
|
|
45
|
-
export { type ActionFunction, type ActionFunctionArgs,
|
|
44
|
+
export { type ActionFunction, type ActionFunctionArgs, Await, type AwaitProps, type BaseRouteObject, type Blocker, type BlockerFunction, BrowserRouter, type BrowserRouterProps, type ClientActionFunction, type ClientActionFunctionArgs, type ClientInstrumentation, type ClientLoaderFunction, type ClientLoaderFunctionArgs, type ClientOnErrorFunction, type Cookie, type CookieOptions, type CookieParseOptions, type CookieSerializeOptions, type CookieSignatureOptions, type CreateRequestHandlerFunction, type DOMRouterOpts, type DataRouteMatch, type DataRouteObject, type Router as DataRouter, type DataStrategyFunction, type DataStrategyFunctionArgs, type DataStrategyMatch, type DataStrategyResult, type DiscoverBehavior, type EntryContext, type ErrorResponse, type Fetcher, type FetcherFormProps, type FetcherSubmitFunction, type FetcherSubmitOptions, type FetcherWithComponents, type FlashSessionData, Form, type FormEncType, type FormMethod, type FormProps, type Future, type GetScrollPositionFunction, type GetScrollRestorationKeyFunction, type HTMLFormMethod, type HandleDataRequestFunction, type HandleDocumentRequestFunction, type HandleErrorFunction, HashRouter, type HashRouterProps, type HeadersArgs, type HeadersFunction, type HistoryRouterProps, type HtmlLinkDescriptor, type HydrationState, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, type IndexRouteObject, type IndexRouteProps, type InitialEntry, type InstrumentRequestHandlerFunction, type InstrumentRouteFunction, type InstrumentRouterFunction, type InstrumentationClientRouterResult, type InstrumentationHandlerResult, type InstrumentationServerHandlerResult, type IsCookieFunction, type IsSessionFunction, type LayoutRouteProps, type LazyRouteFunction, Link, type LinkDescriptor, type LinkProps, Links, type LinksFunction, type LinksProps, type LoaderFunction, type LoaderFunctionArgs, type Location, MemoryRouter, type MemoryRouterOpts, type MemoryRouterProps, Meta, type MetaArgs, type MetaDescriptor, type MetaFunction, type MiddlewareFunction, NavLink, type NavLinkProps, type NavLinkRenderProps, Navigate, type NavigateFunction, type NavigateOptions, type NavigateProps, type Navigation, type NavigationStates, Action as NavigationType, type Navigator, type NonIndexRouteObject, Outlet, type OutletProps, type PageLinkDescriptor, type ParamKeyValuePair, type ParamParseKey, type Params, type PatchRoutesOnNavigationFunction, type PatchRoutesOnNavigationFunctionArgs, type Path, type PathMatch, type PathParam, type PathPattern, type PathRouteProps, type PrefetchBehavior, PrefetchPageLinks, type RedirectFunction, type Register, type RelativeRoutingType, type RequestHandler, type RevalidationState, Route, type RouteMatch, type RouteObject, type RouteProps, Router$1 as Router, type RouterContext, RouterContextProvider, type RouterFetchOptions, type RouterInit, type RouterNavigateOptions, type RouterProps, RouterProvider, type RouterProviderProps, type RouterState, type RouterSubscriber, Routes, type RoutesProps, type RoutesTestStubProps, Scripts, type ScriptsProps, ScrollRestoration, type ScrollRestorationProps, type ServerBuild, type ServerEntryModule, type ServerInstrumentation, ServerRouter, type ServerRouterProps, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, type SetURLSearchParams, type ShouldRevalidateFunction, type ShouldRevalidateFunctionArgs, type StaticHandler, type StaticHandlerContext, StaticRouter, type StaticRouterProps, StaticRouterProvider, type StaticRouterProviderProps, type SubmitFunction, type SubmitOptions, type SubmitTarget, type To, type UIMatch, type AssetsManifest as UNSAFE_AssetsManifest, AwaitContextProvider as UNSAFE_AwaitContextProvider, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, type DataWithResponseInit as UNSAFE_DataWithResponseInit, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, FetchersContext as UNSAFE_FetchersContext, FrameworkContext as UNSAFE_FrameworkContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RSCDefaultRootErrorBoundary as UNSAFE_RSCDefaultRootErrorBoundary, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteContext as UNSAFE_RouteContext, type RouteModules as UNSAFE_RouteModules, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, ViewTransitionContext as UNSAFE_ViewTransitionContext, WithComponentProps as UNSAFE_WithComponentProps, WithErrorBoundaryProps as UNSAFE_WithErrorBoundaryProps, WithHydrateFallbackProps as UNSAFE_WithHydrateFallbackProps, createBrowserHistory as UNSAFE_createBrowserHistory, createClientRoutes as UNSAFE_createClientRoutes, createClientRoutesWithHMRRevalidationOptOut as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, createHashHistory as UNSAFE_createHashHistory, createMemoryHistory as UNSAFE_createMemoryHistory, createRouter as UNSAFE_createRouter, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, defaultMapRouteProperties as UNSAFE_defaultMapRouteProperties, getHydrationData as UNSAFE_getHydrationData, getPatchRoutesOnNavigationFunction as UNSAFE_getPatchRoutesOnNavigationFunction, getTurboStreamSingleFetchDataStrategy as UNSAFE_getTurboStreamSingleFetchDataStrategy, hydrationRouteProperties as UNSAFE_hydrationRouteProperties, invariant as UNSAFE_invariant, shouldHydrateRouteLoader as UNSAFE_shouldHydrateRouteLoader, useFogOFWarDiscovery as UNSAFE_useFogOFWarDiscovery, useScrollRestoration as UNSAFE_useScrollRestoration, withComponentProps as UNSAFE_withComponentProps, withErrorBoundaryProps as UNSAFE_withErrorBoundaryProps, withHydrateFallbackProps as UNSAFE_withHydrateFallbackProps, type URLSearchParamsInit, createBrowserRouter, createContext, createCookie, createCookieSessionStorage, createHashRouter, createMemoryRouter, createMemorySessionStorage, createPath, createRequestHandler, createRoutesFromChildren, createRoutesFromElements, createRoutesStub, createSearchParams, createSession, createSessionStorage, createStaticHandler, createStaticRouter, data, generatePath, href, isCookie, isRouteErrorResponse, isSession, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, replace, resolvePath, type BrowserCreateFromReadableStreamFunction as unstable_BrowserCreateFromReadableStreamFunction, type DecodeActionFunction as unstable_DecodeActionFunction, type DecodeFormStateFunction as unstable_DecodeFormStateFunction, type DecodeReplyFunction as unstable_DecodeReplyFunction, type EncodeReplyFunction as unstable_EncodeReplyFunction, HistoryRouter as unstable_HistoryRouter, type LoadServerActionFunction as unstable_LoadServerActionFunction, type RSCHydratedRouterProps as unstable_RSCHydratedRouterProps, type RSCManifestPayload as unstable_RSCManifestPayload, type RSCMatch as unstable_RSCMatch, type RSCPayload as unstable_RSCPayload, type RSCRenderPayload as unstable_RSCRenderPayload, type RSCRouteConfig as unstable_RSCRouteConfig, type RSCRouteConfigEntry as unstable_RSCRouteConfigEntry, type RSCRouteManifest as unstable_RSCRouteManifest, type RSCRouteMatch as unstable_RSCRouteMatch, RSCStaticRouter as unstable_RSCStaticRouter, type RSCStaticRouterProps as unstable_RSCStaticRouterProps, type unstable_RouterState, type unstable_RouterStateActiveVariant, type unstable_RouterStatePendingVariant, type SSRCreateFromReadableStreamFunction as unstable_SSRCreateFromReadableStreamFunction, type unstable_SerializesTo, unstable_getRequest, unstable_matchRSCServerRequest, routeRSCServerRequest as unstable_routeRSCServerRequest, setDevServerHooks as unstable_setDevServerHooks, usePrompt as unstable_usePrompt, useRoute as unstable_useRoute, useRouterState as unstable_useRouterState, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useBlocker, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, useViewTransitionState };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.1.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -22,7 +22,7 @@ import * as React$1 from "react";
|
|
|
22
22
|
//#region lib/dom/lib.tsx
|
|
23
23
|
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
24
24
|
try {
|
|
25
|
-
if (isBrowser) window.__reactRouterVersion = "8.
|
|
25
|
+
if (isBrowser) window.__reactRouterVersion = "8.1.0";
|
|
26
26
|
} catch (e) {}
|
|
27
27
|
/**
|
|
28
28
|
* Create a new {@link DataRouter| data router} that manages the application
|