react-router 7.8.2 → 7.9.0-pre.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 +22 -0
- package/dist/development/{chunk-5UALIXAM.mjs → chunk-3TJX7VNY.mjs} +93 -57
- package/dist/development/{chunk-CSDGKXLR.js → chunk-4J2JOVAI.js} +135 -135
- package/dist/development/{chunk-PVWAREVJ.mjs → chunk-EAIS2CTK.mjs} +43 -44
- package/dist/development/{chunk-ZO66TDGB.js → chunk-ECJT65VE.js} +37 -38
- package/dist/{production/context-jKip1TFB.d.mts → development/context-BH6Jwdoy.d.mts} +39 -32
- package/dist/development/dom-export.d.mts +3 -3
- package/dist/development/dom-export.d.ts +2 -2
- package/dist/development/dom-export.js +14 -14
- package/dist/development/dom-export.mjs +14 -14
- package/dist/development/{index-react-server-client-DRhjXpk2.d.mts → index-react-server-client-1cWMpKk4.d.mts} +13 -13
- package/dist/{production/index-react-server-client-BKpa2trA.d.ts → development/index-react-server-client-CMC2eQAY.d.ts} +12 -12
- 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 +4 -4
- package/dist/development/index-react-server.d.mts +229 -37
- package/dist/development/index-react-server.d.ts +229 -37
- package/dist/development/index-react-server.js +89 -39
- package/dist/development/index-react-server.mjs +88 -36
- package/dist/development/index.d.mts +31 -24
- package/dist/development/index.d.ts +29 -22
- package/dist/development/index.js +182 -144
- package/dist/development/index.mjs +9 -7
- package/dist/development/lib/types/internal.d.mts +6 -6
- package/dist/development/lib/types/internal.d.ts +5 -5
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/{route-data-DAVP2QQ0.d.mts → route-data-BQkq8Erj.d.mts} +12 -12
- package/dist/development/{routeModules-rOzWJJ9x.d.ts → routeModules-DSKAn01V.d.ts} +175 -168
- package/dist/production/{chunk-REDRD2MB.mjs → chunk-47NS5WEV.mjs} +43 -44
- package/dist/production/{chunk-JNT5PWCQ.js → chunk-CSESPFUI.js} +135 -135
- package/dist/production/{chunk-Z56HUDN5.js → chunk-LQAK2UKE.js} +37 -38
- package/dist/production/{chunk-KWHRV2I7.mjs → chunk-SCSBSW2J.mjs} +93 -57
- package/dist/{development/context-jKip1TFB.d.mts → production/context-BH6Jwdoy.d.mts} +39 -32
- package/dist/production/dom-export.d.mts +3 -3
- package/dist/production/dom-export.d.ts +2 -2
- package/dist/production/dom-export.js +14 -14
- package/dist/production/dom-export.mjs +14 -14
- package/dist/production/{index-react-server-client-DRhjXpk2.d.mts → index-react-server-client-1cWMpKk4.d.mts} +13 -13
- package/dist/{development/index-react-server-client-BKpa2trA.d.ts → production/index-react-server-client-CMC2eQAY.d.ts} +12 -12
- 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 +4 -4
- package/dist/production/index-react-server.d.mts +229 -37
- package/dist/production/index-react-server.d.ts +229 -37
- package/dist/production/index-react-server.js +89 -39
- package/dist/production/index-react-server.mjs +88 -36
- package/dist/production/index.d.mts +31 -24
- package/dist/production/index.d.ts +29 -22
- package/dist/production/index.js +182 -144
- package/dist/production/index.mjs +9 -7
- package/dist/production/lib/types/internal.d.mts +6 -6
- package/dist/production/lib/types/internal.d.ts +5 -5
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/production/{route-data-DAVP2QQ0.d.mts → route-data-BQkq8Erj.d.mts} +12 -12
- package/dist/production/{routeModules-rOzWJJ9x.d.ts → routeModules-DSKAn01V.d.ts} +175 -168
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* react-router v7.
|
|
30
|
+
* react-router v7.9.0-pre.0
|
|
31
31
|
*
|
|
32
32
|
* Copyright (c) Remix Software Inc.
|
|
33
33
|
*
|
|
@@ -108,13 +108,13 @@ function parsePath(path) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
// lib/router/utils.ts
|
|
111
|
-
function
|
|
111
|
+
function createContext(defaultValue) {
|
|
112
112
|
return { defaultValue };
|
|
113
113
|
}
|
|
114
114
|
var _map;
|
|
115
|
-
var
|
|
115
|
+
var RouterContextProvider = class {
|
|
116
116
|
/**
|
|
117
|
-
* Create a new `
|
|
117
|
+
* Create a new `RouterContextProvider` instance
|
|
118
118
|
* @param init An optional initial context map to populate the provider with
|
|
119
119
|
*/
|
|
120
120
|
constructor(init) {
|
|
@@ -174,7 +174,7 @@ var unsupportedLazyRouteFunctionKeys = /* @__PURE__ */ new Set([
|
|
|
174
174
|
"path",
|
|
175
175
|
"id",
|
|
176
176
|
"index",
|
|
177
|
-
"
|
|
177
|
+
"middleware",
|
|
178
178
|
"children"
|
|
179
179
|
]);
|
|
180
180
|
function isUnsupportedLazyRouteFunctionKey(key) {
|
|
@@ -695,13 +695,13 @@ function createStaticHandler(routes, opts) {
|
|
|
695
695
|
skipLoaderErrorBubbling,
|
|
696
696
|
skipRevalidation,
|
|
697
697
|
dataStrategy,
|
|
698
|
-
|
|
698
|
+
generateMiddlewareResponse
|
|
699
699
|
} = {}) {
|
|
700
700
|
let url = new URL(request.url);
|
|
701
701
|
let method = request.method;
|
|
702
702
|
let location = createLocation("", createPath(url), null, "default");
|
|
703
703
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
704
|
-
requestContext = requestContext != null ? requestContext : new
|
|
704
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
705
705
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
706
706
|
let error = getInternalRouterError(405, { method });
|
|
707
707
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -739,8 +739,8 @@ function createStaticHandler(routes, opts) {
|
|
|
739
739
|
}
|
|
740
740
|
if (generateMiddlewareResponse) {
|
|
741
741
|
invariant(
|
|
742
|
-
requestContext instanceof
|
|
743
|
-
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `
|
|
742
|
+
requestContext instanceof RouterContextProvider,
|
|
743
|
+
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
744
744
|
);
|
|
745
745
|
try {
|
|
746
746
|
await loadLazyMiddlewareForMatches(
|
|
@@ -769,7 +769,7 @@ function createStaticHandler(routes, opts) {
|
|
|
769
769
|
dataStrategy || null,
|
|
770
770
|
skipLoaderErrorBubbling === true,
|
|
771
771
|
null,
|
|
772
|
-
"filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : null,
|
|
772
|
+
"filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : filterMatchesToLoad ?? null,
|
|
773
773
|
skipRevalidation === true
|
|
774
774
|
);
|
|
775
775
|
if (isResponse(result2)) {
|
|
@@ -867,13 +867,13 @@ function createStaticHandler(routes, opts) {
|
|
|
867
867
|
routeId,
|
|
868
868
|
requestContext,
|
|
869
869
|
dataStrategy,
|
|
870
|
-
|
|
870
|
+
generateMiddlewareResponse
|
|
871
871
|
} = {}) {
|
|
872
872
|
let url = new URL(request.url);
|
|
873
873
|
let method = request.method;
|
|
874
874
|
let location = createLocation("", createPath(url), null, "default");
|
|
875
875
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
876
|
-
requestContext = requestContext != null ? requestContext : new
|
|
876
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
877
877
|
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
|
878
878
|
throw getInternalRouterError(405, { method });
|
|
879
879
|
} else if (!matches) {
|
|
@@ -890,8 +890,8 @@ function createStaticHandler(routes, opts) {
|
|
|
890
890
|
}
|
|
891
891
|
if (generateMiddlewareResponse) {
|
|
892
892
|
invariant(
|
|
893
|
-
requestContext instanceof
|
|
894
|
-
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `
|
|
893
|
+
requestContext instanceof RouterContextProvider,
|
|
894
|
+
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
895
895
|
);
|
|
896
896
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties);
|
|
897
897
|
let response = await runServerMiddlewarePipeline(
|
|
@@ -1349,12 +1349,12 @@ var loadLazyRouteProperty = ({
|
|
|
1349
1349
|
if (!lazyFn) {
|
|
1350
1350
|
return;
|
|
1351
1351
|
}
|
|
1352
|
-
let
|
|
1353
|
-
if (!
|
|
1354
|
-
|
|
1355
|
-
lazyRoutePropertyCache.set(routeToUpdate,
|
|
1352
|
+
let cache2 = lazyRoutePropertyCache.get(routeToUpdate);
|
|
1353
|
+
if (!cache2) {
|
|
1354
|
+
cache2 = {};
|
|
1355
|
+
lazyRoutePropertyCache.set(routeToUpdate, cache2);
|
|
1356
1356
|
}
|
|
1357
|
-
let cachedPromise =
|
|
1357
|
+
let cachedPromise = cache2[key];
|
|
1358
1358
|
if (cachedPromise) {
|
|
1359
1359
|
return cachedPromise;
|
|
1360
1360
|
}
|
|
@@ -1367,7 +1367,7 @@ var loadLazyRouteProperty = ({
|
|
|
1367
1367
|
!isUnsupported,
|
|
1368
1368
|
"Route property " + key + " is not a supported lazy route property. This property will be ignored."
|
|
1369
1369
|
);
|
|
1370
|
-
|
|
1370
|
+
cache2[key] = Promise.resolve();
|
|
1371
1371
|
} else if (isStaticallyDefined) {
|
|
1372
1372
|
warning(
|
|
1373
1373
|
false,
|
|
@@ -1387,7 +1387,7 @@ var loadLazyRouteProperty = ({
|
|
|
1387
1387
|
}
|
|
1388
1388
|
}
|
|
1389
1389
|
})();
|
|
1390
|
-
|
|
1390
|
+
cache2[key] = propertyPromise;
|
|
1391
1391
|
return propertyPromise;
|
|
1392
1392
|
};
|
|
1393
1393
|
var lazyRouteFunctionCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -1492,11 +1492,11 @@ function isNonNullable(value) {
|
|
|
1492
1492
|
}
|
|
1493
1493
|
function loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties) {
|
|
1494
1494
|
let promises = matches.map(({ route }) => {
|
|
1495
|
-
if (typeof route.lazy !== "object" || !route.lazy.
|
|
1495
|
+
if (typeof route.lazy !== "object" || !route.lazy.middleware) {
|
|
1496
1496
|
return void 0;
|
|
1497
1497
|
}
|
|
1498
1498
|
return loadLazyRouteProperty({
|
|
1499
|
-
key: "
|
|
1499
|
+
key: "middleware",
|
|
1500
1500
|
route,
|
|
1501
1501
|
manifest,
|
|
1502
1502
|
mapRouteProperties
|
|
@@ -1528,7 +1528,7 @@ function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
|
1528
1528
|
async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
|
1529
1529
|
let { matches, request, params, context } = args;
|
|
1530
1530
|
let tuples = matches.flatMap(
|
|
1531
|
-
(m) => m.route.
|
|
1531
|
+
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
1532
1532
|
);
|
|
1533
1533
|
let result = await callRouteMiddleware(
|
|
1534
1534
|
{ request, params, context },
|
|
@@ -1591,7 +1591,7 @@ async function callRouteMiddleware(args, middlewares, handler, processResult, is
|
|
|
1591
1591
|
}
|
|
1592
1592
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
1593
1593
|
let lazyMiddlewarePromise = loadLazyRouteProperty({
|
|
1594
|
-
key: "
|
|
1594
|
+
key: "middleware",
|
|
1595
1595
|
route: match.route,
|
|
1596
1596
|
manifest,
|
|
1597
1597
|
mapRouteProperties
|
|
@@ -1691,15 +1691,15 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
1691
1691
|
context: scopedContext,
|
|
1692
1692
|
matches
|
|
1693
1693
|
};
|
|
1694
|
-
let
|
|
1694
|
+
let runClientMiddleware = () => {
|
|
1695
1695
|
throw new Error(
|
|
1696
|
-
"You cannot call `
|
|
1696
|
+
"You cannot call `runClientMiddleware()` from a static handler `dataStrategy`. Middleware is run outside of `dataStrategy` during SSR in order to bubble up the Response. You can enable middleware via the `respond` API in `query`/`queryRoute`"
|
|
1697
1697
|
);
|
|
1698
1698
|
} ;
|
|
1699
1699
|
let results = await dataStrategyImpl({
|
|
1700
1700
|
...dataStrategyArgs,
|
|
1701
1701
|
fetcherKey,
|
|
1702
|
-
|
|
1702
|
+
runClientMiddleware
|
|
1703
1703
|
});
|
|
1704
1704
|
try {
|
|
1705
1705
|
await Promise.all(
|
|
@@ -2178,6 +2178,34 @@ var replace2 = (...args) => {
|
|
|
2178
2178
|
}
|
|
2179
2179
|
return response;
|
|
2180
2180
|
};
|
|
2181
|
+
var cachedResolvePromise = (
|
|
2182
|
+
// @ts-expect-error - on 18 types, requires 19.
|
|
2183
|
+
React2__namespace.cache(async (resolve) => {
|
|
2184
|
+
return Promise.allSettled([resolve]).then((r) => r[0]);
|
|
2185
|
+
})
|
|
2186
|
+
);
|
|
2187
|
+
var Await = async ({
|
|
2188
|
+
children,
|
|
2189
|
+
resolve,
|
|
2190
|
+
errorElement
|
|
2191
|
+
}) => {
|
|
2192
|
+
let promise = cachedResolvePromise(resolve);
|
|
2193
|
+
let resolved = await promise;
|
|
2194
|
+
if (resolved.status === "rejected" && !errorElement) {
|
|
2195
|
+
throw resolved.reason;
|
|
2196
|
+
}
|
|
2197
|
+
if (resolved.status === "rejected") {
|
|
2198
|
+
return React2__namespace.createElement(reactServerClient.UNSAFE_AwaitContextProvider, {
|
|
2199
|
+
children: React2__namespace.createElement(React2__namespace.Fragment, null, errorElement),
|
|
2200
|
+
value: { _tracked: true, _error: resolved.reason }
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
const toRender = typeof children === "function" ? children(resolved.value) : children;
|
|
2204
|
+
return React2__namespace.createElement(reactServerClient.UNSAFE_AwaitContextProvider, {
|
|
2205
|
+
children: toRender,
|
|
2206
|
+
value: { _tracked: true, _data: resolved.value }
|
|
2207
|
+
});
|
|
2208
|
+
};
|
|
2181
2209
|
async function matchRSCServerRequest({
|
|
2182
2210
|
createTemporaryReferenceSet,
|
|
2183
2211
|
basename,
|
|
@@ -2382,7 +2410,7 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2382
2410
|
let response = await staticHandler.queryRoute(request, {
|
|
2383
2411
|
routeId,
|
|
2384
2412
|
requestContext,
|
|
2385
|
-
async
|
|
2413
|
+
async generateMiddlewareResponse(queryRoute) {
|
|
2386
2414
|
try {
|
|
2387
2415
|
let response2 = await queryRoute(request);
|
|
2388
2416
|
return generateResourceResponse2(response2);
|
|
@@ -2443,10 +2471,8 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2443
2471
|
requestContext,
|
|
2444
2472
|
skipLoaderErrorBubbling: isDataRequest,
|
|
2445
2473
|
skipRevalidation: isSubmission,
|
|
2446
|
-
...routeIdsToLoad ? {
|
|
2447
|
-
|
|
2448
|
-
} : {},
|
|
2449
|
-
async unstable_generateMiddlewareResponse(query) {
|
|
2474
|
+
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : {},
|
|
2475
|
+
async generateMiddlewareResponse(query) {
|
|
2450
2476
|
let formState;
|
|
2451
2477
|
let skipRevalidation = false;
|
|
2452
2478
|
if (request.method === "POST") {
|
|
@@ -2857,6 +2883,32 @@ function canDecodeWithFormData(contentType) {
|
|
|
2857
2883
|
return contentType.match(/\bapplication\/x-www-form-urlencoded\b/) || contentType.match(/\bmultipart\/form-data\b/);
|
|
2858
2884
|
}
|
|
2859
2885
|
|
|
2886
|
+
// lib/href.ts
|
|
2887
|
+
function href(path, ...args) {
|
|
2888
|
+
let params = args[0];
|
|
2889
|
+
let result = path.replace(/\/*\*?$/, "").replace(
|
|
2890
|
+
/\/:([\w-]+)(\?)?/g,
|
|
2891
|
+
// same regex as in .\router\utils.ts: compilePath().
|
|
2892
|
+
(_, param, questionMark) => {
|
|
2893
|
+
const isRequired = questionMark === void 0;
|
|
2894
|
+
const value = params ? params[param] : void 0;
|
|
2895
|
+
if (isRequired && value === void 0) {
|
|
2896
|
+
throw new Error(
|
|
2897
|
+
`Path '${path}' requires param '${param}' but it was not provided`
|
|
2898
|
+
);
|
|
2899
|
+
}
|
|
2900
|
+
return value === void 0 ? "" : "/" + value;
|
|
2901
|
+
}
|
|
2902
|
+
);
|
|
2903
|
+
if (path.endsWith("*")) {
|
|
2904
|
+
const value = params ? params["*"] : void 0;
|
|
2905
|
+
if (value !== void 0) {
|
|
2906
|
+
result += "/" + value;
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
return result || "/";
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2860
2912
|
// lib/server-runtime/crypto.ts
|
|
2861
2913
|
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
2862
2914
|
var sign = async (value, secret) => {
|
|
@@ -3184,10 +3236,6 @@ function createMemorySessionStorage({ cookie } = {}) {
|
|
|
3184
3236
|
});
|
|
3185
3237
|
}
|
|
3186
3238
|
|
|
3187
|
-
Object.defineProperty(exports, "Await", {
|
|
3188
|
-
enumerable: true,
|
|
3189
|
-
get: function () { return reactServerClient.Await; }
|
|
3190
|
-
});
|
|
3191
3239
|
Object.defineProperty(exports, "BrowserRouter", {
|
|
3192
3240
|
enumerable: true,
|
|
3193
3241
|
get: function () { return reactServerClient.BrowserRouter; }
|
|
@@ -3260,6 +3308,9 @@ Object.defineProperty(exports, "unstable_HistoryRouter", {
|
|
|
3260
3308
|
enumerable: true,
|
|
3261
3309
|
get: function () { return reactServerClient.unstable_HistoryRouter; }
|
|
3262
3310
|
});
|
|
3311
|
+
exports.Await = Await;
|
|
3312
|
+
exports.RouterContextProvider = RouterContextProvider;
|
|
3313
|
+
exports.createContext = createContext;
|
|
3263
3314
|
exports.createCookie = createCookie;
|
|
3264
3315
|
exports.createCookieSessionStorage = createCookieSessionStorage;
|
|
3265
3316
|
exports.createMemorySessionStorage = createMemorySessionStorage;
|
|
@@ -3267,6 +3318,7 @@ exports.createSession = createSession;
|
|
|
3267
3318
|
exports.createSessionStorage = createSessionStorage;
|
|
3268
3319
|
exports.createStaticHandler = createStaticHandler;
|
|
3269
3320
|
exports.data = data;
|
|
3321
|
+
exports.href = href;
|
|
3270
3322
|
exports.isCookie = isCookie;
|
|
3271
3323
|
exports.isRouteErrorResponse = isRouteErrorResponse;
|
|
3272
3324
|
exports.isSession = isSession;
|
|
@@ -3274,6 +3326,4 @@ exports.matchRoutes = matchRoutes;
|
|
|
3274
3326
|
exports.redirect = redirect2;
|
|
3275
3327
|
exports.redirectDocument = redirectDocument2;
|
|
3276
3328
|
exports.replace = replace2;
|
|
3277
|
-
exports.unstable_RouterContextProvider = unstable_RouterContextProvider;
|
|
3278
|
-
exports.unstable_createContext = unstable_createContext;
|
|
3279
3329
|
exports.unstable_matchRSCServerRequest = matchRSCServerRequest;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import * as React2 from 'react';
|
|
3
3
|
import { splitCookiesString } from 'set-cookie-parser';
|
|
4
|
-
import { UNSAFE_WithComponentProps, Outlet as Outlet$1, UNSAFE_WithErrorBoundaryProps, UNSAFE_WithHydrateFallbackProps } from 'react-router/internal/react-server-client';
|
|
5
|
-
export {
|
|
4
|
+
import { UNSAFE_AwaitContextProvider, UNSAFE_WithComponentProps, Outlet as Outlet$1, UNSAFE_WithErrorBoundaryProps, UNSAFE_WithHydrateFallbackProps } from 'react-router/internal/react-server-client';
|
|
5
|
+
export { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from 'react-router/internal/react-server-client';
|
|
6
6
|
import { serialize, parse } from 'cookie';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* react-router v7.
|
|
9
|
+
* react-router v7.9.0-pre.0
|
|
10
10
|
*
|
|
11
11
|
* Copyright (c) Remix Software Inc.
|
|
12
12
|
*
|
|
@@ -87,13 +87,13 @@ function parsePath(path) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// lib/router/utils.ts
|
|
90
|
-
function
|
|
90
|
+
function createContext(defaultValue) {
|
|
91
91
|
return { defaultValue };
|
|
92
92
|
}
|
|
93
93
|
var _map;
|
|
94
|
-
var
|
|
94
|
+
var RouterContextProvider = class {
|
|
95
95
|
/**
|
|
96
|
-
* Create a new `
|
|
96
|
+
* Create a new `RouterContextProvider` instance
|
|
97
97
|
* @param init An optional initial context map to populate the provider with
|
|
98
98
|
*/
|
|
99
99
|
constructor(init) {
|
|
@@ -153,7 +153,7 @@ var unsupportedLazyRouteFunctionKeys = /* @__PURE__ */ new Set([
|
|
|
153
153
|
"path",
|
|
154
154
|
"id",
|
|
155
155
|
"index",
|
|
156
|
-
"
|
|
156
|
+
"middleware",
|
|
157
157
|
"children"
|
|
158
158
|
]);
|
|
159
159
|
function isUnsupportedLazyRouteFunctionKey(key) {
|
|
@@ -674,13 +674,13 @@ function createStaticHandler(routes, opts) {
|
|
|
674
674
|
skipLoaderErrorBubbling,
|
|
675
675
|
skipRevalidation,
|
|
676
676
|
dataStrategy,
|
|
677
|
-
|
|
677
|
+
generateMiddlewareResponse
|
|
678
678
|
} = {}) {
|
|
679
679
|
let url = new URL(request.url);
|
|
680
680
|
let method = request.method;
|
|
681
681
|
let location = createLocation("", createPath(url), null, "default");
|
|
682
682
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
683
|
-
requestContext = requestContext != null ? requestContext : new
|
|
683
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
684
684
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
685
685
|
let error = getInternalRouterError(405, { method });
|
|
686
686
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -718,8 +718,8 @@ function createStaticHandler(routes, opts) {
|
|
|
718
718
|
}
|
|
719
719
|
if (generateMiddlewareResponse) {
|
|
720
720
|
invariant(
|
|
721
|
-
requestContext instanceof
|
|
722
|
-
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `
|
|
721
|
+
requestContext instanceof RouterContextProvider,
|
|
722
|
+
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
723
723
|
);
|
|
724
724
|
try {
|
|
725
725
|
await loadLazyMiddlewareForMatches(
|
|
@@ -748,7 +748,7 @@ function createStaticHandler(routes, opts) {
|
|
|
748
748
|
dataStrategy || null,
|
|
749
749
|
skipLoaderErrorBubbling === true,
|
|
750
750
|
null,
|
|
751
|
-
"filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : null,
|
|
751
|
+
"filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : filterMatchesToLoad ?? null,
|
|
752
752
|
skipRevalidation === true
|
|
753
753
|
);
|
|
754
754
|
if (isResponse(result2)) {
|
|
@@ -846,13 +846,13 @@ function createStaticHandler(routes, opts) {
|
|
|
846
846
|
routeId,
|
|
847
847
|
requestContext,
|
|
848
848
|
dataStrategy,
|
|
849
|
-
|
|
849
|
+
generateMiddlewareResponse
|
|
850
850
|
} = {}) {
|
|
851
851
|
let url = new URL(request.url);
|
|
852
852
|
let method = request.method;
|
|
853
853
|
let location = createLocation("", createPath(url), null, "default");
|
|
854
854
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
855
|
-
requestContext = requestContext != null ? requestContext : new
|
|
855
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
856
856
|
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
|
857
857
|
throw getInternalRouterError(405, { method });
|
|
858
858
|
} else if (!matches) {
|
|
@@ -869,8 +869,8 @@ function createStaticHandler(routes, opts) {
|
|
|
869
869
|
}
|
|
870
870
|
if (generateMiddlewareResponse) {
|
|
871
871
|
invariant(
|
|
872
|
-
requestContext instanceof
|
|
873
|
-
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `
|
|
872
|
+
requestContext instanceof RouterContextProvider,
|
|
873
|
+
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
874
874
|
);
|
|
875
875
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties);
|
|
876
876
|
let response = await runServerMiddlewarePipeline(
|
|
@@ -1328,12 +1328,12 @@ var loadLazyRouteProperty = ({
|
|
|
1328
1328
|
if (!lazyFn) {
|
|
1329
1329
|
return;
|
|
1330
1330
|
}
|
|
1331
|
-
let
|
|
1332
|
-
if (!
|
|
1333
|
-
|
|
1334
|
-
lazyRoutePropertyCache.set(routeToUpdate,
|
|
1331
|
+
let cache2 = lazyRoutePropertyCache.get(routeToUpdate);
|
|
1332
|
+
if (!cache2) {
|
|
1333
|
+
cache2 = {};
|
|
1334
|
+
lazyRoutePropertyCache.set(routeToUpdate, cache2);
|
|
1335
1335
|
}
|
|
1336
|
-
let cachedPromise =
|
|
1336
|
+
let cachedPromise = cache2[key];
|
|
1337
1337
|
if (cachedPromise) {
|
|
1338
1338
|
return cachedPromise;
|
|
1339
1339
|
}
|
|
@@ -1346,7 +1346,7 @@ var loadLazyRouteProperty = ({
|
|
|
1346
1346
|
!isUnsupported,
|
|
1347
1347
|
"Route property " + key + " is not a supported lazy route property. This property will be ignored."
|
|
1348
1348
|
);
|
|
1349
|
-
|
|
1349
|
+
cache2[key] = Promise.resolve();
|
|
1350
1350
|
} else if (isStaticallyDefined) {
|
|
1351
1351
|
warning(
|
|
1352
1352
|
false,
|
|
@@ -1366,7 +1366,7 @@ var loadLazyRouteProperty = ({
|
|
|
1366
1366
|
}
|
|
1367
1367
|
}
|
|
1368
1368
|
})();
|
|
1369
|
-
|
|
1369
|
+
cache2[key] = propertyPromise;
|
|
1370
1370
|
return propertyPromise;
|
|
1371
1371
|
};
|
|
1372
1372
|
var lazyRouteFunctionCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -1471,11 +1471,11 @@ function isNonNullable(value) {
|
|
|
1471
1471
|
}
|
|
1472
1472
|
function loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties) {
|
|
1473
1473
|
let promises = matches.map(({ route }) => {
|
|
1474
|
-
if (typeof route.lazy !== "object" || !route.lazy.
|
|
1474
|
+
if (typeof route.lazy !== "object" || !route.lazy.middleware) {
|
|
1475
1475
|
return void 0;
|
|
1476
1476
|
}
|
|
1477
1477
|
return loadLazyRouteProperty({
|
|
1478
|
-
key: "
|
|
1478
|
+
key: "middleware",
|
|
1479
1479
|
route,
|
|
1480
1480
|
manifest,
|
|
1481
1481
|
mapRouteProperties
|
|
@@ -1507,7 +1507,7 @@ function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
|
1507
1507
|
async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
|
1508
1508
|
let { matches, request, params, context } = args;
|
|
1509
1509
|
let tuples = matches.flatMap(
|
|
1510
|
-
(m) => m.route.
|
|
1510
|
+
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
1511
1511
|
);
|
|
1512
1512
|
let result = await callRouteMiddleware(
|
|
1513
1513
|
{ request, params, context },
|
|
@@ -1570,7 +1570,7 @@ async function callRouteMiddleware(args, middlewares, handler, processResult, is
|
|
|
1570
1570
|
}
|
|
1571
1571
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
1572
1572
|
let lazyMiddlewarePromise = loadLazyRouteProperty({
|
|
1573
|
-
key: "
|
|
1573
|
+
key: "middleware",
|
|
1574
1574
|
route: match.route,
|
|
1575
1575
|
manifest,
|
|
1576
1576
|
mapRouteProperties
|
|
@@ -1670,15 +1670,15 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
1670
1670
|
context: scopedContext,
|
|
1671
1671
|
matches
|
|
1672
1672
|
};
|
|
1673
|
-
let
|
|
1673
|
+
let runClientMiddleware = () => {
|
|
1674
1674
|
throw new Error(
|
|
1675
|
-
"You cannot call `
|
|
1675
|
+
"You cannot call `runClientMiddleware()` from a static handler `dataStrategy`. Middleware is run outside of `dataStrategy` during SSR in order to bubble up the Response. You can enable middleware via the `respond` API in `query`/`queryRoute`"
|
|
1676
1676
|
);
|
|
1677
1677
|
} ;
|
|
1678
1678
|
let results = await dataStrategyImpl({
|
|
1679
1679
|
...dataStrategyArgs,
|
|
1680
1680
|
fetcherKey,
|
|
1681
|
-
|
|
1681
|
+
runClientMiddleware
|
|
1682
1682
|
});
|
|
1683
1683
|
try {
|
|
1684
1684
|
await Promise.all(
|
|
@@ -2157,6 +2157,34 @@ var replace2 = (...args) => {
|
|
|
2157
2157
|
}
|
|
2158
2158
|
return response;
|
|
2159
2159
|
};
|
|
2160
|
+
var cachedResolvePromise = (
|
|
2161
|
+
// @ts-expect-error - on 18 types, requires 19.
|
|
2162
|
+
React2.cache(async (resolve) => {
|
|
2163
|
+
return Promise.allSettled([resolve]).then((r) => r[0]);
|
|
2164
|
+
})
|
|
2165
|
+
);
|
|
2166
|
+
var Await = async ({
|
|
2167
|
+
children,
|
|
2168
|
+
resolve,
|
|
2169
|
+
errorElement
|
|
2170
|
+
}) => {
|
|
2171
|
+
let promise = cachedResolvePromise(resolve);
|
|
2172
|
+
let resolved = await promise;
|
|
2173
|
+
if (resolved.status === "rejected" && !errorElement) {
|
|
2174
|
+
throw resolved.reason;
|
|
2175
|
+
}
|
|
2176
|
+
if (resolved.status === "rejected") {
|
|
2177
|
+
return React2.createElement(UNSAFE_AwaitContextProvider, {
|
|
2178
|
+
children: React2.createElement(React2.Fragment, null, errorElement),
|
|
2179
|
+
value: { _tracked: true, _error: resolved.reason }
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
const toRender = typeof children === "function" ? children(resolved.value) : children;
|
|
2183
|
+
return React2.createElement(UNSAFE_AwaitContextProvider, {
|
|
2184
|
+
children: toRender,
|
|
2185
|
+
value: { _tracked: true, _data: resolved.value }
|
|
2186
|
+
});
|
|
2187
|
+
};
|
|
2160
2188
|
async function matchRSCServerRequest({
|
|
2161
2189
|
createTemporaryReferenceSet,
|
|
2162
2190
|
basename,
|
|
@@ -2361,7 +2389,7 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2361
2389
|
let response = await staticHandler.queryRoute(request, {
|
|
2362
2390
|
routeId,
|
|
2363
2391
|
requestContext,
|
|
2364
|
-
async
|
|
2392
|
+
async generateMiddlewareResponse(queryRoute) {
|
|
2365
2393
|
try {
|
|
2366
2394
|
let response2 = await queryRoute(request);
|
|
2367
2395
|
return generateResourceResponse2(response2);
|
|
@@ -2422,10 +2450,8 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2422
2450
|
requestContext,
|
|
2423
2451
|
skipLoaderErrorBubbling: isDataRequest,
|
|
2424
2452
|
skipRevalidation: isSubmission,
|
|
2425
|
-
...routeIdsToLoad ? {
|
|
2426
|
-
|
|
2427
|
-
} : {},
|
|
2428
|
-
async unstable_generateMiddlewareResponse(query) {
|
|
2453
|
+
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : {},
|
|
2454
|
+
async generateMiddlewareResponse(query) {
|
|
2429
2455
|
let formState;
|
|
2430
2456
|
let skipRevalidation = false;
|
|
2431
2457
|
if (request.method === "POST") {
|
|
@@ -2836,6 +2862,32 @@ function canDecodeWithFormData(contentType) {
|
|
|
2836
2862
|
return contentType.match(/\bapplication\/x-www-form-urlencoded\b/) || contentType.match(/\bmultipart\/form-data\b/);
|
|
2837
2863
|
}
|
|
2838
2864
|
|
|
2865
|
+
// lib/href.ts
|
|
2866
|
+
function href(path, ...args) {
|
|
2867
|
+
let params = args[0];
|
|
2868
|
+
let result = path.replace(/\/*\*?$/, "").replace(
|
|
2869
|
+
/\/:([\w-]+)(\?)?/g,
|
|
2870
|
+
// same regex as in .\router\utils.ts: compilePath().
|
|
2871
|
+
(_, param, questionMark) => {
|
|
2872
|
+
const isRequired = questionMark === void 0;
|
|
2873
|
+
const value = params ? params[param] : void 0;
|
|
2874
|
+
if (isRequired && value === void 0) {
|
|
2875
|
+
throw new Error(
|
|
2876
|
+
`Path '${path}' requires param '${param}' but it was not provided`
|
|
2877
|
+
);
|
|
2878
|
+
}
|
|
2879
|
+
return value === void 0 ? "" : "/" + value;
|
|
2880
|
+
}
|
|
2881
|
+
);
|
|
2882
|
+
if (path.endsWith("*")) {
|
|
2883
|
+
const value = params ? params["*"] : void 0;
|
|
2884
|
+
if (value !== void 0) {
|
|
2885
|
+
result += "/" + value;
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
return result || "/";
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2839
2891
|
// lib/server-runtime/crypto.ts
|
|
2840
2892
|
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
2841
2893
|
var sign = async (value, secret) => {
|
|
@@ -3163,4 +3215,4 @@ function createMemorySessionStorage({ cookie } = {}) {
|
|
|
3163
3215
|
});
|
|
3164
3216
|
}
|
|
3165
3217
|
|
|
3166
|
-
export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, createStaticHandler, data, isCookie, isRouteErrorResponse, isSession, matchRoutes, redirect2 as redirect, redirectDocument2 as redirectDocument, replace2 as replace,
|
|
3218
|
+
export { Await, RouterContextProvider, createContext, createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, createStaticHandler, data, href, isCookie, isRouteErrorResponse, isSession, matchRoutes, redirect2 as redirect, redirectDocument2 as redirectDocument, replace2 as replace, matchRSCServerRequest as unstable_matchRSCServerRequest };
|