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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v7.
|
|
2
|
+
* react-router v7.9.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -362,13 +362,13 @@ function createBrowserURLImpl(to, isAbsolute = false) {
|
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
// lib/router/utils.ts
|
|
365
|
-
function
|
|
365
|
+
function createContext(defaultValue) {
|
|
366
366
|
return { defaultValue };
|
|
367
367
|
}
|
|
368
368
|
var _map;
|
|
369
|
-
var
|
|
369
|
+
var RouterContextProvider = class {
|
|
370
370
|
/**
|
|
371
|
-
* Create a new `
|
|
371
|
+
* Create a new `RouterContextProvider` instance
|
|
372
372
|
* @param init An optional initial context map to populate the provider with
|
|
373
373
|
*/
|
|
374
374
|
constructor(init) {
|
|
@@ -428,7 +428,7 @@ var unsupportedLazyRouteFunctionKeys = /* @__PURE__ */ new Set([
|
|
|
428
428
|
"path",
|
|
429
429
|
"id",
|
|
430
430
|
"index",
|
|
431
|
-
"
|
|
431
|
+
"middleware",
|
|
432
432
|
"children"
|
|
433
433
|
]);
|
|
434
434
|
function isUnsupportedLazyRouteFunctionKey(key) {
|
|
@@ -1466,7 +1466,7 @@ function createRouter(init) {
|
|
|
1466
1466
|
pendingNavigationController.signal,
|
|
1467
1467
|
opts && opts.submission
|
|
1468
1468
|
);
|
|
1469
|
-
let scopedContext = init.
|
|
1469
|
+
let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
|
|
1470
1470
|
let pendingActionResult;
|
|
1471
1471
|
if (opts && opts.pendingError) {
|
|
1472
1472
|
pendingActionResult = [
|
|
@@ -1756,7 +1756,7 @@ function createRouter(init) {
|
|
|
1756
1756
|
pendingActionResult
|
|
1757
1757
|
);
|
|
1758
1758
|
pendingNavigationLoadId = ++incrementingLoadId;
|
|
1759
|
-
if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.
|
|
1759
|
+
if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.middleware) && revalidatingFetchers.length === 0) {
|
|
1760
1760
|
let updatedFetchers2 = markFetchRedirectsDone();
|
|
1761
1761
|
completeNavigation(
|
|
1762
1762
|
location,
|
|
@@ -1910,7 +1910,7 @@ function createRouter(init) {
|
|
|
1910
1910
|
setFetcherError(key, routeId, error, { flushSync });
|
|
1911
1911
|
return;
|
|
1912
1912
|
}
|
|
1913
|
-
let scopedContext = init.
|
|
1913
|
+
let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
|
|
1914
1914
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1915
1915
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1916
1916
|
await handleFetcherAction(
|
|
@@ -2761,13 +2761,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2761
2761
|
skipLoaderErrorBubbling,
|
|
2762
2762
|
skipRevalidation,
|
|
2763
2763
|
dataStrategy,
|
|
2764
|
-
|
|
2764
|
+
generateMiddlewareResponse
|
|
2765
2765
|
} = {}) {
|
|
2766
2766
|
let url = new URL(request.url);
|
|
2767
2767
|
let method = request.method;
|
|
2768
2768
|
let location = createLocation("", createPath(url), null, "default");
|
|
2769
2769
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2770
|
-
requestContext = requestContext != null ? requestContext : new
|
|
2770
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
2771
2771
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2772
2772
|
let error = getInternalRouterError(405, { method });
|
|
2773
2773
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2805,8 +2805,8 @@ function createStaticHandler(routes, opts) {
|
|
|
2805
2805
|
}
|
|
2806
2806
|
if (generateMiddlewareResponse) {
|
|
2807
2807
|
invariant(
|
|
2808
|
-
requestContext instanceof
|
|
2809
|
-
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `
|
|
2808
|
+
requestContext instanceof RouterContextProvider,
|
|
2809
|
+
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
2810
2810
|
);
|
|
2811
2811
|
try {
|
|
2812
2812
|
await loadLazyMiddlewareForMatches(
|
|
@@ -2835,7 +2835,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2835
2835
|
dataStrategy || null,
|
|
2836
2836
|
skipLoaderErrorBubbling === true,
|
|
2837
2837
|
null,
|
|
2838
|
-
"filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : null,
|
|
2838
|
+
"filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : filterMatchesToLoad ?? null,
|
|
2839
2839
|
skipRevalidation === true
|
|
2840
2840
|
);
|
|
2841
2841
|
if (isResponse(result2)) {
|
|
@@ -2933,13 +2933,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2933
2933
|
routeId,
|
|
2934
2934
|
requestContext,
|
|
2935
2935
|
dataStrategy,
|
|
2936
|
-
|
|
2936
|
+
generateMiddlewareResponse
|
|
2937
2937
|
} = {}) {
|
|
2938
2938
|
let url = new URL(request.url);
|
|
2939
2939
|
let method = request.method;
|
|
2940
2940
|
let location = createLocation("", createPath(url), null, "default");
|
|
2941
2941
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2942
|
-
requestContext = requestContext != null ? requestContext : new
|
|
2942
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
2943
2943
|
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
|
2944
2944
|
throw getInternalRouterError(405, { method });
|
|
2945
2945
|
} else if (!matches) {
|
|
@@ -2956,8 +2956,8 @@ function createStaticHandler(routes, opts) {
|
|
|
2956
2956
|
}
|
|
2957
2957
|
if (generateMiddlewareResponse) {
|
|
2958
2958
|
invariant(
|
|
2959
|
-
requestContext instanceof
|
|
2960
|
-
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `
|
|
2959
|
+
requestContext instanceof RouterContextProvider,
|
|
2960
|
+
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
2961
2961
|
);
|
|
2962
2962
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2);
|
|
2963
2963
|
let response = await runServerMiddlewarePipeline(
|
|
@@ -3947,11 +3947,11 @@ function isNonNullable(value) {
|
|
|
3947
3947
|
}
|
|
3948
3948
|
function loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2) {
|
|
3949
3949
|
let promises = matches.map(({ route }) => {
|
|
3950
|
-
if (typeof route.lazy !== "object" || !route.lazy.
|
|
3950
|
+
if (typeof route.lazy !== "object" || !route.lazy.middleware) {
|
|
3951
3951
|
return void 0;
|
|
3952
3952
|
}
|
|
3953
3953
|
return loadLazyRouteProperty({
|
|
3954
|
-
key: "
|
|
3954
|
+
key: "middleware",
|
|
3955
3955
|
route,
|
|
3956
3956
|
manifest,
|
|
3957
3957
|
mapRouteProperties: mapRouteProperties2
|
|
@@ -3969,7 +3969,7 @@ async function defaultDataStrategy(args) {
|
|
|
3969
3969
|
return keyedResults;
|
|
3970
3970
|
}
|
|
3971
3971
|
async function defaultDataStrategyWithMiddleware(args) {
|
|
3972
|
-
if (!args.matches.some((m) => m.route.
|
|
3972
|
+
if (!args.matches.some((m) => m.route.middleware)) {
|
|
3973
3973
|
return defaultDataStrategy(args);
|
|
3974
3974
|
}
|
|
3975
3975
|
return runClientMiddlewarePipeline(args, () => defaultDataStrategy(args));
|
|
@@ -4023,7 +4023,7 @@ function runClientMiddlewarePipeline(args, handler) {
|
|
|
4023
4023
|
async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
|
4024
4024
|
let { matches, request, params, context } = args;
|
|
4025
4025
|
let tuples = matches.flatMap(
|
|
4026
|
-
(m) => m.route.
|
|
4026
|
+
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
4027
4027
|
);
|
|
4028
4028
|
let result = await callRouteMiddleware(
|
|
4029
4029
|
{ request, params, context },
|
|
@@ -4086,7 +4086,7 @@ async function callRouteMiddleware(args, middlewares, handler, processResult, is
|
|
|
4086
4086
|
}
|
|
4087
4087
|
function getDataStrategyMatchLazyPromises(mapRouteProperties2, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
4088
4088
|
let lazyMiddlewarePromise = loadLazyRouteProperty({
|
|
4089
|
-
key: "
|
|
4089
|
+
key: "middleware",
|
|
4090
4090
|
route: match.route,
|
|
4091
4091
|
manifest,
|
|
4092
4092
|
mapRouteProperties: mapRouteProperties2
|
|
@@ -4186,9 +4186,9 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4186
4186
|
context: scopedContext,
|
|
4187
4187
|
matches
|
|
4188
4188
|
};
|
|
4189
|
-
let
|
|
4189
|
+
let runClientMiddleware = isStaticHandler ? () => {
|
|
4190
4190
|
throw new Error(
|
|
4191
|
-
"You cannot call `
|
|
4191
|
+
"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`"
|
|
4192
4192
|
);
|
|
4193
4193
|
} : (cb) => {
|
|
4194
4194
|
let typedDataStrategyArgs = dataStrategyArgs;
|
|
@@ -4196,9 +4196,9 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4196
4196
|
return cb({
|
|
4197
4197
|
...typedDataStrategyArgs,
|
|
4198
4198
|
fetcherKey,
|
|
4199
|
-
|
|
4199
|
+
runClientMiddleware: () => {
|
|
4200
4200
|
throw new Error(
|
|
4201
|
-
"Cannot call `
|
|
4201
|
+
"Cannot call `runClientMiddleware()` from within an `runClientMiddleware` handler"
|
|
4202
4202
|
);
|
|
4203
4203
|
}
|
|
4204
4204
|
});
|
|
@@ -4207,7 +4207,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4207
4207
|
let results = await dataStrategyImpl({
|
|
4208
4208
|
...dataStrategyArgs,
|
|
4209
4209
|
fetcherKey,
|
|
4210
|
-
|
|
4210
|
+
runClientMiddleware
|
|
4211
4211
|
});
|
|
4212
4212
|
try {
|
|
4213
4213
|
await Promise.all(
|
|
@@ -4926,6 +4926,7 @@ var FetchersContext = React.createContext(
|
|
|
4926
4926
|
FetchersContext.displayName = "Fetchers";
|
|
4927
4927
|
var AwaitContext = React.createContext(null);
|
|
4928
4928
|
AwaitContext.displayName = "Await";
|
|
4929
|
+
var AwaitContextProvider = (props) => React.createElement(AwaitContext.Provider, props);
|
|
4929
4930
|
var NavigationContext = React.createContext(
|
|
4930
4931
|
null
|
|
4931
4932
|
);
|
|
@@ -5593,7 +5594,7 @@ var hydrationRouteProperties = [
|
|
|
5593
5594
|
function createMemoryRouter(routes, opts) {
|
|
5594
5595
|
return createRouter({
|
|
5595
5596
|
basename: opts?.basename,
|
|
5596
|
-
|
|
5597
|
+
getContext: opts?.getContext,
|
|
5597
5598
|
future: opts?.future,
|
|
5598
5599
|
history: createMemoryHistory({
|
|
5599
5600
|
initialEntries: opts?.initialEntries,
|
|
@@ -7097,7 +7098,7 @@ function getTurboStreamSingleFetchDataStrategy(getRouter, manifest, routeModules
|
|
|
7097
7098
|
ssr,
|
|
7098
7099
|
basename
|
|
7099
7100
|
);
|
|
7100
|
-
return async (args) => args.
|
|
7101
|
+
return async (args) => args.runClientMiddleware(dataStrategy);
|
|
7101
7102
|
}
|
|
7102
7103
|
function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, basename, shouldAllowOptOut = () => true) {
|
|
7103
7104
|
return async (args) => {
|
|
@@ -7893,7 +7894,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
7893
7894
|
Object.assign(dataRoute, {
|
|
7894
7895
|
...dataRoute,
|
|
7895
7896
|
...getRouteComponents(route, routeModule, isSpaMode),
|
|
7896
|
-
|
|
7897
|
+
middleware: routeModule.clientMiddleware,
|
|
7897
7898
|
handle: routeModule.handle,
|
|
7898
7899
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
7899
7900
|
dataRoute.path,
|
|
@@ -8035,17 +8036,14 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
8035
8036
|
}
|
|
8036
8037
|
});
|
|
8037
8038
|
} : void 0,
|
|
8038
|
-
|
|
8039
|
-
let {
|
|
8039
|
+
middleware: route.hasClientMiddleware ? async () => {
|
|
8040
|
+
let { clientMiddleware } = route.clientMiddlewareModule ? await import(
|
|
8040
8041
|
/* @vite-ignore */
|
|
8041
8042
|
/* webpackIgnore: true */
|
|
8042
8043
|
route.clientMiddlewareModule
|
|
8043
8044
|
) : await getLazyRoute();
|
|
8044
|
-
invariant2(
|
|
8045
|
-
|
|
8046
|
-
"No `unstable_clientMiddleware` export found"
|
|
8047
|
-
);
|
|
8048
|
-
return unstable_clientMiddleware;
|
|
8045
|
+
invariant2(clientMiddleware, "No `clientMiddleware` export found");
|
|
8046
|
+
return clientMiddleware;
|
|
8049
8047
|
} : void 0,
|
|
8050
8048
|
shouldRevalidate: async () => {
|
|
8051
8049
|
let lazyRoute = await getLazyRoute();
|
|
@@ -8126,7 +8124,7 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
|
|
8126
8124
|
return {
|
|
8127
8125
|
Component: getRouteModuleComponent(routeModule),
|
|
8128
8126
|
ErrorBoundary: routeModule.ErrorBoundary,
|
|
8129
|
-
|
|
8127
|
+
clientMiddleware: routeModule.clientMiddleware,
|
|
8130
8128
|
clientAction: routeModule.clientAction,
|
|
8131
8129
|
clientLoader: routeModule.clientLoader,
|
|
8132
8130
|
handle: routeModule.handle,
|
|
@@ -8969,14 +8967,14 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
|
|
|
8969
8967
|
try {
|
|
8970
8968
|
if (isBrowser) {
|
|
8971
8969
|
window.__reactRouterVersion = // @ts-expect-error
|
|
8972
|
-
"7.
|
|
8970
|
+
"7.9.0-pre.0";
|
|
8973
8971
|
}
|
|
8974
8972
|
} catch (e) {
|
|
8975
8973
|
}
|
|
8976
8974
|
function createBrowserRouter(routes, opts) {
|
|
8977
8975
|
return createRouter({
|
|
8978
8976
|
basename: opts?.basename,
|
|
8979
|
-
|
|
8977
|
+
getContext: opts?.getContext,
|
|
8980
8978
|
future: opts?.future,
|
|
8981
8979
|
history: createBrowserHistory({ window: opts?.window }),
|
|
8982
8980
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -8991,7 +8989,7 @@ function createBrowserRouter(routes, opts) {
|
|
|
8991
8989
|
function createHashRouter(routes, opts) {
|
|
8992
8990
|
return createRouter({
|
|
8993
8991
|
basename: opts?.basename,
|
|
8994
|
-
|
|
8992
|
+
getContext: opts?.getContext,
|
|
8995
8993
|
future: opts?.future,
|
|
8996
8994
|
history: createHashHistory({ window: opts?.window }),
|
|
8997
8995
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -9960,7 +9958,7 @@ function createStaticRouter(routes, context, opts = {}) {
|
|
|
9960
9958
|
},
|
|
9961
9959
|
get future() {
|
|
9962
9960
|
return {
|
|
9963
|
-
|
|
9961
|
+
v8_middleware: false,
|
|
9964
9962
|
...opts?.future
|
|
9965
9963
|
};
|
|
9966
9964
|
},
|
|
@@ -10066,8 +10064,8 @@ export {
|
|
|
10066
10064
|
invariant,
|
|
10067
10065
|
createPath,
|
|
10068
10066
|
parsePath,
|
|
10069
|
-
|
|
10070
|
-
|
|
10067
|
+
createContext,
|
|
10068
|
+
RouterContextProvider,
|
|
10071
10069
|
convertRoutesToDataRoutes,
|
|
10072
10070
|
matchRoutes,
|
|
10073
10071
|
generatePath,
|
|
@@ -10096,6 +10094,7 @@ export {
|
|
|
10096
10094
|
RSCRouterContext,
|
|
10097
10095
|
ViewTransitionContext,
|
|
10098
10096
|
FetchersContext,
|
|
10097
|
+
AwaitContextProvider,
|
|
10099
10098
|
NavigationContext,
|
|
10100
10099
|
LocationContext,
|
|
10101
10100
|
RouteContext,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
2
|
-
* react-router v7.
|
|
2
|
+
* react-router v7.9.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -362,13 +362,13 @@ function createBrowserURLImpl(to, isAbsolute = false) {
|
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
// lib/router/utils.ts
|
|
365
|
-
function
|
|
365
|
+
function createContext(defaultValue) {
|
|
366
366
|
return { defaultValue };
|
|
367
367
|
}
|
|
368
368
|
var _map;
|
|
369
|
-
var
|
|
369
|
+
var RouterContextProvider = class {
|
|
370
370
|
/**
|
|
371
|
-
* Create a new `
|
|
371
|
+
* Create a new `RouterContextProvider` instance
|
|
372
372
|
* @param init An optional initial context map to populate the provider with
|
|
373
373
|
*/
|
|
374
374
|
constructor(init) {
|
|
@@ -428,7 +428,7 @@ var unsupportedLazyRouteFunctionKeys = /* @__PURE__ */ new Set([
|
|
|
428
428
|
"path",
|
|
429
429
|
"id",
|
|
430
430
|
"index",
|
|
431
|
-
"
|
|
431
|
+
"middleware",
|
|
432
432
|
"children"
|
|
433
433
|
]);
|
|
434
434
|
function isUnsupportedLazyRouteFunctionKey(key) {
|
|
@@ -1466,7 +1466,7 @@ function createRouter(init) {
|
|
|
1466
1466
|
pendingNavigationController.signal,
|
|
1467
1467
|
opts && opts.submission
|
|
1468
1468
|
);
|
|
1469
|
-
let scopedContext = init.
|
|
1469
|
+
let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
|
|
1470
1470
|
let pendingActionResult;
|
|
1471
1471
|
if (opts && opts.pendingError) {
|
|
1472
1472
|
pendingActionResult = [
|
|
@@ -1756,7 +1756,7 @@ function createRouter(init) {
|
|
|
1756
1756
|
pendingActionResult
|
|
1757
1757
|
);
|
|
1758
1758
|
pendingNavigationLoadId = ++incrementingLoadId;
|
|
1759
|
-
if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.
|
|
1759
|
+
if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.middleware) && revalidatingFetchers.length === 0) {
|
|
1760
1760
|
let updatedFetchers2 = markFetchRedirectsDone();
|
|
1761
1761
|
completeNavigation(
|
|
1762
1762
|
location,
|
|
@@ -1910,7 +1910,7 @@ function createRouter(init) {
|
|
|
1910
1910
|
setFetcherError(key, routeId, error, { flushSync });
|
|
1911
1911
|
return;
|
|
1912
1912
|
}
|
|
1913
|
-
let scopedContext = init.
|
|
1913
|
+
let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
|
|
1914
1914
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1915
1915
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1916
1916
|
await handleFetcherAction(
|
|
@@ -2761,13 +2761,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2761
2761
|
skipLoaderErrorBubbling,
|
|
2762
2762
|
skipRevalidation,
|
|
2763
2763
|
dataStrategy,
|
|
2764
|
-
|
|
2764
|
+
generateMiddlewareResponse
|
|
2765
2765
|
} = {}) {
|
|
2766
2766
|
let url = new URL(request.url);
|
|
2767
2767
|
let method = request.method;
|
|
2768
2768
|
let location = createLocation("", createPath(url), null, "default");
|
|
2769
2769
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2770
|
-
requestContext = requestContext != null ? requestContext : new
|
|
2770
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
2771
2771
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2772
2772
|
let error = getInternalRouterError(405, { method });
|
|
2773
2773
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2805,8 +2805,8 @@ function createStaticHandler(routes, opts) {
|
|
|
2805
2805
|
}
|
|
2806
2806
|
if (generateMiddlewareResponse) {
|
|
2807
2807
|
invariant(
|
|
2808
|
-
requestContext instanceof
|
|
2809
|
-
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `
|
|
2808
|
+
requestContext instanceof RouterContextProvider,
|
|
2809
|
+
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
2810
2810
|
);
|
|
2811
2811
|
try {
|
|
2812
2812
|
await loadLazyMiddlewareForMatches(
|
|
@@ -2835,7 +2835,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2835
2835
|
dataStrategy || null,
|
|
2836
2836
|
skipLoaderErrorBubbling === true,
|
|
2837
2837
|
null,
|
|
2838
|
-
"filterMatchesToLoad" in opts2 ? _nullishCoalesce(opts2.filterMatchesToLoad, () => ( null)) : null,
|
|
2838
|
+
"filterMatchesToLoad" in opts2 ? _nullishCoalesce(opts2.filterMatchesToLoad, () => ( null)) : _nullishCoalesce(filterMatchesToLoad, () => ( null)),
|
|
2839
2839
|
skipRevalidation === true
|
|
2840
2840
|
);
|
|
2841
2841
|
if (isResponse(result2)) {
|
|
@@ -2933,13 +2933,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2933
2933
|
routeId,
|
|
2934
2934
|
requestContext,
|
|
2935
2935
|
dataStrategy,
|
|
2936
|
-
|
|
2936
|
+
generateMiddlewareResponse
|
|
2937
2937
|
} = {}) {
|
|
2938
2938
|
let url = new URL(request.url);
|
|
2939
2939
|
let method = request.method;
|
|
2940
2940
|
let location = createLocation("", createPath(url), null, "default");
|
|
2941
2941
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2942
|
-
requestContext = requestContext != null ? requestContext : new
|
|
2942
|
+
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
2943
2943
|
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
|
2944
2944
|
throw getInternalRouterError(405, { method });
|
|
2945
2945
|
} else if (!matches) {
|
|
@@ -2956,8 +2956,8 @@ function createStaticHandler(routes, opts) {
|
|
|
2956
2956
|
}
|
|
2957
2957
|
if (generateMiddlewareResponse) {
|
|
2958
2958
|
invariant(
|
|
2959
|
-
requestContext instanceof
|
|
2960
|
-
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `
|
|
2959
|
+
requestContext instanceof RouterContextProvider,
|
|
2960
|
+
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
|
2961
2961
|
);
|
|
2962
2962
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties);
|
|
2963
2963
|
let response = await runServerMiddlewarePipeline(
|
|
@@ -3947,11 +3947,11 @@ function isNonNullable(value) {
|
|
|
3947
3947
|
}
|
|
3948
3948
|
function loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties) {
|
|
3949
3949
|
let promises = matches.map(({ route }) => {
|
|
3950
|
-
if (typeof route.lazy !== "object" || !route.lazy.
|
|
3950
|
+
if (typeof route.lazy !== "object" || !route.lazy.middleware) {
|
|
3951
3951
|
return void 0;
|
|
3952
3952
|
}
|
|
3953
3953
|
return loadLazyRouteProperty({
|
|
3954
|
-
key: "
|
|
3954
|
+
key: "middleware",
|
|
3955
3955
|
route,
|
|
3956
3956
|
manifest,
|
|
3957
3957
|
mapRouteProperties
|
|
@@ -3969,7 +3969,7 @@ async function defaultDataStrategy(args) {
|
|
|
3969
3969
|
return keyedResults;
|
|
3970
3970
|
}
|
|
3971
3971
|
async function defaultDataStrategyWithMiddleware(args) {
|
|
3972
|
-
if (!args.matches.some((m) => m.route.
|
|
3972
|
+
if (!args.matches.some((m) => m.route.middleware)) {
|
|
3973
3973
|
return defaultDataStrategy(args);
|
|
3974
3974
|
}
|
|
3975
3975
|
return runClientMiddlewarePipeline(args, () => defaultDataStrategy(args));
|
|
@@ -4023,7 +4023,7 @@ function runClientMiddlewarePipeline(args, handler) {
|
|
|
4023
4023
|
async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
|
4024
4024
|
let { matches, request, params, context } = args;
|
|
4025
4025
|
let tuples = matches.flatMap(
|
|
4026
|
-
(m) => m.route.
|
|
4026
|
+
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
4027
4027
|
);
|
|
4028
4028
|
let result = await callRouteMiddleware(
|
|
4029
4029
|
{ request, params, context },
|
|
@@ -4086,7 +4086,7 @@ async function callRouteMiddleware(args, middlewares, handler, processResult, is
|
|
|
4086
4086
|
}
|
|
4087
4087
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
4088
4088
|
let lazyMiddlewarePromise = loadLazyRouteProperty({
|
|
4089
|
-
key: "
|
|
4089
|
+
key: "middleware",
|
|
4090
4090
|
route: match.route,
|
|
4091
4091
|
manifest,
|
|
4092
4092
|
mapRouteProperties
|
|
@@ -4186,9 +4186,9 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4186
4186
|
context: scopedContext,
|
|
4187
4187
|
matches
|
|
4188
4188
|
};
|
|
4189
|
-
let
|
|
4189
|
+
let runClientMiddleware = isStaticHandler ? () => {
|
|
4190
4190
|
throw new Error(
|
|
4191
|
-
"You cannot call `
|
|
4191
|
+
"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`"
|
|
4192
4192
|
);
|
|
4193
4193
|
} : (cb) => {
|
|
4194
4194
|
let typedDataStrategyArgs = dataStrategyArgs;
|
|
@@ -4196,9 +4196,9 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4196
4196
|
return cb({
|
|
4197
4197
|
...typedDataStrategyArgs,
|
|
4198
4198
|
fetcherKey,
|
|
4199
|
-
|
|
4199
|
+
runClientMiddleware: () => {
|
|
4200
4200
|
throw new Error(
|
|
4201
|
-
"Cannot call `
|
|
4201
|
+
"Cannot call `runClientMiddleware()` from within an `runClientMiddleware` handler"
|
|
4202
4202
|
);
|
|
4203
4203
|
}
|
|
4204
4204
|
});
|
|
@@ -4207,7 +4207,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4207
4207
|
let results = await dataStrategyImpl({
|
|
4208
4208
|
...dataStrategyArgs,
|
|
4209
4209
|
fetcherKey,
|
|
4210
|
-
|
|
4210
|
+
runClientMiddleware
|
|
4211
4211
|
});
|
|
4212
4212
|
try {
|
|
4213
4213
|
await Promise.all(
|
|
@@ -5708,7 +5708,7 @@ function getTurboStreamSingleFetchDataStrategy(getRouter, manifest, routeModules
|
|
|
5708
5708
|
ssr,
|
|
5709
5709
|
basename
|
|
5710
5710
|
);
|
|
5711
|
-
return async (args) => args.
|
|
5711
|
+
return async (args) => args.runClientMiddleware(dataStrategy);
|
|
5712
5712
|
}
|
|
5713
5713
|
function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, basename, shouldAllowOptOut = () => true) {
|
|
5714
5714
|
return async (args) => {
|
|
@@ -6107,6 +6107,7 @@ var FetchersContext = React2.createContext(
|
|
|
6107
6107
|
FetchersContext.displayName = "Fetchers";
|
|
6108
6108
|
var AwaitContext = React2.createContext(null);
|
|
6109
6109
|
AwaitContext.displayName = "Await";
|
|
6110
|
+
var AwaitContextProvider = (props) => React2.createElement(AwaitContext.Provider, props);
|
|
6110
6111
|
var NavigationContext = React2.createContext(
|
|
6111
6112
|
null
|
|
6112
6113
|
);
|
|
@@ -7130,7 +7131,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
7130
7131
|
Object.assign(dataRoute, {
|
|
7131
7132
|
...dataRoute,
|
|
7132
7133
|
...getRouteComponents(route, routeModule, isSpaMode),
|
|
7133
|
-
|
|
7134
|
+
middleware: routeModule.clientMiddleware,
|
|
7134
7135
|
handle: routeModule.handle,
|
|
7135
7136
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
7136
7137
|
dataRoute.path,
|
|
@@ -7272,17 +7273,14 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
7272
7273
|
}
|
|
7273
7274
|
});
|
|
7274
7275
|
} : void 0,
|
|
7275
|
-
|
|
7276
|
-
let {
|
|
7276
|
+
middleware: route.hasClientMiddleware ? async () => {
|
|
7277
|
+
let { clientMiddleware } = route.clientMiddlewareModule ? await Promise.resolve().then(() => _interopRequireWildcard(require(
|
|
7277
7278
|
/* @vite-ignore */
|
|
7278
7279
|
/* webpackIgnore: true */
|
|
7279
7280
|
route.clientMiddlewareModule
|
|
7280
7281
|
))) : await getLazyRoute();
|
|
7281
|
-
invariant2(
|
|
7282
|
-
|
|
7283
|
-
"No `unstable_clientMiddleware` export found"
|
|
7284
|
-
);
|
|
7285
|
-
return unstable_clientMiddleware;
|
|
7282
|
+
invariant2(clientMiddleware, "No `clientMiddleware` export found");
|
|
7283
|
+
return clientMiddleware;
|
|
7286
7284
|
} : void 0,
|
|
7287
7285
|
shouldRevalidate: async () => {
|
|
7288
7286
|
let lazyRoute = await getLazyRoute();
|
|
@@ -7363,7 +7361,7 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
|
|
7363
7361
|
return {
|
|
7364
7362
|
Component: getRouteModuleComponent(routeModule),
|
|
7365
7363
|
ErrorBoundary: routeModule.ErrorBoundary,
|
|
7366
|
-
|
|
7364
|
+
clientMiddleware: routeModule.clientMiddleware,
|
|
7367
7365
|
clientAction: routeModule.clientAction,
|
|
7368
7366
|
clientLoader: routeModule.clientLoader,
|
|
7369
7367
|
handle: routeModule.handle,
|
|
@@ -8301,4 +8299,5 @@ function BoundaryShell({
|
|
|
8301
8299
|
|
|
8302
8300
|
|
|
8303
8301
|
|
|
8304
|
-
|
|
8302
|
+
|
|
8303
|
+
exports.Action = Action; exports.createMemoryHistory = createMemoryHistory; exports.createBrowserHistory = createBrowserHistory; exports.createHashHistory = createHashHistory; exports.invariant = invariant; exports.warning = warning; exports.createPath = createPath; exports.parsePath = parsePath; exports.createContext = createContext; exports.RouterContextProvider = RouterContextProvider; exports.convertRoutesToDataRoutes = convertRoutesToDataRoutes; exports.matchRoutes = matchRoutes; exports.generatePath = generatePath; exports.matchPath = matchPath; exports.stripBasename = stripBasename; exports.resolvePath = resolvePath; exports.getResolveToMatches = getResolveToMatches; exports.resolveTo = resolveTo; exports.joinPaths = joinPaths; exports.data = data; exports.redirect = redirect; exports.redirectDocument = redirectDocument; exports.replace = replace; exports.ErrorResponseImpl = ErrorResponseImpl; exports.isRouteErrorResponse = isRouteErrorResponse; exports.encode = encode; exports.IDLE_NAVIGATION = IDLE_NAVIGATION; exports.IDLE_FETCHER = IDLE_FETCHER; exports.IDLE_BLOCKER = IDLE_BLOCKER; exports.createRouter = createRouter; exports.createStaticHandler = createStaticHandler; exports.getStaticContextFromError = getStaticContextFromError; exports.isDataWithResponseInit = isDataWithResponseInit; exports.isResponse = isResponse; exports.isRedirectStatusCode = isRedirectStatusCode; exports.isRedirectResponse = isRedirectResponse; exports.isMutationMethod = isMutationMethod; exports.createRequestInit = createRequestInit; exports.SingleFetchRedirectSymbol = SingleFetchRedirectSymbol; exports.SINGLE_FETCH_REDIRECT_STATUS = SINGLE_FETCH_REDIRECT_STATUS; exports.NO_BODY_STATUS_CODES = NO_BODY_STATUS_CODES; exports.StreamTransfer = StreamTransfer; exports.getTurboStreamSingleFetchDataStrategy = getTurboStreamSingleFetchDataStrategy; exports.getSingleFetchDataStrategyImpl = getSingleFetchDataStrategyImpl; exports.stripIndexParam = stripIndexParam; exports.singleFetchUrl = singleFetchUrl; exports.decodeViaTurboStream = decodeViaTurboStream; exports.DataRouterContext = DataRouterContext; exports.DataRouterStateContext = DataRouterStateContext; exports.RSCRouterContext = RSCRouterContext; exports.ViewTransitionContext = ViewTransitionContext; exports.FetchersContext = FetchersContext; exports.AwaitContext = AwaitContext; exports.AwaitContextProvider = AwaitContextProvider; exports.NavigationContext = NavigationContext; exports.LocationContext = LocationContext; exports.RouteContext = RouteContext; exports.ENABLE_DEV_WARNINGS = ENABLE_DEV_WARNINGS; exports.warnOnce = warnOnce; exports.useHref = useHref; exports.useInRouterContext = useInRouterContext; exports.useLocation = useLocation; exports.useNavigationType = useNavigationType; exports.useMatch = useMatch; exports.useNavigate = useNavigate; exports.useOutletContext = useOutletContext; exports.useOutlet = useOutlet; exports.useParams = useParams; exports.useResolvedPath = useResolvedPath; exports.useRoutes = useRoutes; exports.useRoutesImpl = useRoutesImpl; exports._renderMatches = _renderMatches; exports.useRouteId = useRouteId; exports.useNavigation = useNavigation; exports.useRevalidator = useRevalidator; exports.useMatches = useMatches; exports.useLoaderData = useLoaderData; exports.useRouteLoaderData = useRouteLoaderData; exports.useActionData = useActionData; exports.useRouteError = useRouteError; exports.useAsyncValue = useAsyncValue; exports.useAsyncError = useAsyncError; exports.useBlocker = useBlocker; exports.RemixErrorBoundary = RemixErrorBoundary; exports.createServerRoutes = createServerRoutes; exports.createClientRoutesWithHMRRevalidationOptOut = createClientRoutesWithHMRRevalidationOptOut; exports.noActionDefinedError = noActionDefinedError; exports.createClientRoutes = createClientRoutes; exports.shouldHydrateRouteLoader = shouldHydrateRouteLoader; exports.getPatchRoutesOnNavigationFunction = getPatchRoutesOnNavigationFunction; exports.useFogOFWarDiscovery = useFogOFWarDiscovery; exports.getManifestPath = getManifestPath; exports.FrameworkContext = FrameworkContext; exports.usePrefetchBehavior = usePrefetchBehavior; exports.CRITICAL_CSS_DATA_ATTRIBUTE = CRITICAL_CSS_DATA_ATTRIBUTE; exports.Links = Links; exports.PrefetchPageLinks = PrefetchPageLinks; exports.Meta = Meta; exports.setIsHydrated = setIsHydrated; exports.Scripts = Scripts; exports.mergeRefs = mergeRefs;
|