react-router 0.0.0-experimental-1ebb6d403 → 0.0.0-experimental-e41ede670

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +0 -10
  2. package/dist/development/{chunk-5XVYBMAF.mjs → chunk-H3OBLXFX.mjs} +767 -514
  3. package/dist/development/dom-export.d.mts +13 -3
  4. package/dist/development/dom-export.d.ts +13 -3
  5. package/dist/development/dom-export.js +272 -108
  6. package/dist/development/dom-export.mjs +9 -6
  7. package/dist/{production/fog-of-war-7V7BguJA.d.ts → development/fog-of-war-Bt7PejVF.d.ts} +91 -6
  8. package/dist/development/{fog-of-war-NQCW9yWR.d.mts → fog-of-war-Dz4n-TU-.d.mts} +91 -6
  9. package/dist/development/index.d.mts +10 -19
  10. package/dist/development/index.d.ts +10 -19
  11. package/dist/development/index.js +767 -514
  12. package/dist/development/index.mjs +2 -2
  13. package/dist/development/lib/types/route-module.d.mts +6 -2
  14. package/dist/development/lib/types/route-module.d.ts +6 -2
  15. package/dist/development/lib/types/route-module.js +1 -1
  16. package/dist/development/lib/types/route-module.mjs +1 -1
  17. package/dist/development/{route-data-JFOfNyPS.d.ts → route-data-C96IyGKo.d.mts} +37 -15
  18. package/dist/{production/route-data-JFOfNyPS.d.mts → development/route-data-C96IyGKo.d.ts} +37 -15
  19. package/dist/production/{chunk-CKFZHSMW.mjs → chunk-YBZNESR7.mjs} +767 -514
  20. package/dist/production/dom-export.d.mts +13 -3
  21. package/dist/production/dom-export.d.ts +13 -3
  22. package/dist/production/dom-export.js +272 -108
  23. package/dist/production/dom-export.mjs +9 -6
  24. package/dist/{development/fog-of-war-7V7BguJA.d.ts → production/fog-of-war-Bt7PejVF.d.ts} +91 -6
  25. package/dist/production/{fog-of-war-NQCW9yWR.d.mts → fog-of-war-Dz4n-TU-.d.mts} +91 -6
  26. package/dist/production/index.d.mts +10 -19
  27. package/dist/production/index.d.ts +10 -19
  28. package/dist/production/index.js +767 -514
  29. package/dist/production/index.mjs +2 -2
  30. package/dist/production/lib/types/route-module.d.mts +6 -2
  31. package/dist/production/lib/types/route-module.d.ts +6 -2
  32. package/dist/production/lib/types/route-module.js +1 -1
  33. package/dist/production/lib/types/route-module.mjs +1 -1
  34. package/dist/production/{route-data-JFOfNyPS.d.ts → route-data-C96IyGKo.d.mts} +37 -15
  35. package/dist/{development/route-data-JFOfNyPS.d.mts → production/route-data-C96IyGKo.d.ts} +37 -15
  36. package/package.json +2 -17
  37. package/dist/development/server.d.mts +0 -988
  38. package/dist/development/server.d.ts +0 -988
  39. package/dist/development/server.js +0 -1429
  40. package/dist/development/server.mjs +0 -1406
  41. package/dist/production/server.d.mts +0 -988
  42. package/dist/production/server.d.ts +0 -988
  43. package/dist/production/server.js +0 -1405
  44. package/dist/production/server.mjs +0 -1382
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-1ebb6d403
2
+ * react-router v0.0.0-experimental-e41ede670
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -120,7 +120,7 @@ import {
120
120
  useSearchParams,
121
121
  useSubmit,
122
122
  useViewTransitionState
123
- } from "./chunk-5XVYBMAF.mjs";
123
+ } from "./chunk-H3OBLXFX.mjs";
124
124
  export {
125
125
  Await,
126
126
  BrowserRouter,
@@ -1,4 +1,4 @@
1
- import { av as LinkDescriptor, as as MetaDescriptor, aJ as ServerDataFrom, aK as ClientDataFrom, aL as Func, aM as Equal, aN as Pretty } from '../../route-data-JFOfNyPS.mjs';
1
+ import { ay as LinkDescriptor, av as MetaDescriptor, aM as ServerDataFrom, aN as ClientDataFrom, aO as Func, M as MiddlewareFunction, d as ClientMiddlewareFunction, aP as Equal, aQ as Pretty } from '../../route-data-C96IyGKo.mjs';
2
2
  import { A as AppLoadContext } from '../../data-CQbyyGzl.mjs';
3
3
  import 'react';
4
4
 
@@ -76,6 +76,10 @@ type ClientDataFunctionArgs<T extends RouteInfo> = {
76
76
  type ServerDataFunctionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
77
77
  context: AppLoadContext;
78
78
  };
79
+ type CreateServerMiddlewareArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>;
80
+ type ServerMiddlewareNextFunction = Parameters<MiddlewareFunction>[1];
81
+ type CreateClientMiddlewareArgs<T extends RouteInfo> = Parameters<ClientMiddlewareFunction>[0];
82
+ type ClientMiddlewareNextFunction = Parameters<ClientMiddlewareFunction>[1];
79
83
  type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>;
80
84
  type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
81
85
  serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
@@ -106,4 +110,4 @@ type CreateErrorBoundaryProps<T extends RouteInfo> = {
106
110
  actionData?: T["actionData"];
107
111
  };
108
112
 
109
- export type { CreateActionData, CreateClientActionArgs, CreateClientLoaderArgs, CreateComponentProps, CreateErrorBoundaryProps, CreateHydrateFallbackProps, CreateLoaderData, CreateMetaArgs, CreateServerActionArgs, CreateServerLoaderArgs, HeadersArgs, LinkDescriptors, MetaDescriptors };
113
+ export type { ClientMiddlewareNextFunction, CreateActionData, CreateClientActionArgs, CreateClientLoaderArgs, CreateClientMiddlewareArgs, CreateComponentProps, CreateErrorBoundaryProps, CreateHydrateFallbackProps, CreateLoaderData, CreateMetaArgs, CreateServerActionArgs, CreateServerLoaderArgs, CreateServerMiddlewareArgs, HeadersArgs, LinkDescriptors, MetaDescriptors, ServerMiddlewareNextFunction };
@@ -1,4 +1,4 @@
1
- import { av as LinkDescriptor, as as MetaDescriptor, aJ as ServerDataFrom, aK as ClientDataFrom, aL as Func, aM as Equal, aN as Pretty } from '../../route-data-JFOfNyPS.js';
1
+ import { ay as LinkDescriptor, av as MetaDescriptor, aM as ServerDataFrom, aN as ClientDataFrom, aO as Func, M as MiddlewareFunction, d as ClientMiddlewareFunction, aP as Equal, aQ as Pretty } from '../../route-data-C96IyGKo.js';
2
2
  import { A as AppLoadContext } from '../../data-CQbyyGzl.js';
3
3
  import 'react';
4
4
 
@@ -76,6 +76,10 @@ type ClientDataFunctionArgs<T extends RouteInfo> = {
76
76
  type ServerDataFunctionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
77
77
  context: AppLoadContext;
78
78
  };
79
+ type CreateServerMiddlewareArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>;
80
+ type ServerMiddlewareNextFunction = Parameters<MiddlewareFunction>[1];
81
+ type CreateClientMiddlewareArgs<T extends RouteInfo> = Parameters<ClientMiddlewareFunction>[0];
82
+ type ClientMiddlewareNextFunction = Parameters<ClientMiddlewareFunction>[1];
79
83
  type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>;
80
84
  type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
81
85
  serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
@@ -106,4 +110,4 @@ type CreateErrorBoundaryProps<T extends RouteInfo> = {
106
110
  actionData?: T["actionData"];
107
111
  };
108
112
 
109
- export type { CreateActionData, CreateClientActionArgs, CreateClientLoaderArgs, CreateComponentProps, CreateErrorBoundaryProps, CreateHydrateFallbackProps, CreateLoaderData, CreateMetaArgs, CreateServerActionArgs, CreateServerLoaderArgs, HeadersArgs, LinkDescriptors, MetaDescriptors };
113
+ export type { ClientMiddlewareNextFunction, CreateActionData, CreateClientActionArgs, CreateClientLoaderArgs, CreateClientMiddlewareArgs, CreateComponentProps, CreateErrorBoundaryProps, CreateHydrateFallbackProps, CreateLoaderData, CreateMetaArgs, CreateServerActionArgs, CreateServerLoaderArgs, CreateServerMiddlewareArgs, HeadersArgs, LinkDescriptors, MetaDescriptors, ServerMiddlewareNextFunction };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-1ebb6d403
2
+ * react-router v0.0.0-experimental-e41ede670
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-1ebb6d403
2
+ * react-router v0.0.0-experimental-e41ede670
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -260,6 +260,12 @@ type Submission = {
260
260
  json: undefined;
261
261
  text: string;
262
262
  };
263
+ /**
264
+ * @private
265
+ * Default context value type for `createRouter`, can be overridden via the generics
266
+ * on LoaderFunction/LoaderFunctionArgs/ActionFunction/ActionFunctionArgs
267
+ */
268
+ type DefaultRouterContext = any;
263
269
  /**
264
270
  * @private
265
271
  * Arguments passed to route loader/action functions. Same for now but we keep
@@ -268,29 +274,38 @@ type Submission = {
268
274
  interface DataFunctionArgs<Context> {
269
275
  request: Request;
270
276
  params: Params;
271
- context?: Context;
277
+ context: Context;
272
278
  }
279
+ type BaseMiddlewareFunction<Result, Context> = {
280
+ (args: DataFunctionArgs<Context>, next: () => Promise<Result>): Result | Promise<Result>;
281
+ };
282
+ /**
283
+ * Server-side route middleware function signature
284
+ */
285
+ type MiddlewareFunction<Context = DefaultRouterContext> = BaseMiddlewareFunction<unknown, Context>;
286
+ /**
287
+ * Client-side route middleware function signature
288
+ */
289
+ type ClientMiddlewareFunction<Context = DefaultRouterContext> = BaseMiddlewareFunction<unknown, Context>;
273
290
  /**
274
291
  * Arguments passed to loader functions
275
292
  */
276
- interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
293
+ interface LoaderFunctionArgs<Context = DefaultRouterContext> extends DataFunctionArgs<Context> {
277
294
  }
278
295
  /**
279
296
  * Arguments passed to action functions
280
297
  */
281
- interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
298
+ interface ActionFunctionArgs<Context = DefaultRouterContext> extends DataFunctionArgs<Context> {
282
299
  }
283
300
  /**
284
- * Loaders and actions can return anything except `undefined` (`null` is a
285
- * valid return value if there is no data to return). Responses are preferred
286
- * and will ease any future migration to Remix
301
+ * Loaders and actions can return anything
287
302
  */
288
- type DataFunctionValue = Response | NonNullable<unknown> | null;
303
+ type DataFunctionValue = unknown;
289
304
  type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
290
305
  /**
291
306
  * Route loader function signature
292
307
  */
293
- type LoaderFunction<Context = any> = {
308
+ type LoaderFunction<Context = DefaultRouterContext> = {
294
309
  (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
295
310
  } & {
296
311
  hydrate?: boolean;
@@ -298,7 +313,7 @@ type LoaderFunction<Context = any> = {
298
313
  /**
299
314
  * Route action function signature
300
315
  */
301
- interface ActionFunction<Context = any> {
316
+ interface ActionFunction<Context = DefaultRouterContext> {
302
317
  (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
303
318
  }
304
319
  /**
@@ -333,7 +348,7 @@ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRoute
333
348
  shouldLoad: boolean;
334
349
  resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
335
350
  }
336
- interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
351
+ interface DataStrategyFunctionArgs<Context = DefaultRouterContext> extends DataFunctionArgs<Context> {
337
352
  matches: DataStrategyMatch[];
338
353
  fetcherKey: string | null;
339
354
  }
@@ -385,6 +400,7 @@ type AgnosticBaseRouteObject = {
385
400
  caseSensitive?: boolean;
386
401
  path?: string;
387
402
  id?: string;
403
+ middleware?: ClientMiddlewareFunction[];
388
404
  loader?: LoaderFunction | boolean;
389
405
  action?: ActionFunction | boolean;
390
406
  hasErrorBoundary?: boolean;
@@ -868,6 +884,7 @@ interface RouterInit {
868
884
  routes: AgnosticRouteObject[];
869
885
  history: History;
870
886
  basename?: string;
887
+ context?: DefaultRouterContext;
871
888
  mapRouteProperties?: MapRoutePropertiesFunction;
872
889
  future?: Partial<FutureConfig>;
873
890
  hydrationData?: HydrationState;
@@ -899,11 +916,13 @@ interface StaticHandler {
899
916
  requestContext?: unknown;
900
917
  skipLoaderErrorBubbling?: boolean;
901
918
  dataStrategy?: DataStrategyFunction;
919
+ respond?: (staticContext: StaticHandlerContext) => Promise<Response>;
902
920
  }): Promise<StaticHandlerContext | Response>;
903
921
  queryRoute(request: Request, opts?: {
904
922
  routeId?: string;
905
923
  requestContext?: unknown;
906
924
  dataStrategy?: DataStrategyFunction;
925
+ respond?: (staticContext: StaticHandlerContext) => Promise<Response>;
907
926
  }): Promise<any>;
908
927
  }
909
928
  type ViewTransitionOpts = {
@@ -1137,6 +1156,7 @@ interface IndexRouteObject {
1137
1156
  caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1138
1157
  path?: AgnosticIndexRouteObject["path"];
1139
1158
  id?: AgnosticIndexRouteObject["id"];
1159
+ middleware?: AgnosticIndexRouteObject["middleware"];
1140
1160
  loader?: AgnosticIndexRouteObject["loader"];
1141
1161
  action?: AgnosticIndexRouteObject["action"];
1142
1162
  hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
@@ -1156,6 +1176,7 @@ interface NonIndexRouteObject {
1156
1176
  caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1157
1177
  path?: AgnosticNonIndexRouteObject["path"];
1158
1178
  id?: AgnosticNonIndexRouteObject["id"];
1179
+ middleware?: AgnosticNonIndexRouteObject["middleware"];
1159
1180
  loader?: AgnosticNonIndexRouteObject["loader"];
1160
1181
  action?: AgnosticNonIndexRouteObject["action"];
1161
1182
  hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
@@ -1352,6 +1373,7 @@ interface RouteModules {
1352
1373
  interface RouteModule {
1353
1374
  clientAction?: ClientActionFunction;
1354
1375
  clientLoader?: ClientLoaderFunction;
1376
+ clientMiddleware?: ClientMiddlewareFunction[];
1355
1377
  ErrorBoundary?: ErrorBoundaryComponent;
1356
1378
  HydrateFallback?: HydrateFallbackComponent;
1357
1379
  Layout?: LayoutComponent;
@@ -1368,7 +1390,7 @@ type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<Actio
1368
1390
  /**
1369
1391
  * Arguments passed to a route `clientAction` function
1370
1392
  */
1371
- type ClientActionFunctionArgs = ActionFunctionArgs<undefined> & {
1393
+ type ClientActionFunctionArgs = ActionFunctionArgs & {
1372
1394
  serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1373
1395
  };
1374
1396
  /**
@@ -1380,7 +1402,7 @@ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<Load
1380
1402
  /**
1381
1403
  * Arguments passed to a route `clientLoader` function
1382
1404
  */
1383
- type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
1405
+ type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1384
1406
  serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1385
1407
  };
1386
1408
  /**
@@ -1537,10 +1559,10 @@ type Serialize<T> = T extends Serializable ? T : T extends (...args: any[]) => u
1537
1559
  } : undefined;
1538
1560
  type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1539
1561
  type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1540
- type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1541
- type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1562
+ type ClientData<T> = T extends DataWithResponseInit<infer U> ? U : T;
1563
+ type ServerData<T> = T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1542
1564
  type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1543
1565
  type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1544
1566
  type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1545
1567
 
1546
- export { type HTMLFormMethod as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyFunction as D, type RouterInit as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterSubscriber as J, type RouterNavigateOptions as K, type LoaderFunction as L, type MetaFunction as M, type NavigateOptions as N, type RouterFetchOptions as O, type ParamParseKey as P, type DataStrategyFunctionArgs as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type DataStrategyMatch as V, type DataStrategyResult as W, DataWithResponseInit as X, type ErrorResponse as Y, type FormEncType as Z, type FormMethod as _, type Router as a, type LazyRouteFunction as a0, type PathParam as a1, type RedirectFunction as a2, type ShouldRevalidateFunction as a3, type ShouldRevalidateFunctionArgs as a4, createPath as a5, parsePath as a6, IDLE_NAVIGATION as a7, IDLE_FETCHER as a8, IDLE_BLOCKER as a9, DataRouterContext as aA, DataRouterStateContext as aB, FetchersContext as aC, LocationContext as aD, NavigationContext as aE, RouteContext as aF, ViewTransitionContext as aG, type RouteModule as aH, type History as aI, type ServerDataFrom as aJ, type ClientDataFrom as aK, type Func as aL, type Equal as aM, type Pretty as aN, data as aa, generatePath as ab, isRouteErrorResponse as ac, matchPath as ad, matchRoutes as ae, redirect as af, redirectDocument as ag, replace as ah, resolvePath as ai, type DataRouteMatch as aj, type DataRouteObject as ak, type Navigator as al, type PatchRoutesOnNavigationFunction as am, type PatchRoutesOnNavigationFunctionArgs as an, type RouteMatch as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunctionArgs as aq, type MetaArgs as ar, type MetaDescriptor as as, type PageLinkDescriptor as at, type HtmlLinkDescriptor as au, type LinkDescriptor as av, createBrowserHistory as aw, invariant as ax, createRouter as ay, ErrorResponseImpl as az, type ClientLoaderFunction as b, type LinksFunction as c, type RouteManifest as d, type LoaderFunctionArgs as e, type ActionFunctionArgs as f, type RelativeRoutingType as g, type Location as h, Action as i, type Path as j, type PathPattern as k, type PathMatch as l, type Params as m, type RouteObject as n, type Navigation as o, type RevalidationState as p, type Blocker as q, type StaticHandlerContext as r, type StaticHandler as s, type CreateStaticHandlerOptions as t, type IndexRouteObject as u, type NonIndexRouteObject as v, type RouterState as w, type GetScrollRestorationKeyFunction as x, type Fetcher as y, type NavigationStates as z };
1568
+ export { type ErrorResponse as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DefaultRouterContext as D, type GetScrollRestorationKeyFunction as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type Fetcher as J, type NavigationStates as K, type LoaderFunction as L, type MiddlewareFunction as M, type NavigateOptions as N, type RouterInit as O, type ParamParseKey as P, type RouterSubscriber as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type RouterNavigateOptions as V, type RouterFetchOptions as W, type DataStrategyFunctionArgs as X, type DataStrategyMatch as Y, type DataStrategyResult as Z, DataWithResponseInit as _, type Router as a, type FormEncType as a0, type FormMethod as a1, type HTMLFormMethod as a2, type LazyRouteFunction as a3, type PathParam as a4, type RedirectFunction as a5, type ShouldRevalidateFunction as a6, type ShouldRevalidateFunctionArgs as a7, createPath as a8, parsePath as a9, invariant as aA, createRouter as aB, ErrorResponseImpl as aC, DataRouterContext as aD, DataRouterStateContext as aE, FetchersContext as aF, LocationContext as aG, NavigationContext as aH, RouteContext as aI, ViewTransitionContext as aJ, type RouteModule as aK, type History as aL, type ServerDataFrom as aM, type ClientDataFrom as aN, type Func as aO, type Equal as aP, type Pretty as aQ, IDLE_NAVIGATION as aa, IDLE_FETCHER as ab, IDLE_BLOCKER as ac, data as ad, generatePath as ae, isRouteErrorResponse as af, matchPath as ag, matchRoutes as ah, redirect as ai, redirectDocument as aj, replace as ak, resolvePath as al, type DataRouteMatch as am, type DataRouteObject as an, type Navigator as ao, type PatchRoutesOnNavigationFunction as ap, type PatchRoutesOnNavigationFunctionArgs as aq, type RouteMatch as ar, type ClientActionFunctionArgs as as, type ClientLoaderFunctionArgs as at, type MetaArgs as au, type MetaDescriptor as av, type PageLinkDescriptor as aw, type HtmlLinkDescriptor as ax, type LinkDescriptor as ay, createBrowserHistory as az, type DataStrategyFunction as b, type ClientLoaderFunction as c, type ClientMiddlewareFunction as d, type LinksFunction as e, type MetaFunction as f, type RouteManifest as g, type LoaderFunctionArgs as h, type ActionFunctionArgs as i, type RelativeRoutingType as j, type Location as k, Action as l, type Path as m, type PathPattern as n, type PathMatch as o, type Params as p, type RouteObject as q, type Navigation as r, type RevalidationState as s, type Blocker as t, type StaticHandlerContext as u, type StaticHandler as v, type CreateStaticHandlerOptions as w, type IndexRouteObject as x, type NonIndexRouteObject as y, type RouterState as z };
@@ -260,6 +260,12 @@ type Submission = {
260
260
  json: undefined;
261
261
  text: string;
262
262
  };
263
+ /**
264
+ * @private
265
+ * Default context value type for `createRouter`, can be overridden via the generics
266
+ * on LoaderFunction/LoaderFunctionArgs/ActionFunction/ActionFunctionArgs
267
+ */
268
+ type DefaultRouterContext = any;
263
269
  /**
264
270
  * @private
265
271
  * Arguments passed to route loader/action functions. Same for now but we keep
@@ -268,29 +274,38 @@ type Submission = {
268
274
  interface DataFunctionArgs<Context> {
269
275
  request: Request;
270
276
  params: Params;
271
- context?: Context;
277
+ context: Context;
272
278
  }
279
+ type BaseMiddlewareFunction<Result, Context> = {
280
+ (args: DataFunctionArgs<Context>, next: () => Promise<Result>): Result | Promise<Result>;
281
+ };
282
+ /**
283
+ * Server-side route middleware function signature
284
+ */
285
+ type MiddlewareFunction<Context = DefaultRouterContext> = BaseMiddlewareFunction<unknown, Context>;
286
+ /**
287
+ * Client-side route middleware function signature
288
+ */
289
+ type ClientMiddlewareFunction<Context = DefaultRouterContext> = BaseMiddlewareFunction<unknown, Context>;
273
290
  /**
274
291
  * Arguments passed to loader functions
275
292
  */
276
- interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
293
+ interface LoaderFunctionArgs<Context = DefaultRouterContext> extends DataFunctionArgs<Context> {
277
294
  }
278
295
  /**
279
296
  * Arguments passed to action functions
280
297
  */
281
- interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
298
+ interface ActionFunctionArgs<Context = DefaultRouterContext> extends DataFunctionArgs<Context> {
282
299
  }
283
300
  /**
284
- * Loaders and actions can return anything except `undefined` (`null` is a
285
- * valid return value if there is no data to return). Responses are preferred
286
- * and will ease any future migration to Remix
301
+ * Loaders and actions can return anything
287
302
  */
288
- type DataFunctionValue = Response | NonNullable<unknown> | null;
303
+ type DataFunctionValue = unknown;
289
304
  type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
290
305
  /**
291
306
  * Route loader function signature
292
307
  */
293
- type LoaderFunction<Context = any> = {
308
+ type LoaderFunction<Context = DefaultRouterContext> = {
294
309
  (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
295
310
  } & {
296
311
  hydrate?: boolean;
@@ -298,7 +313,7 @@ type LoaderFunction<Context = any> = {
298
313
  /**
299
314
  * Route action function signature
300
315
  */
301
- interface ActionFunction<Context = any> {
316
+ interface ActionFunction<Context = DefaultRouterContext> {
302
317
  (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
303
318
  }
304
319
  /**
@@ -333,7 +348,7 @@ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRoute
333
348
  shouldLoad: boolean;
334
349
  resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
335
350
  }
336
- interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
351
+ interface DataStrategyFunctionArgs<Context = DefaultRouterContext> extends DataFunctionArgs<Context> {
337
352
  matches: DataStrategyMatch[];
338
353
  fetcherKey: string | null;
339
354
  }
@@ -385,6 +400,7 @@ type AgnosticBaseRouteObject = {
385
400
  caseSensitive?: boolean;
386
401
  path?: string;
387
402
  id?: string;
403
+ middleware?: ClientMiddlewareFunction[];
388
404
  loader?: LoaderFunction | boolean;
389
405
  action?: ActionFunction | boolean;
390
406
  hasErrorBoundary?: boolean;
@@ -868,6 +884,7 @@ interface RouterInit {
868
884
  routes: AgnosticRouteObject[];
869
885
  history: History;
870
886
  basename?: string;
887
+ context?: DefaultRouterContext;
871
888
  mapRouteProperties?: MapRoutePropertiesFunction;
872
889
  future?: Partial<FutureConfig>;
873
890
  hydrationData?: HydrationState;
@@ -899,11 +916,13 @@ interface StaticHandler {
899
916
  requestContext?: unknown;
900
917
  skipLoaderErrorBubbling?: boolean;
901
918
  dataStrategy?: DataStrategyFunction;
919
+ respond?: (staticContext: StaticHandlerContext) => Promise<Response>;
902
920
  }): Promise<StaticHandlerContext | Response>;
903
921
  queryRoute(request: Request, opts?: {
904
922
  routeId?: string;
905
923
  requestContext?: unknown;
906
924
  dataStrategy?: DataStrategyFunction;
925
+ respond?: (staticContext: StaticHandlerContext) => Promise<Response>;
907
926
  }): Promise<any>;
908
927
  }
909
928
  type ViewTransitionOpts = {
@@ -1137,6 +1156,7 @@ interface IndexRouteObject {
1137
1156
  caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1138
1157
  path?: AgnosticIndexRouteObject["path"];
1139
1158
  id?: AgnosticIndexRouteObject["id"];
1159
+ middleware?: AgnosticIndexRouteObject["middleware"];
1140
1160
  loader?: AgnosticIndexRouteObject["loader"];
1141
1161
  action?: AgnosticIndexRouteObject["action"];
1142
1162
  hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
@@ -1156,6 +1176,7 @@ interface NonIndexRouteObject {
1156
1176
  caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1157
1177
  path?: AgnosticNonIndexRouteObject["path"];
1158
1178
  id?: AgnosticNonIndexRouteObject["id"];
1179
+ middleware?: AgnosticNonIndexRouteObject["middleware"];
1159
1180
  loader?: AgnosticNonIndexRouteObject["loader"];
1160
1181
  action?: AgnosticNonIndexRouteObject["action"];
1161
1182
  hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
@@ -1352,6 +1373,7 @@ interface RouteModules {
1352
1373
  interface RouteModule {
1353
1374
  clientAction?: ClientActionFunction;
1354
1375
  clientLoader?: ClientLoaderFunction;
1376
+ clientMiddleware?: ClientMiddlewareFunction[];
1355
1377
  ErrorBoundary?: ErrorBoundaryComponent;
1356
1378
  HydrateFallback?: HydrateFallbackComponent;
1357
1379
  Layout?: LayoutComponent;
@@ -1368,7 +1390,7 @@ type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<Actio
1368
1390
  /**
1369
1391
  * Arguments passed to a route `clientAction` function
1370
1392
  */
1371
- type ClientActionFunctionArgs = ActionFunctionArgs<undefined> & {
1393
+ type ClientActionFunctionArgs = ActionFunctionArgs & {
1372
1394
  serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1373
1395
  };
1374
1396
  /**
@@ -1380,7 +1402,7 @@ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<Load
1380
1402
  /**
1381
1403
  * Arguments passed to a route `clientLoader` function
1382
1404
  */
1383
- type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
1405
+ type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1384
1406
  serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1385
1407
  };
1386
1408
  /**
@@ -1537,10 +1559,10 @@ type Serialize<T> = T extends Serializable ? T : T extends (...args: any[]) => u
1537
1559
  } : undefined;
1538
1560
  type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1539
1561
  type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1540
- type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1541
- type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1562
+ type ClientData<T> = T extends DataWithResponseInit<infer U> ? U : T;
1563
+ type ServerData<T> = T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1542
1564
  type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1543
1565
  type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1544
1566
  type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1545
1567
 
1546
- export { type HTMLFormMethod as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyFunction as D, type RouterInit as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterSubscriber as J, type RouterNavigateOptions as K, type LoaderFunction as L, type MetaFunction as M, type NavigateOptions as N, type RouterFetchOptions as O, type ParamParseKey as P, type DataStrategyFunctionArgs as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type DataStrategyMatch as V, type DataStrategyResult as W, DataWithResponseInit as X, type ErrorResponse as Y, type FormEncType as Z, type FormMethod as _, type Router as a, type LazyRouteFunction as a0, type PathParam as a1, type RedirectFunction as a2, type ShouldRevalidateFunction as a3, type ShouldRevalidateFunctionArgs as a4, createPath as a5, parsePath as a6, IDLE_NAVIGATION as a7, IDLE_FETCHER as a8, IDLE_BLOCKER as a9, DataRouterContext as aA, DataRouterStateContext as aB, FetchersContext as aC, LocationContext as aD, NavigationContext as aE, RouteContext as aF, ViewTransitionContext as aG, type RouteModule as aH, type History as aI, type ServerDataFrom as aJ, type ClientDataFrom as aK, type Func as aL, type Equal as aM, type Pretty as aN, data as aa, generatePath as ab, isRouteErrorResponse as ac, matchPath as ad, matchRoutes as ae, redirect as af, redirectDocument as ag, replace as ah, resolvePath as ai, type DataRouteMatch as aj, type DataRouteObject as ak, type Navigator as al, type PatchRoutesOnNavigationFunction as am, type PatchRoutesOnNavigationFunctionArgs as an, type RouteMatch as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunctionArgs as aq, type MetaArgs as ar, type MetaDescriptor as as, type PageLinkDescriptor as at, type HtmlLinkDescriptor as au, type LinkDescriptor as av, createBrowserHistory as aw, invariant as ax, createRouter as ay, ErrorResponseImpl as az, type ClientLoaderFunction as b, type LinksFunction as c, type RouteManifest as d, type LoaderFunctionArgs as e, type ActionFunctionArgs as f, type RelativeRoutingType as g, type Location as h, Action as i, type Path as j, type PathPattern as k, type PathMatch as l, type Params as m, type RouteObject as n, type Navigation as o, type RevalidationState as p, type Blocker as q, type StaticHandlerContext as r, type StaticHandler as s, type CreateStaticHandlerOptions as t, type IndexRouteObject as u, type NonIndexRouteObject as v, type RouterState as w, type GetScrollRestorationKeyFunction as x, type Fetcher as y, type NavigationStates as z };
1568
+ export { type ErrorResponse as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DefaultRouterContext as D, type GetScrollRestorationKeyFunction as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type Fetcher as J, type NavigationStates as K, type LoaderFunction as L, type MiddlewareFunction as M, type NavigateOptions as N, type RouterInit as O, type ParamParseKey as P, type RouterSubscriber as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type RouterNavigateOptions as V, type RouterFetchOptions as W, type DataStrategyFunctionArgs as X, type DataStrategyMatch as Y, type DataStrategyResult as Z, DataWithResponseInit as _, type Router as a, type FormEncType as a0, type FormMethod as a1, type HTMLFormMethod as a2, type LazyRouteFunction as a3, type PathParam as a4, type RedirectFunction as a5, type ShouldRevalidateFunction as a6, type ShouldRevalidateFunctionArgs as a7, createPath as a8, parsePath as a9, invariant as aA, createRouter as aB, ErrorResponseImpl as aC, DataRouterContext as aD, DataRouterStateContext as aE, FetchersContext as aF, LocationContext as aG, NavigationContext as aH, RouteContext as aI, ViewTransitionContext as aJ, type RouteModule as aK, type History as aL, type ServerDataFrom as aM, type ClientDataFrom as aN, type Func as aO, type Equal as aP, type Pretty as aQ, IDLE_NAVIGATION as aa, IDLE_FETCHER as ab, IDLE_BLOCKER as ac, data as ad, generatePath as ae, isRouteErrorResponse as af, matchPath as ag, matchRoutes as ah, redirect as ai, redirectDocument as aj, replace as ak, resolvePath as al, type DataRouteMatch as am, type DataRouteObject as an, type Navigator as ao, type PatchRoutesOnNavigationFunction as ap, type PatchRoutesOnNavigationFunctionArgs as aq, type RouteMatch as ar, type ClientActionFunctionArgs as as, type ClientLoaderFunctionArgs as at, type MetaArgs as au, type MetaDescriptor as av, type PageLinkDescriptor as aw, type HtmlLinkDescriptor as ax, type LinkDescriptor as ay, createBrowserHistory as az, type DataStrategyFunction as b, type ClientLoaderFunction as c, type ClientMiddlewareFunction as d, type LinksFunction as e, type MetaFunction as f, type RouteManifest as g, type LoaderFunctionArgs as h, type ActionFunctionArgs as i, type RelativeRoutingType as j, type Location as k, Action as l, type Path as m, type PathPattern as n, type PathMatch as o, type Params as p, type RouteObject as q, type Navigation as r, type RevalidationState as s, type Blocker as t, type StaticHandlerContext as u, type StaticHandler as v, type CreateStaticHandlerOptions as w, type IndexRouteObject as x, type NonIndexRouteObject as y, type RouterState as z };