react-router 0.0.0-experimental-3d7dcee → 0.0.0-experimental-426e5caec
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 +39 -2
- package/dist/development/{chunk-WJ2QP6HN.mjs → chunk-5HELVQDL.mjs} +179 -249
- package/dist/development/{chunk-S2WJDCRE.js → chunk-KCPD675I.js} +173 -243
- package/dist/{production/chunk-NIW37A6Q.js → development/chunk-KPVSYEOF.js} +135 -135
- package/dist/development/{chunk-QMIAKNRH.mjs → chunk-ZOYSFAC5.mjs} +56 -102
- package/dist/{production/context-DnZM5brG.d.mts → development/context-EwD9faH7.d.mts} +34 -33
- package/dist/development/dom-export.d.mts +3 -3
- package/dist/development/dom-export.d.ts +2 -2
- package/dist/development/dom-export.js +7 -7
- package/dist/development/dom-export.mjs +7 -7
- package/dist/development/{index-react-server-client-zr5eNeut.d.ts → index-react-server-client-CjrUmqhw.d.ts} +12 -12
- package/dist/{production/index-react-server-client-9rHNv-U3.d.mts → development/index-react-server-client-DDdP8ud2.d.mts} +13 -13
- package/dist/development/index-react-server-client.d.mts +3 -3
- package/dist/development/index-react-server-client.d.ts +2 -2
- package/dist/development/index-react-server-client.js +4 -4
- package/dist/development/index-react-server-client.mjs +2 -2
- package/dist/development/index-react-server.d.mts +76 -38
- package/dist/development/index-react-server.d.ts +76 -38
- package/dist/development/index-react-server.js +116 -112
- package/dist/development/index-react-server.mjs +114 -111
- package/dist/development/index.d.mts +53 -15
- package/dist/development/index.d.ts +51 -13
- package/dist/development/index.js +138 -184
- package/dist/development/index.mjs +7 -7
- package/dist/development/lib/types/internal.d.mts +11 -8
- package/dist/development/lib/types/internal.d.ts +10 -7
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/{route-data-C24VEkoE.d.mts → route-data-CAnRKu1U.d.mts} +14 -14
- package/dist/development/{routeModules-FY5IBiA_.d.ts → routeModules-CQWjJ9NX.d.ts} +46 -45
- package/dist/production/{chunk-2BFZ6QQU.mjs → chunk-5W7O3ZZ2.mjs} +179 -249
- package/dist/production/{chunk-OFC37UQM.mjs → chunk-DZS627TW.mjs} +56 -102
- package/dist/production/{chunk-7CWVKQLP.js → chunk-NLCKEFES.js} +173 -243
- package/dist/{development/chunk-LSB26UC6.js → production/chunk-TC5SCO6O.js} +135 -135
- package/dist/{development/context-DnZM5brG.d.mts → production/context-EwD9faH7.d.mts} +34 -33
- package/dist/production/dom-export.d.mts +3 -3
- package/dist/production/dom-export.d.ts +2 -2
- package/dist/production/dom-export.js +7 -7
- package/dist/production/dom-export.mjs +7 -7
- package/dist/production/{index-react-server-client-zr5eNeut.d.ts → index-react-server-client-CjrUmqhw.d.ts} +12 -12
- package/dist/{development/index-react-server-client-9rHNv-U3.d.mts → production/index-react-server-client-DDdP8ud2.d.mts} +13 -13
- package/dist/production/index-react-server-client.d.mts +3 -3
- package/dist/production/index-react-server-client.d.ts +2 -2
- package/dist/production/index-react-server-client.js +4 -4
- package/dist/production/index-react-server-client.mjs +2 -2
- package/dist/production/index-react-server.d.mts +76 -38
- package/dist/production/index-react-server.d.ts +76 -38
- package/dist/production/index-react-server.js +116 -112
- package/dist/production/index-react-server.mjs +114 -111
- package/dist/production/index.d.mts +53 -15
- package/dist/production/index.d.ts +51 -13
- package/dist/production/index.js +138 -184
- package/dist/production/index.mjs +7 -7
- package/dist/production/lib/types/internal.d.mts +11 -8
- package/dist/production/lib/types/internal.d.ts +10 -7
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/production/{route-data-C24VEkoE.d.mts → route-data-CAnRKu1U.d.mts} +14 -14
- package/dist/production/{routeModules-FY5IBiA_.d.ts → routeModules-CQWjJ9NX.d.ts} +46 -45
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-426e5caec
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
Outlet,
|
|
17
17
|
RSCRouterContext,
|
|
18
18
|
RemixErrorBoundary,
|
|
19
|
+
RouterContextProvider,
|
|
19
20
|
RouterProvider,
|
|
20
21
|
SINGLE_FETCH_REDIRECT_STATUS,
|
|
21
22
|
SingleFetchRedirectSymbol,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
StreamTransfer,
|
|
24
25
|
convertRoutesToDataRoutes,
|
|
25
26
|
createBrowserHistory,
|
|
27
|
+
createContext,
|
|
26
28
|
createMemoryRouter,
|
|
27
29
|
createRequestInit,
|
|
28
30
|
createRouter,
|
|
@@ -51,14 +53,12 @@ import {
|
|
|
51
53
|
singleFetchUrl,
|
|
52
54
|
stripBasename,
|
|
53
55
|
stripIndexParam,
|
|
54
|
-
unstable_RouterContextProvider,
|
|
55
|
-
unstable_createContext,
|
|
56
56
|
useRouteError,
|
|
57
57
|
warnOnce,
|
|
58
58
|
withComponentProps,
|
|
59
59
|
withErrorBoundaryProps,
|
|
60
60
|
withHydrateFallbackProps
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-5HELVQDL.mjs";
|
|
62
62
|
|
|
63
63
|
// lib/dom/ssr/server.tsx
|
|
64
64
|
import * as React from "react";
|
|
@@ -145,7 +145,7 @@ function createRoutesStub(routes, _context) {
|
|
|
145
145
|
frameworkContextRef.current = {
|
|
146
146
|
future: {
|
|
147
147
|
unstable_subResourceIntegrity: future?.unstable_subResourceIntegrity === true,
|
|
148
|
-
|
|
148
|
+
v8_middleware: future?.v8_middleware === true
|
|
149
149
|
},
|
|
150
150
|
manifest: {
|
|
151
151
|
routes: {},
|
|
@@ -162,7 +162,7 @@ function createRoutesStub(routes, _context) {
|
|
|
162
162
|
// @ts-expect-error `StubRouteObject` is stricter about `loader`/`action`
|
|
163
163
|
// types compared to `AgnosticRouteObject`
|
|
164
164
|
convertRoutesToDataRoutes(routes, (r) => r),
|
|
165
|
-
_context !== void 0 ? _context : future?.
|
|
165
|
+
_context !== void 0 ? _context : future?.v8_middleware ? new RouterContextProvider() : {},
|
|
166
166
|
frameworkContextRef.current.manifest,
|
|
167
167
|
frameworkContextRef.current.routeModules
|
|
168
168
|
);
|
|
@@ -612,7 +612,7 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
|
|
|
612
612
|
hasErrorBoundary: route.id === "root" || route.module.ErrorBoundary != null,
|
|
613
613
|
id: route.id,
|
|
614
614
|
path: route.path,
|
|
615
|
-
|
|
615
|
+
middleware: route.module.middleware,
|
|
616
616
|
// Need to use RR's version in the param typed here to permit the optional
|
|
617
617
|
// context even though we know it'll always be provided in remix
|
|
618
618
|
loader: route.module.loader ? async (args) => {
|
|
@@ -785,7 +785,7 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
785
785
|
requestContext: loadContext,
|
|
786
786
|
skipLoaderErrorBubbling: true,
|
|
787
787
|
skipRevalidation: true,
|
|
788
|
-
|
|
788
|
+
generateMiddlewareResponse: build.future.v8_middleware ? async (query) => {
|
|
789
789
|
try {
|
|
790
790
|
let innerResult = await query(handlerRequest);
|
|
791
791
|
return handleQueryResult(innerResult);
|
|
@@ -799,21 +799,7 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
799
799
|
return handleQueryError(error);
|
|
800
800
|
}
|
|
801
801
|
function handleQueryResult(result) {
|
|
802
|
-
|
|
803
|
-
result = staticContextToResponse(result);
|
|
804
|
-
}
|
|
805
|
-
if (isRedirectResponse(result)) {
|
|
806
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
807
|
-
result: getSingleFetchRedirect(
|
|
808
|
-
result.status,
|
|
809
|
-
result.headers,
|
|
810
|
-
build.basename
|
|
811
|
-
),
|
|
812
|
-
headers: result.headers,
|
|
813
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
return result;
|
|
802
|
+
return isResponse(result) ? result : staticContextToResponse(result);
|
|
817
803
|
}
|
|
818
804
|
function handleQueryError(error) {
|
|
819
805
|
handleError(error);
|
|
@@ -826,15 +812,7 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
826
812
|
function staticContextToResponse(context) {
|
|
827
813
|
let headers = getDocumentHeaders(context, build);
|
|
828
814
|
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
829
|
-
return
|
|
830
|
-
result: getSingleFetchRedirect(
|
|
831
|
-
context.statusCode,
|
|
832
|
-
headers,
|
|
833
|
-
build.basename
|
|
834
|
-
),
|
|
835
|
-
headers,
|
|
836
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
837
|
-
});
|
|
815
|
+
return new Response(null, { status: context.statusCode, headers });
|
|
838
816
|
}
|
|
839
817
|
if (context.errors) {
|
|
840
818
|
Object.values(context.errors).forEach((err) => {
|
|
@@ -871,7 +849,7 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
871
849
|
requestContext: loadContext,
|
|
872
850
|
filterMatchesToLoad: (m) => !loadRouteIds || loadRouteIds.has(m.route.id),
|
|
873
851
|
skipLoaderErrorBubbling: true,
|
|
874
|
-
|
|
852
|
+
generateMiddlewareResponse: build.future.v8_middleware ? async (query) => {
|
|
875
853
|
try {
|
|
876
854
|
let innerResult = await query(handlerRequest);
|
|
877
855
|
return handleQueryResult(innerResult);
|
|
@@ -885,21 +863,7 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
885
863
|
return handleQueryError(error);
|
|
886
864
|
}
|
|
887
865
|
function handleQueryResult(result) {
|
|
888
|
-
|
|
889
|
-
if (isRedirectResponse(response)) {
|
|
890
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
891
|
-
result: {
|
|
892
|
-
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
893
|
-
response.status,
|
|
894
|
-
response.headers,
|
|
895
|
-
build.basename
|
|
896
|
-
)
|
|
897
|
-
},
|
|
898
|
-
headers: response.headers,
|
|
899
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
return response;
|
|
866
|
+
return isResponse(result) ? result : staticContextToResponse(result);
|
|
903
867
|
}
|
|
904
868
|
function handleQueryError(error) {
|
|
905
869
|
handleError(error);
|
|
@@ -912,17 +876,7 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
912
876
|
function staticContextToResponse(context) {
|
|
913
877
|
let headers = getDocumentHeaders(context, build);
|
|
914
878
|
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
915
|
-
return
|
|
916
|
-
result: {
|
|
917
|
-
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
918
|
-
context.statusCode,
|
|
919
|
-
headers,
|
|
920
|
-
build.basename
|
|
921
|
-
)
|
|
922
|
-
},
|
|
923
|
-
headers,
|
|
924
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
925
|
-
});
|
|
879
|
+
return new Response(null, { status: context.statusCode, headers });
|
|
926
880
|
}
|
|
927
881
|
if (context.errors) {
|
|
928
882
|
Object.values(context.errors).forEach((err) => {
|
|
@@ -980,6 +934,21 @@ function generateSingleFetchResponse(request, build, serverMode, {
|
|
|
980
934
|
}
|
|
981
935
|
);
|
|
982
936
|
}
|
|
937
|
+
function generateSingleFetchRedirectResponse(redirectResponse, request, build, serverMode) {
|
|
938
|
+
let redirect2 = getSingleFetchRedirect(
|
|
939
|
+
redirectResponse.status,
|
|
940
|
+
redirectResponse.headers,
|
|
941
|
+
build.basename
|
|
942
|
+
);
|
|
943
|
+
let headers = new Headers(redirectResponse.headers);
|
|
944
|
+
headers.delete("Location");
|
|
945
|
+
headers.set("Content-Type", "text/x-script");
|
|
946
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
947
|
+
result: request.method === "GET" ? { [SingleFetchRedirectSymbol]: redirect2 } : redirect2,
|
|
948
|
+
headers,
|
|
949
|
+
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
950
|
+
});
|
|
951
|
+
}
|
|
983
952
|
function getSingleFetchRedirect(status, headers, basename) {
|
|
984
953
|
let redirect2 = headers.get("Location");
|
|
985
954
|
if (basename) {
|
|
@@ -1097,15 +1066,15 @@ var createRequestHandler = (build, mode) => {
|
|
|
1097
1066
|
request
|
|
1098
1067
|
});
|
|
1099
1068
|
};
|
|
1100
|
-
if (_build.future.
|
|
1101
|
-
if (initialContext && !(initialContext instanceof
|
|
1069
|
+
if (_build.future.v8_middleware) {
|
|
1070
|
+
if (initialContext && !(initialContext instanceof RouterContextProvider)) {
|
|
1102
1071
|
let error = new Error(
|
|
1103
|
-
"Invalid `context` value provided to `handleRequest`. When middleware is enabled you must return an instance of `
|
|
1072
|
+
"Invalid `context` value provided to `handleRequest`. When middleware is enabled you must return an instance of `RouterContextProvider` from your `getLoadContext` function."
|
|
1104
1073
|
);
|
|
1105
1074
|
handleError(error);
|
|
1106
1075
|
return returnLastResortErrorResponse(error, serverMode);
|
|
1107
1076
|
}
|
|
1108
|
-
loadContext = initialContext || new
|
|
1077
|
+
loadContext = initialContext || new RouterContextProvider();
|
|
1109
1078
|
} else {
|
|
1110
1079
|
loadContext = initialContext || {};
|
|
1111
1080
|
}
|
|
@@ -1205,6 +1174,14 @@ var createRequestHandler = (build, mode) => {
|
|
|
1205
1174
|
loadContext,
|
|
1206
1175
|
handleError
|
|
1207
1176
|
);
|
|
1177
|
+
if (isRedirectResponse(response)) {
|
|
1178
|
+
response = generateSingleFetchRedirectResponse(
|
|
1179
|
+
response,
|
|
1180
|
+
request,
|
|
1181
|
+
_build,
|
|
1182
|
+
serverMode
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1208
1185
|
if (_build.entry.module.handleDataRequest) {
|
|
1209
1186
|
response = await _build.entry.module.handleDataRequest(response, {
|
|
1210
1187
|
context: loadContext,
|
|
@@ -1212,29 +1189,11 @@ var createRequestHandler = (build, mode) => {
|
|
|
1212
1189
|
request
|
|
1213
1190
|
});
|
|
1214
1191
|
if (isRedirectResponse(response)) {
|
|
1215
|
-
|
|
1216
|
-
response
|
|
1217
|
-
|
|
1218
|
-
_build
|
|
1219
|
-
|
|
1220
|
-
if (request.method === "GET") {
|
|
1221
|
-
result = {
|
|
1222
|
-
[SingleFetchRedirectSymbol]: result
|
|
1223
|
-
};
|
|
1224
|
-
}
|
|
1225
|
-
let headers = new Headers(response.headers);
|
|
1226
|
-
headers.set("Content-Type", "text/x-script");
|
|
1227
|
-
return new Response(
|
|
1228
|
-
encodeViaTurboStream(
|
|
1229
|
-
result,
|
|
1230
|
-
request.signal,
|
|
1231
|
-
_build.entry.module.streamTimeout,
|
|
1232
|
-
serverMode
|
|
1233
|
-
),
|
|
1234
|
-
{
|
|
1235
|
-
status: SINGLE_FETCH_REDIRECT_STATUS,
|
|
1236
|
-
headers
|
|
1237
|
-
}
|
|
1192
|
+
response = generateSingleFetchRedirectResponse(
|
|
1193
|
+
response,
|
|
1194
|
+
request,
|
|
1195
|
+
_build,
|
|
1196
|
+
serverMode
|
|
1238
1197
|
);
|
|
1239
1198
|
}
|
|
1240
1199
|
}
|
|
@@ -1343,7 +1302,7 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
|
|
|
1343
1302
|
try {
|
|
1344
1303
|
let result = await staticHandler.query(request, {
|
|
1345
1304
|
requestContext: loadContext,
|
|
1346
|
-
|
|
1305
|
+
generateMiddlewareResponse: build.future.v8_middleware ? async (query) => {
|
|
1347
1306
|
try {
|
|
1348
1307
|
let innerResult = await query(request);
|
|
1349
1308
|
if (!isResponse(innerResult)) {
|
|
@@ -1479,7 +1438,7 @@ async function handleResourceRequest(serverMode, build, staticHandler, routeId,
|
|
|
1479
1438
|
let result = await staticHandler.queryRoute(request, {
|
|
1480
1439
|
routeId,
|
|
1481
1440
|
requestContext: loadContext,
|
|
1482
|
-
|
|
1441
|
+
generateMiddlewareResponse: build.future.v8_middleware ? async (queryRoute) => {
|
|
1483
1442
|
try {
|
|
1484
1443
|
let innerResult = await queryRoute(request);
|
|
1485
1444
|
return handleQueryRouteResult(innerResult);
|
|
@@ -1974,7 +1933,7 @@ function createCallServer({
|
|
|
1974
1933
|
function createRouterFromPayload({
|
|
1975
1934
|
fetchImplementation,
|
|
1976
1935
|
createFromReadableStream,
|
|
1977
|
-
|
|
1936
|
+
getContext,
|
|
1978
1937
|
payload
|
|
1979
1938
|
}) {
|
|
1980
1939
|
const globalVar = window;
|
|
@@ -2012,7 +1971,7 @@ function createRouterFromPayload({
|
|
|
2012
1971
|
}, []);
|
|
2013
1972
|
globalVar.__reactRouterDataRouter = createRouter({
|
|
2014
1973
|
routes,
|
|
2015
|
-
|
|
1974
|
+
getContext,
|
|
2016
1975
|
basename: payload.basename,
|
|
2017
1976
|
history: createBrowserHistory(),
|
|
2018
1977
|
hydrationData: getHydrationData(
|
|
@@ -2122,7 +2081,7 @@ function createRouterFromPayload({
|
|
|
2122
2081
|
routeModules: globalVar.__reactRouterRouteModules
|
|
2123
2082
|
};
|
|
2124
2083
|
}
|
|
2125
|
-
var renderedRoutesContext =
|
|
2084
|
+
var renderedRoutesContext = createContext();
|
|
2126
2085
|
function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
|
|
2127
2086
|
let dataStrategy = getSingleFetchDataStrategyImpl(
|
|
2128
2087
|
getRouter,
|
|
@@ -2149,7 +2108,7 @@ function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReada
|
|
|
2149
2108
|
return M.route.hasComponent && !M.route.element;
|
|
2150
2109
|
}
|
|
2151
2110
|
);
|
|
2152
|
-
return async (args) => args.
|
|
2111
|
+
return async (args) => args.runClientMiddleware(async () => {
|
|
2153
2112
|
let context = args.context;
|
|
2154
2113
|
context.set(renderedRoutesContext, []);
|
|
2155
2114
|
let results = await dataStrategy(args);
|
|
@@ -2235,22 +2194,17 @@ function RSCHydratedRouter({
|
|
|
2235
2194
|
fetch: fetchImplementation = fetch,
|
|
2236
2195
|
payload,
|
|
2237
2196
|
routeDiscovery = "eager",
|
|
2238
|
-
|
|
2197
|
+
getContext
|
|
2239
2198
|
}) {
|
|
2240
2199
|
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
2241
2200
|
let { router, routeModules } = React4.useMemo(
|
|
2242
2201
|
() => createRouterFromPayload({
|
|
2243
2202
|
payload,
|
|
2244
2203
|
fetchImplementation,
|
|
2245
|
-
|
|
2204
|
+
getContext,
|
|
2246
2205
|
createFromReadableStream
|
|
2247
2206
|
}),
|
|
2248
|
-
[
|
|
2249
|
-
createFromReadableStream,
|
|
2250
|
-
payload,
|
|
2251
|
-
fetchImplementation,
|
|
2252
|
-
unstable_getContext
|
|
2253
|
-
]
|
|
2207
|
+
[createFromReadableStream, payload, fetchImplementation, getContext]
|
|
2254
2208
|
);
|
|
2255
2209
|
React4.useEffect(() => {
|
|
2256
2210
|
setIsHydrated();
|
|
@@ -2322,7 +2276,7 @@ function RSCHydratedRouter({
|
|
|
2322
2276
|
future: {
|
|
2323
2277
|
// These flags have no runtime impact so can always be false. If we add
|
|
2324
2278
|
// flags that drive runtime behavior they'll need to be proxied through.
|
|
2325
|
-
|
|
2279
|
+
v8_middleware: false,
|
|
2326
2280
|
unstable_subResourceIntegrity: false
|
|
2327
2281
|
},
|
|
2328
2282
|
isSpaMode: false,
|
|
@@ -2738,7 +2692,7 @@ function RSCStaticRouter({ getPayload }) {
|
|
|
2738
2692
|
future: {
|
|
2739
2693
|
// These flags have no runtime impact so can always be false. If we add
|
|
2740
2694
|
// flags that drive runtime behavior they'll need to be proxied through.
|
|
2741
|
-
|
|
2695
|
+
v8_middleware: false,
|
|
2742
2696
|
unstable_subResourceIntegrity: false
|
|
2743
2697
|
},
|
|
2744
2698
|
isSpaMode: false,
|
|
@@ -212,7 +212,7 @@ type UrlHistoryOptions = {
|
|
|
212
212
|
interface Future {
|
|
213
213
|
}
|
|
214
214
|
type MiddlewareEnabled = Future extends {
|
|
215
|
-
|
|
215
|
+
middleware: infer T extends boolean;
|
|
216
216
|
} ? T : false;
|
|
217
217
|
|
|
218
218
|
type MaybePromise<T> = T | Promise<T>;
|
|
@@ -272,14 +272,14 @@ type Submission = {
|
|
|
272
272
|
};
|
|
273
273
|
/**
|
|
274
274
|
* A context instance used as the key for the `get`/`set` methods of a
|
|
275
|
-
* {@link
|
|
275
|
+
* {@link RouterContextProvider}. Accepts an optional default
|
|
276
276
|
* value to be returned if no value has been set.
|
|
277
277
|
*/
|
|
278
|
-
interface
|
|
278
|
+
interface RouterContext<T = unknown> {
|
|
279
279
|
defaultValue?: T;
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
282
|
-
* Creates a type-safe {@link
|
|
282
|
+
* Creates a type-safe {@link RouterContext} object that can be used to
|
|
283
283
|
* store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
|
|
284
284
|
* [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
|
|
285
285
|
* Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
|
|
@@ -290,11 +290,11 @@ interface unstable_RouterContext<T = unknown> {
|
|
|
290
290
|
* when no value has been set will throw an error.
|
|
291
291
|
*
|
|
292
292
|
* ```tsx filename=app/context.ts
|
|
293
|
-
* import {
|
|
293
|
+
* import { createContext } from "react-router";
|
|
294
294
|
*
|
|
295
295
|
* // Create a context for user data
|
|
296
296
|
* export const userContext =
|
|
297
|
-
*
|
|
297
|
+
* createContext<User | null>(null);
|
|
298
298
|
* ```
|
|
299
299
|
*
|
|
300
300
|
* ```tsx filename=app/middleware/auth.ts
|
|
@@ -332,23 +332,23 @@ interface unstable_RouterContext<T = unknown> {
|
|
|
332
332
|
* @mode data
|
|
333
333
|
* @param defaultValue An optional default value for the context. This value
|
|
334
334
|
* will be returned if no value has been set for this context.
|
|
335
|
-
* @returns A {@link
|
|
335
|
+
* @returns A {@link RouterContext} object that can be used with
|
|
336
336
|
* `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
|
|
337
337
|
* [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
|
|
338
338
|
*/
|
|
339
|
-
declare function
|
|
339
|
+
declare function createContext<T>(defaultValue?: T): RouterContext<T>;
|
|
340
340
|
/**
|
|
341
341
|
* Provides methods for writing/reading values in application context in a
|
|
342
342
|
* type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
|
|
343
343
|
*
|
|
344
344
|
* @example
|
|
345
345
|
* import {
|
|
346
|
-
*
|
|
347
|
-
*
|
|
346
|
+
* createContext,
|
|
347
|
+
* RouterContextProvider
|
|
348
348
|
* } from "react-router";
|
|
349
349
|
*
|
|
350
|
-
* const userContext =
|
|
351
|
-
* const contextProvider = new
|
|
350
|
+
* const userContext = createContext<User | null>(null);
|
|
351
|
+
* const contextProvider = new RouterContextProvider();
|
|
352
352
|
* contextProvider.set(userContext, getUser());
|
|
353
353
|
* // ^ Type-safe
|
|
354
354
|
* const user = contextProvider.get(userContext);
|
|
@@ -359,13 +359,13 @@ declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterCon
|
|
|
359
359
|
* @mode framework
|
|
360
360
|
* @mode data
|
|
361
361
|
*/
|
|
362
|
-
declare class
|
|
362
|
+
declare class RouterContextProvider {
|
|
363
363
|
#private;
|
|
364
364
|
/**
|
|
365
|
-
* Create a new `
|
|
365
|
+
* Create a new `RouterContextProvider` instance
|
|
366
366
|
* @param init An optional initial context map to populate the provider with
|
|
367
367
|
*/
|
|
368
|
-
constructor(init?: Map<
|
|
368
|
+
constructor(init?: Map<RouterContext, unknown>);
|
|
369
369
|
/**
|
|
370
370
|
* Access a value from the context. If no value has been set for the context,
|
|
371
371
|
* it will return the context's `defaultValue` if provided, or throw an error
|
|
@@ -374,7 +374,7 @@ declare class unstable_RouterContextProvider {
|
|
|
374
374
|
* @returns The value for the context, or the context's `defaultValue` if no
|
|
375
375
|
* value was set
|
|
376
376
|
*/
|
|
377
|
-
get<T>(context:
|
|
377
|
+
get<T>(context: RouterContext<T>): T;
|
|
378
378
|
/**
|
|
379
379
|
* Set a value for the context. If the context already has a value set, this
|
|
380
380
|
* will overwrite it.
|
|
@@ -383,9 +383,9 @@ declare class unstable_RouterContextProvider {
|
|
|
383
383
|
* @param value The value to set for the context
|
|
384
384
|
* @returns {void}
|
|
385
385
|
*/
|
|
386
|
-
set<C extends
|
|
386
|
+
set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void;
|
|
387
387
|
}
|
|
388
|
-
type DefaultContext = MiddlewareEnabled extends true ? Readonly<
|
|
388
|
+
type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : any;
|
|
389
389
|
/**
|
|
390
390
|
* @private
|
|
391
391
|
* Arguments passed to route loader/action functions. Same for now but we keep
|
|
@@ -420,7 +420,7 @@ interface DataFunctionArgs<Context> {
|
|
|
420
420
|
* Route middleware `next` function to call downstream handlers and then complete
|
|
421
421
|
* middlewares from the bottom-up
|
|
422
422
|
*/
|
|
423
|
-
interface
|
|
423
|
+
interface MiddlewareNextFunction<Result = unknown> {
|
|
424
424
|
(): Promise<Result>;
|
|
425
425
|
}
|
|
426
426
|
/**
|
|
@@ -429,7 +429,7 @@ interface unstable_MiddlewareNextFunction<Result = unknown> {
|
|
|
429
429
|
* a `next` function as the second parameter which will call downstream handlers
|
|
430
430
|
* and then complete middlewares from the bottom-up
|
|
431
431
|
*/
|
|
432
|
-
type
|
|
432
|
+
type MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<RouterContextProvider>>, next: MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
|
|
433
433
|
/**
|
|
434
434
|
* Arguments passed to loader functions
|
|
435
435
|
*/
|
|
@@ -584,7 +584,7 @@ interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctio
|
|
|
584
584
|
* Matches for this route extended with Data strategy APIs
|
|
585
585
|
*/
|
|
586
586
|
matches: DataStrategyMatch[];
|
|
587
|
-
|
|
587
|
+
runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
|
|
588
588
|
/**
|
|
589
589
|
* The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
|
|
590
590
|
* for navigational executions
|
|
@@ -629,7 +629,7 @@ type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" |
|
|
|
629
629
|
* onto the route. Either they're meaningful to the router, or they'll get
|
|
630
630
|
* ignored.
|
|
631
631
|
*/
|
|
632
|
-
type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "
|
|
632
|
+
type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "middleware";
|
|
633
633
|
/**
|
|
634
634
|
* lazy object to load route properties, which can add non-matching
|
|
635
635
|
* related properties to a route
|
|
@@ -652,7 +652,7 @@ type AgnosticBaseRouteObject = {
|
|
|
652
652
|
caseSensitive?: boolean;
|
|
653
653
|
path?: string;
|
|
654
654
|
id?: string;
|
|
655
|
-
|
|
655
|
+
middleware?: MiddlewareFunction[];
|
|
656
656
|
loader?: LoaderFunction | boolean;
|
|
657
657
|
action?: ActionFunction | boolean;
|
|
658
658
|
hasErrorBoundary?: boolean;
|
|
@@ -1299,7 +1299,6 @@ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "e
|
|
|
1299
1299
|
* Future flags to toggle new feature behavior
|
|
1300
1300
|
*/
|
|
1301
1301
|
interface FutureConfig {
|
|
1302
|
-
unstable_middleware: boolean;
|
|
1303
1302
|
}
|
|
1304
1303
|
/**
|
|
1305
1304
|
* Initialization options for createRouter
|
|
@@ -1308,7 +1307,7 @@ interface RouterInit {
|
|
|
1308
1307
|
routes: AgnosticRouteObject[];
|
|
1309
1308
|
history: History;
|
|
1310
1309
|
basename?: string;
|
|
1311
|
-
|
|
1310
|
+
getContext?: () => MaybePromise<RouterContextProvider>;
|
|
1312
1311
|
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
1313
1312
|
future?: Partial<FutureConfig>;
|
|
1314
1313
|
hydrationRouteProperties?: string[];
|
|
@@ -1343,13 +1342,15 @@ interface StaticHandler {
|
|
|
1343
1342
|
skipLoaderErrorBubbling?: boolean;
|
|
1344
1343
|
skipRevalidation?: boolean;
|
|
1345
1344
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
1346
|
-
|
|
1345
|
+
generateMiddlewareResponse?: (query: (r: Request, args?: {
|
|
1346
|
+
filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
|
|
1347
|
+
}) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
1347
1348
|
}): Promise<StaticHandlerContext | Response>;
|
|
1348
1349
|
queryRoute(request: Request, opts?: {
|
|
1349
1350
|
routeId?: string;
|
|
1350
1351
|
requestContext?: unknown;
|
|
1351
1352
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
1352
|
-
|
|
1353
|
+
generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
1353
1354
|
}): Promise<any>;
|
|
1354
1355
|
}
|
|
1355
1356
|
type ViewTransitionOpts = {
|
|
@@ -1596,13 +1597,13 @@ interface MemoryRouterOpts {
|
|
|
1596
1597
|
*/
|
|
1597
1598
|
basename?: string;
|
|
1598
1599
|
/**
|
|
1599
|
-
* A function that returns an {@link
|
|
1600
|
+
* A function that returns an {@link RouterContextProvider} instance
|
|
1600
1601
|
* which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
|
|
1601
1602
|
* [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
|
|
1602
1603
|
* This function is called to generate a fresh `context` instance on each
|
|
1603
1604
|
* navigation or fetcher call.
|
|
1604
1605
|
*/
|
|
1605
|
-
|
|
1606
|
+
getContext?: RouterInit["getContext"];
|
|
1606
1607
|
/**
|
|
1607
1608
|
* Future flags to enable for the router.
|
|
1608
1609
|
*/
|
|
@@ -1643,7 +1644,7 @@ interface MemoryRouterOpts {
|
|
|
1643
1644
|
* @param {MemoryRouterOpts.basename} opts.basename n/a
|
|
1644
1645
|
* @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
|
|
1645
1646
|
* @param {MemoryRouterOpts.future} opts.future n/a
|
|
1646
|
-
* @param {MemoryRouterOpts.
|
|
1647
|
+
* @param {MemoryRouterOpts.getContext} opts.getContext n/a
|
|
1647
1648
|
* @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
|
|
1648
1649
|
* @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
|
|
1649
1650
|
* @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
|
|
@@ -2423,7 +2424,7 @@ interface IndexRouteObject {
|
|
|
2423
2424
|
caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
|
|
2424
2425
|
path?: AgnosticIndexRouteObject["path"];
|
|
2425
2426
|
id?: AgnosticIndexRouteObject["id"];
|
|
2426
|
-
|
|
2427
|
+
middleware?: AgnosticIndexRouteObject["middleware"];
|
|
2427
2428
|
loader?: AgnosticIndexRouteObject["loader"];
|
|
2428
2429
|
action?: AgnosticIndexRouteObject["action"];
|
|
2429
2430
|
hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
|
|
@@ -2443,7 +2444,7 @@ interface NonIndexRouteObject {
|
|
|
2443
2444
|
caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
|
|
2444
2445
|
path?: AgnosticNonIndexRouteObject["path"];
|
|
2445
2446
|
id?: AgnosticNonIndexRouteObject["id"];
|
|
2446
|
-
|
|
2447
|
+
middleware?: AgnosticNonIndexRouteObject["middleware"];
|
|
2447
2448
|
loader?: AgnosticNonIndexRouteObject["loader"];
|
|
2448
2449
|
action?: AgnosticNonIndexRouteObject["action"];
|
|
2449
2450
|
hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
|
|
@@ -2537,4 +2538,4 @@ interface RouteContextObject {
|
|
|
2537
2538
|
}
|
|
2538
2539
|
declare const RouteContext: React.Context<RouteContextObject>;
|
|
2539
2540
|
|
|
2540
|
-
export { type
|
|
2541
|
+
export { type DataStrategyMatch as $, type ActionFunctionArgs as A, type BlockerFunction as B, type PatchRoutesOnNavigationFunction as C, type DataStrategyResult as D, type ErrorBoundaryType as E, type DataRouteObject as F, type StaticHandler as G, type HydrationState as H, type InitialEntry as I, type GetScrollPositionFunction as J, type GetScrollRestorationKeyFunction as K, type Location as L, type MiddlewareNextFunction as M, type NavigateOptions as N, type StaticHandlerContext as O, type Params as P, type Fetcher as Q, type RouterProviderProps as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type NavigationStates as V, type RouterSubscriber as W, type RouterNavigateOptions as X, type RouterFetchOptions as Y, type RevalidationState as Z, type DataStrategyFunctionArgs as _, type RouterInit as a, mapRouteProperties as a$, type ErrorResponse as a0, type FormEncType as a1, type FormMethod as a2, type HTMLFormMethod as a3, type LazyRouteFunction as a4, type PathParam as a5, type RedirectFunction as a6, type RouterContext as a7, type ShouldRevalidateFunctionArgs as a8, createContext as a9, type RouterProps as aA, type RoutesProps as aB, Await as aC, MemoryRouter as aD, Navigate as aE, Outlet as aF, Route as aG, Router as aH, RouterProvider as aI, Routes as aJ, createMemoryRouter as aK, createRoutesFromChildren as aL, createRoutesFromElements as aM, renderMatches as aN, type Future as aO, createBrowserHistory as aP, invariant as aQ, createRouter as aR, ErrorResponseImpl as aS, DataRouterContext as aT, DataRouterStateContext as aU, FetchersContext as aV, LocationContext as aW, NavigationContext as aX, RouteContext as aY, ViewTransitionContext as aZ, hydrationRouteProperties as a_, createPath as aa, parsePath as ab, IDLE_NAVIGATION as ac, IDLE_FETCHER as ad, IDLE_BLOCKER as ae, data as af, generatePath as ag, isRouteErrorResponse as ah, matchPath as ai, matchRoutes as aj, redirect as ak, redirectDocument as al, replace as am, resolvePath as an, type Navigator as ao, type PatchRoutesOnNavigationFunctionArgs as ap, type RouteMatch as aq, type AwaitProps as ar, type IndexRouteProps as as, type LayoutRouteProps as at, type MemoryRouterOpts as au, type MemoryRouterProps as av, type NavigateProps as aw, type OutletProps as ax, type PathRouteProps as ay, type RouteProps as az, type LoaderFunctionArgs as b, WithComponentProps as b0, withComponentProps as b1, WithHydrateFallbackProps as b2, withHydrateFallbackProps as b3, WithErrorBoundaryProps as b4, withErrorBoundaryProps as b5, type RouteManifest as b6, type History as b7, type FutureConfig as b8, type CreateStaticHandlerOptions as b9, type ActionFunction as c, type LoaderFunction as d, type DataRouteMatch as e, type MiddlewareFunction as f, RouterContextProvider as g, DataWithResponseInit as h, type MiddlewareEnabled as i, type Router$1 as j, type DataStrategyFunction as k, type Blocker as l, type RelativeRoutingType as m, type ParamParseKey as n, type Path as o, type PathPattern as p, type PathMatch as q, type Navigation as r, Action as s, type RouteObject as t, type unstable_ClientOnErrorFunction as u, type IndexRouteObject as v, type RouteComponentType as w, type HydrateFallbackType as x, type NonIndexRouteObject as y, type RouterState as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { R as RouterProviderProps$1, a as RouterInit, u as unstable_ClientOnErrorFunction } from './context-
|
|
2
|
+
import { R as RouterProviderProps$1, a as RouterInit, u as unstable_ClientOnErrorFunction } from './context-EwD9faH7.mjs';
|
|
3
3
|
import './browser-z32v5KVN.mjs';
|
|
4
4
|
|
|
5
5
|
type RouterProviderProps = Omit<RouterProviderProps$1, "flushSync">;
|
|
@@ -17,7 +17,7 @@ interface HydratedRouterProps {
|
|
|
17
17
|
* [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
|
|
18
18
|
* functions
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
getContext?: RouterInit["getContext"];
|
|
21
21
|
/**
|
|
22
22
|
* An error handler function that will be called for any loader/action/render
|
|
23
23
|
* errors that are encountered in your application. This is useful for
|
|
@@ -45,7 +45,7 @@ interface HydratedRouterProps {
|
|
|
45
45
|
* @category Framework Routers
|
|
46
46
|
* @mode framework
|
|
47
47
|
* @param props Props
|
|
48
|
-
* @param {dom.HydratedRouterProps.
|
|
48
|
+
* @param {dom.HydratedRouterProps.getContext} props.getContext n/a
|
|
49
49
|
* @param {dom.HydratedRouterProps.unstable_onError} props.unstable_onError n/a
|
|
50
50
|
* @returns A React element that represents the hydrated application.
|
|
51
51
|
*/
|
|
@@ -16,7 +16,7 @@ interface HydratedRouterProps {
|
|
|
16
16
|
* [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
|
|
17
17
|
* functions
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
getContext?: RouterInit["getContext"];
|
|
20
20
|
/**
|
|
21
21
|
* An error handler function that will be called for any loader/action/render
|
|
22
22
|
* errors that are encountered in your application. This is useful for
|
|
@@ -44,7 +44,7 @@ interface HydratedRouterProps {
|
|
|
44
44
|
* @category Framework Routers
|
|
45
45
|
* @mode framework
|
|
46
46
|
* @param props Props
|
|
47
|
-
* @param {dom.HydratedRouterProps.
|
|
47
|
+
* @param {dom.HydratedRouterProps.getContext} props.getContext n/a
|
|
48
48
|
* @param {dom.HydratedRouterProps.unstable_onError} props.unstable_onError n/a
|
|
49
49
|
* @returns A React element that represents the hydrated application.
|
|
50
50
|
*/
|