react-router 7.7.1 → 7.8.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +81 -5
  2. package/dist/development/browser-z32v5KVN.d.mts +46 -0
  3. package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-HSC5IU24.mjs} +177 -134
  4. package/dist/development/{chunk-K7YFBME3.js → chunk-IW6UADHO.js} +250 -187
  5. package/dist/development/{chunk-C37GKA54.mjs → chunk-SC4OUYO4.mjs} +232 -169
  6. package/dist/development/{chunk-R73PQUJU.js → chunk-Z4NNCWGU.js} +130 -130
  7. package/dist/development/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
  8. package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DZWGFcKX.d.mts} +312 -524
  9. package/dist/development/dom-export.d.mts +16 -12
  10. package/dist/development/dom-export.d.ts +13 -8
  11. package/dist/development/dom-export.js +3 -3
  12. package/dist/development/dom-export.mjs +3 -3
  13. package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-BUK-oRcG.d.mts} +327 -200
  14. package/dist/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
  15. package/dist/development/index-react-server-client.d.mts +4 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -2
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +291 -70
  20. package/dist/development/index-react-server.d.ts +291 -70
  21. package/dist/development/index-react-server.js +174 -180
  22. package/dist/development/index-react-server.mjs +174 -180
  23. package/dist/development/index.d.mts +294 -86
  24. package/dist/development/index.d.ts +136 -105
  25. package/dist/development/index.js +258 -215
  26. package/dist/development/index.mjs +3 -3
  27. package/dist/development/lib/types/internal.d.mts +13 -2
  28. package/dist/development/lib/types/internal.d.ts +12 -2
  29. package/dist/development/lib/types/internal.js +1 -1
  30. package/dist/development/lib/types/internal.mjs +1 -1
  31. package/dist/development/route-data-UTmTa8an.d.mts +473 -0
  32. package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-D5bppTB2.d.ts} +325 -67
  33. package/dist/production/browser-z32v5KVN.d.mts +46 -0
  34. package/dist/production/{chunk-4DGLNKXF.js → chunk-BCLZG6QW.js} +130 -130
  35. package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-KQ5567DT.mjs} +177 -134
  36. package/dist/production/{chunk-IZ57JD2V.mjs → chunk-X2NPJMV2.mjs} +232 -169
  37. package/dist/production/{chunk-7OQROU2D.js → chunk-YC2ENCM3.js} +250 -187
  38. package/dist/production/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
  39. package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DZWGFcKX.d.mts} +312 -524
  40. package/dist/production/dom-export.d.mts +16 -12
  41. package/dist/production/dom-export.d.ts +13 -8
  42. package/dist/production/dom-export.js +3 -3
  43. package/dist/production/dom-export.mjs +3 -3
  44. package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-BUK-oRcG.d.mts} +327 -200
  45. package/dist/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
  46. package/dist/production/index-react-server-client.d.mts +4 -3
  47. package/dist/production/index-react-server-client.d.ts +2 -2
  48. package/dist/production/index-react-server-client.js +4 -4
  49. package/dist/production/index-react-server-client.mjs +2 -2
  50. package/dist/production/index-react-server.d.mts +291 -70
  51. package/dist/production/index-react-server.d.ts +291 -70
  52. package/dist/production/index-react-server.js +174 -180
  53. package/dist/production/index-react-server.mjs +174 -180
  54. package/dist/production/index.d.mts +294 -86
  55. package/dist/production/index.d.ts +136 -105
  56. package/dist/production/index.js +258 -215
  57. package/dist/production/index.mjs +3 -3
  58. package/dist/production/lib/types/internal.d.mts +13 -2
  59. package/dist/production/lib/types/internal.d.ts +12 -2
  60. package/dist/production/lib/types/internal.js +1 -1
  61. package/dist/production/lib/types/internal.mjs +1 -1
  62. package/dist/production/route-data-UTmTa8an.d.mts +473 -0
  63. package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-D5bppTB2.d.ts} +325 -67
  64. package/package.json +1 -1
  65. package/dist/development/browser-7LYX59NK.d.mts +0 -226
  66. package/dist/production/browser-7LYX59NK.d.mts +0 -226
@@ -1,4 +1,3 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
1
  import * as React from 'react';
3
2
  export { Await, 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';
4
3
  import { ParseOptions, SerializeOptions } from 'cookie';
@@ -228,35 +227,123 @@ type Submission = {
228
227
  json: undefined;
229
228
  text: string;
230
229
  };
230
+ /**
231
+ * A context instance used as the key for the `get`/`set` methods of a
232
+ * {@link unstable_RouterContextProvider}. Accepts an optional default
233
+ * value to be returned if no value has been set.
234
+ */
231
235
  interface unstable_RouterContext<T = unknown> {
232
236
  defaultValue?: T;
233
237
  }
234
238
  /**
235
- * Creates a context object that may be used to store and retrieve arbitrary values.
239
+ * Creates a type-safe {@link unstable_RouterContext} object that can be used to
240
+ * * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
241
+ * * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
242
+ * * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
243
+ * * but specifically designed for React Router's request/response lifecycle.
244
+ *
245
+ * <docs-warning>Enable this API with the `future.unstable_middleware` flag.</docs-warning>
246
+ *
247
+ * If a `defaultValue` is provided, it will be returned from `context.get()`
248
+ * when no value has been set for the context. Otherwise, reading this context
249
+ * when no value has been set will throw an error.
250
+ *
251
+ * ```tsx filename=app/context.ts
252
+ * import { unstable_createContext } from "react-router";
253
+ *
254
+ * // Create a context for user data
255
+ * export const userContext =
256
+ * unstable_createContext<User | null>(null);
257
+ * ```
258
+ *
259
+ * ```tsx filename=app/middleware/auth.ts
260
+ * import { getUserFromSession } from "~/auth.server";
261
+ * import { userContext } from "~/context";
262
+ *
263
+ * export const authMiddleware = async ({
264
+ * context,
265
+ * request,
266
+ * }) => {
267
+ * const user = await getUserFromSession(request);
268
+ * context.set(userContext, user);
269
+ * };
270
+ * ```
236
271
  *
237
- * If a `defaultValue` is provided, it will be returned from `context.get()` when no value has been
238
- * set for the context. Otherwise reading this context when no value has been set will throw an
239
- * error.
272
+ * ```tsx filename=app/routes/profile.tsx
273
+ * import { userContext } from "~/context";
240
274
  *
241
- * @param defaultValue The default value for the context
242
- * @returns A context object
275
+ * export async function loader({
276
+ * context,
277
+ * }: Route.LoaderArgs) {
278
+ * const user = context.get(userContext);
279
+ *
280
+ * if (!user) {
281
+ * throw new Response("Unauthorized", { status: 401 });
282
+ * }
283
+ *
284
+ * return { user };
285
+ * }
286
+ * ```
287
+ *
288
+ * @public
289
+ * @category Utils
290
+ * @mode framework
291
+ * @mode data
292
+ * @param defaultValue An optional default value for the context. This value
293
+ * will be returned if no value has been set for this context.
294
+ * @returns A {@link unstable_RouterContext} object that can be used with
295
+ * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
296
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
243
297
  */
244
298
  declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
245
299
  /**
246
- * A Map of RouterContext objects to their initial values - used to populate a
247
- * fresh `context` value per request/navigation/fetch
248
- */
249
- type unstable_InitialContext = Map<unstable_RouterContext, unknown>;
250
- /**
251
- * Provides methods for writing/reading values in application context in a typesafe way.
300
+ * Provides methods for writing/reading values in application context in a
301
+ * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
302
+ *
303
+ * @example
304
+ * import {
305
+ * unstable_createContext,
306
+ * unstable_RouterContextProvider
307
+ * } from "react-router";
308
+ *
309
+ * const userContext = unstable_createContext<User | null>(null);
310
+ * const contextProvider = new unstable_RouterContextProvider();
311
+ * contextProvider.set(userContext, getUser());
312
+ * const user = contextProvider.get(userContext);
313
+ * // ^ User
314
+ *
315
+ * @public
316
+ * @category Utils
317
+ * @mode framework
318
+ * @mode data
252
319
  */
253
320
  declare class unstable_RouterContextProvider {
254
321
  #private;
255
- constructor(init?: unstable_InitialContext);
322
+ /**
323
+ * Create a new `unstable_RouterContextProvider` instance
324
+ * @param init An optional initial context map to populate the provider with
325
+ */
326
+ constructor(init?: Map<unstable_RouterContext, unknown>);
327
+ /**
328
+ * Access a value from the context. If no value has been set for the context,
329
+ * it will return the context's `defaultValue` if provided, or throw an error
330
+ * if no `defaultValue` was set.
331
+ * @param context The context to get the value for
332
+ * @returns The value for the context, or the context's `defaultValue` if no
333
+ * value was set
334
+ */
256
335
  get<T>(context: unstable_RouterContext<T>): T;
336
+ /**
337
+ * Set a value for the context. If the context already has a value set, this
338
+ * will overwrite it.
339
+ *
340
+ * @param context The context to set the value for
341
+ * @param value The value to set for the context
342
+ * @returns {void}
343
+ */
257
344
  set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
258
345
  }
259
- type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
346
+ type DefaultContext = MiddlewareEnabled extends true ? Readonly<unstable_RouterContextProvider> : any;
260
347
  /**
261
348
  * @private
262
349
  * Arguments passed to route loader/action functions. Same for now but we keep
@@ -278,7 +365,7 @@ interface DataFunctionArgs<Context> {
278
365
  * params.teamId;
279
366
  * // ^ string
280
367
  * }
281
- **/
368
+ */
282
369
  params: Params;
283
370
  /**
284
371
  * This is the context passed in to your server adapter's getLoadContext() function.
@@ -300,7 +387,7 @@ interface unstable_MiddlewareNextFunction<Result = unknown> {
300
387
  * a `next` function as the second parameter which will call downstream handlers
301
388
  * and then complete middlewares from the bottom-up
302
389
  */
303
- type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
390
+ type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<unstable_RouterContextProvider>>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
304
391
  /**
305
392
  * Arguments passed to loader functions
306
393
  */
@@ -406,34 +493,39 @@ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRoute
406
493
  route: Promise<void> | undefined;
407
494
  };
408
495
  /**
409
- * A boolean value indicating whether this route handler should be called in this pass.
496
+ * A boolean value indicating whether this route handler should be called in
497
+ * this pass.
410
498
  *
411
- * The `matches` array always includes _all_ matched routes even when only _some_
412
- * route handlers need to be called so that things like middleware can be implemented.
499
+ * The `matches` array always includes _all_ matched routes even when only
500
+ * _some_ route handlers need to be called so that things like middleware can
501
+ * be implemented.
413
502
  *
414
- * `shouldLoad` is usually only interesting if you are skipping the route handler
415
- * entirely and implementing custom handler logic - since it lets you determine
416
- * if that custom logic should run for this route or not.
503
+ * `shouldLoad` is usually only interesting if you are skipping the route
504
+ * handler entirely and implementing custom handler logic - since it lets you
505
+ * determine if that custom logic should run for this route or not.
417
506
  *
418
507
  * For example:
419
508
  * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
420
509
  * you'll get an array of three matches (`[parent, child, b]`), but only `b`
421
510
  * will have `shouldLoad=true` because the data for `parent` and `child` is
422
511
  * already loaded
423
- * - If you are on `/parent/child/a` and you submit to `a`'s `action`, then only
424
- * `a` will have `shouldLoad=true` for the action execution of `dataStrategy`
425
- * - After the `action`, `dataStrategy` will be called again for the `loader`
426
- * revalidation, and all matches will have `shouldLoad=true` (assuming no custom
427
- * `shouldRevalidate` implementations)
512
+ * - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
513
+ * then only `a` will have `shouldLoad=true` for the action execution of
514
+ * `dataStrategy`
515
+ * - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
516
+ * `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
517
+ * revalidation, and all matches will have `shouldLoad=true` (assuming no
518
+ * custom `shouldRevalidate` implementations)
428
519
  */
429
520
  shouldLoad: boolean;
430
521
  unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
431
522
  unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
432
523
  /**
433
524
  * An async function that will resolve any `route.lazy` implementations and
434
- * execute the route's handler (if necessary), returning a `DataStrategyResult`
525
+ * execute the route's handler (if necessary), returning a {@link DataStrategyResult}
435
526
  *
436
- * - Calling `match.resolve` does not mean you're calling the `loader`/`action`
527
+ * - Calling `match.resolve` does not mean you're calling the
528
+ * [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
437
529
  * (the "handler") - `resolve` will only call the `handler` internally if
438
530
  * needed _and_ if you don't pass your own `handlerOverride` function parameter
439
531
  * - It is safe to call `match.resolve` for all matches, even if they have
@@ -588,7 +680,28 @@ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticData
588
680
  /**
589
681
  * Matches the given routes to a location and returns the match data.
590
682
  *
683
+ * @example
684
+ * import { matchRoutes } from "react-router";
685
+ *
686
+ * let routes = [{
687
+ * path: "/",
688
+ * Component: Root,
689
+ * children: [{
690
+ * path: "dashboard",
691
+ * Component: Dashboard,
692
+ * }]
693
+ * }];
694
+ *
695
+ * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
696
+ *
697
+ * @public
591
698
  * @category Utils
699
+ * @param routes The array of route objects to match against.
700
+ * @param locationArg The location to match against, either a string path or a
701
+ * partial {@link Location} object
702
+ * @param basename Optional base path to strip from the location before matching.
703
+ * Defaults to `/`.
704
+ * @returns An array of matched routes, or `null` if no matches were found.
592
705
  */
593
706
  declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
594
707
  interface UIMatch<Data = unknown, Handle = unknown> {
@@ -596,11 +709,26 @@ interface UIMatch<Data = unknown, Handle = unknown> {
596
709
  pathname: string;
597
710
  /**
598
711
  * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
599
- **/
712
+ */
600
713
  params: AgnosticRouteMatch["params"];
601
- /** The return value from the matched route's loader or clientLoader */
602
- data: Data;
603
- /** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
714
+ /**
715
+ * The return value from the matched route's loader or clientLoader. This might
716
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
717
+ * an error and we're currently displaying an `ErrorBoundary`.
718
+ *
719
+ * @deprecated Use `UIMatch.loaderData` instead
720
+ */
721
+ data: Data | undefined;
722
+ /**
723
+ * The return value from the matched route's loader or clientLoader. This might
724
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
725
+ * an error and we're currently displaying an `ErrorBoundary`.
726
+ */
727
+ loaderData: Data | undefined;
728
+ /**
729
+ * The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
730
+ * exported from the matched route module
731
+ */
604
732
  handle: Handle;
605
733
  }
606
734
  declare class DataWithResponseInit<D> {
@@ -610,35 +738,116 @@ declare class DataWithResponseInit<D> {
610
738
  constructor(data: D, init?: ResponseInit);
611
739
  }
612
740
  /**
613
- * Create "responses" that contain `status`/`headers` without forcing
614
- * serialization into an actual `Response` - used by Remix single fetch
741
+ * Create "responses" that contain `headers`/`status` without forcing
742
+ * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
743
+ *
744
+ * @example
745
+ * import { data } from "react-router";
615
746
  *
747
+ * export async function action({ request }: Route.ActionArgs) {
748
+ * let formData = await request.formData();
749
+ * let item = await createItem(formData);
750
+ * return data(item, {
751
+ * headers: { "X-Custom-Header": "value" }
752
+ * status: 201,
753
+ * });
754
+ * }
755
+ *
756
+ * @public
616
757
  * @category Utils
758
+ * @mode framework
759
+ * @mode data
760
+ * @param data The data to be included in the response.
761
+ * @param init The status code or a `ResponseInit` object to be included in the
762
+ * response.
763
+ * @returns A {@link DataWithResponseInit} instance containing the data and
764
+ * response init.
617
765
  */
618
766
  declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
619
767
  type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
620
768
  /**
621
- * A redirect response. Sets the status code and the `Location` header.
622
- * Defaults to "302 Found".
769
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
770
+ * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
771
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
772
+ *
773
+ * @example
774
+ * import { redirect } from "react-router";
623
775
  *
776
+ * export async function loader({ request }: Route.LoaderArgs) {
777
+ * if (!isLoggedIn(request))
778
+ * throw redirect("/login");
779
+ * }
780
+ *
781
+ * // ...
782
+ * }
783
+ *
784
+ * @public
624
785
  * @category Utils
786
+ * @mode framework
787
+ * @mode data
788
+ * @param url The URL to redirect to.
789
+ * @param init The status code or a `ResponseInit` object to be included in the
790
+ * response.
791
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
792
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
793
+ * header.
625
794
  */
626
795
  declare const redirect$1: RedirectFunction;
627
796
  /**
628
- * A redirect response that will force a document reload to the new location.
629
- * Sets the status code and the `Location` header.
630
- * Defaults to "302 Found".
797
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
798
+ * that will force a document reload to the new location. Sets the status code
799
+ * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
800
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
631
801
  *
802
+ * ```tsx filename=routes/logout.tsx
803
+ * import { redirectDocument } from "react-router";
804
+ *
805
+ * import { destroySession } from "../sessions.server";
806
+ *
807
+ * export async function action({ request }: Route.ActionArgs) {
808
+ * let session = await getSession(request.headers.get("Cookie"));
809
+ * return redirectDocument("/", {
810
+ * headers: { "Set-Cookie": await destroySession(session) }
811
+ * });
812
+ * }
813
+ * ```
814
+ *
815
+ * @public
632
816
  * @category Utils
817
+ * @mode framework
818
+ * @mode data
819
+ * @param url The URL to redirect to.
820
+ * @param init The status code or a `ResponseInit` object to be included in the
821
+ * response.
822
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
823
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
824
+ * header.
633
825
  */
634
826
  declare const redirectDocument$1: RedirectFunction;
635
827
  /**
636
- * A redirect response that will perform a `history.replaceState` instead of a
637
- * `history.pushState` for client-side navigation redirects.
638
- * Sets the status code and the `Location` header.
639
- * Defaults to "302 Found".
828
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
829
+ * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
830
+ * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
831
+ * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
832
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
833
+ *
834
+ * @example
835
+ * import { replace } from "react-router";
836
+ *
837
+ * export async function loader() {
838
+ * return replace("/new-location");
839
+ * }
640
840
  *
841
+ * @public
641
842
  * @category Utils
843
+ * @mode framework
844
+ * @mode data
845
+ * @param url The URL to redirect to.
846
+ * @param init The status code or a `ResponseInit` object to be included in the
847
+ * response.
848
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
849
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
850
+ * header.
642
851
  */
643
852
  declare const replace$1: RedirectFunction;
644
853
 
@@ -916,7 +1125,7 @@ interface RouterInit {
916
1125
  routes: AgnosticRouteObject[];
917
1126
  history: History;
918
1127
  basename?: string;
919
- unstable_getContext?: () => MaybePromise<unstable_InitialContext>;
1128
+ unstable_getContext?: () => MaybePromise<unstable_RouterContextProvider>;
920
1129
  mapRouteProperties?: MapRoutePropertiesFunction;
921
1130
  future?: Partial<FutureConfig>;
922
1131
  hydrationRouteProperties?: string[];
@@ -951,14 +1160,13 @@ interface StaticHandler {
951
1160
  skipLoaderErrorBubbling?: boolean;
952
1161
  skipRevalidation?: boolean;
953
1162
  dataStrategy?: DataStrategyFunction<unknown>;
954
- unstable_respond?: (staticContext: StaticHandlerContext) => MaybePromise<Response>;
955
- unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
1163
+ unstable_generateMiddlewareResponse?: (query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
956
1164
  }): Promise<StaticHandlerContext | Response>;
957
1165
  queryRoute(request: Request, opts?: {
958
1166
  routeId?: string;
959
1167
  requestContext?: unknown;
960
1168
  dataStrategy?: DataStrategyFunction<unknown>;
961
- unstable_respond?: (res: Response) => MaybePromise<Response>;
1169
+ unstable_generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
962
1170
  }): Promise<any>;
963
1171
  }
964
1172
  type ViewTransitionOpts = {
@@ -1334,7 +1542,13 @@ type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">
1334
1542
  });
1335
1543
  interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1336
1544
  /**
1337
- * The absolute path of the page to prefetch.
1545
+ * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
1546
+ * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
1547
+ * element
1548
+ */
1549
+ nonce?: string | undefined;
1550
+ /**
1551
+ * The absolute path of the page to prefetch, e.g. `/absolute/path`.
1338
1552
  */
1339
1553
  page: string;
1340
1554
  }
@@ -1397,7 +1611,7 @@ type ClientDataFunctionArgs<Params> = {
1397
1611
  * from your route middlewares. You may pass in initial context values in your
1398
1612
  * `<HydratedRouter unstable_getContext>` prop
1399
1613
  */
1400
- context: unstable_RouterContextProvider;
1614
+ context: Readonly<unstable_RouterContextProvider>;
1401
1615
  };
1402
1616
  type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
1403
1617
  ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
@@ -1450,7 +1664,9 @@ interface LinksFunction {
1450
1664
  interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1451
1665
  id: RouteId;
1452
1666
  pathname: DataRouteMatch["pathname"];
1667
+ /** @deprecated Use `MetaMatch.loaderData` instead */
1453
1668
  data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1669
+ loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1454
1670
  handle?: RouteHandle;
1455
1671
  params: DataRouteMatch["params"];
1456
1672
  meta: MetaDescriptor[];
@@ -1460,7 +1676,9 @@ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoad
1460
1676
  [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1461
1677
  }[keyof MatchLoaders]>;
1462
1678
  interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1679
+ /** @deprecated Use `MetaArgs.loaderData` instead */
1463
1680
  data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1681
+ loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1464
1682
  params: Params;
1465
1683
  location: Location;
1466
1684
  matches: MetaMatches<MatchLoaders>;
@@ -1555,12 +1773,6 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1555
1773
  */
1556
1774
  type RouteHandle = unknown;
1557
1775
 
1558
- type ServerContext = {
1559
- redirect?: Response;
1560
- };
1561
- declare global {
1562
- var ___reactRouterServerStorage___: AsyncLocalStorage<ServerContext> | undefined;
1563
- }
1564
1776
  declare const redirect: typeof redirect$1;
1565
1777
  declare const redirectDocument: typeof redirectDocument$1;
1566
1778
  declare const replace: typeof replace$1;
@@ -1661,8 +1873,11 @@ type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
1661
1873
  }) => Promise<unknown[]>;
1662
1874
  type LoadServerActionFunction = (id: string) => Promise<Function>;
1663
1875
  /**
1664
- * Matches the given routes to a Request and returns a RSC Response encoding an
1665
- * `RSCPayload` for consumption by a RSC enabled client router.
1876
+ * Matches the given routes to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
1877
+ * and returns an [RSC](https://react.dev/reference/rsc/server-components)
1878
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1879
+ * encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
1880
+ * enabled client router.
1666
1881
  *
1667
1882
  * @example
1668
1883
  * import {
@@ -1699,27 +1914,33 @@ type LoadServerActionFunction = (id: string) => Promise<Function>;
1699
1914
  * @mode data
1700
1915
  * @param opts Options
1701
1916
  * @param opts.basename The basename to use when matching the request.
1917
+ * @param opts.createTemporaryReferenceSet A function that returns a temporary
1918
+ * reference set for the request, used to track temporary references in the [RSC](https://react.dev/reference/rsc/server-components)
1919
+ * stream.
1702
1920
  * @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
1703
1921
  * function, responsible for loading a server action.
1922
+ * @param opts.decodeFormState A function responsible for decoding form state for
1923
+ * progressively enhanceable forms with React's [`useActionState`](https://react.dev/reference/react/useActionState)
1924
+ * using your `react-server-dom-xyz/server`'s `decodeFormState`.
1704
1925
  * @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
1705
1926
  * function, used to decode the server function's arguments and bind them to the
1706
1927
  * implementation for invocation by the router.
1707
- * @param opts.decodeFormState A function responsible for decoding form state for
1708
- * progressively enhanceable forms with `useActionState` using your
1709
- * `react-server-dom-xyz/server`'s `decodeFormState`.
1710
1928
  * @param opts.generateResponse A function responsible for using your
1711
- * `renderToReadableStream` to generate a Response encoding the `RSCPayload`.
1929
+ * `renderToReadableStream` to generate a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1930
+ * encoding the {@link unstable_RSCPayload}.
1712
1931
  * @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
1713
1932
  * `loadServerAction` function, used to load a server action by ID.
1714
- * @param opts.request The request to match against.
1715
- * @param opts.requestContext An instance of `unstable_RouterContextProvider`
1716
- * that should be created per request, to be passed to loaders, actions and middleware.
1717
- * @param opts.routes Your route definitions.
1718
- * @param opts.createTemporaryReferenceSet A function that returns a temporary
1719
- * reference set for the request, used to track temporary references in the RSC stream.
1720
1933
  * @param opts.onError An optional error handler that will be called with any
1721
1934
  * errors that occur during the request processing.
1722
- * @returns A Response that contains the RSC data for hydration.
1935
+ * @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
1936
+ * to match against.
1937
+ * @param opts.requestContext An instance of {@link unstable_RouterContextProvider}
1938
+ * that should be created per request, to be passed to [`action`](../../start/data/route-object#action)s,
1939
+ * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
1940
+ * @param opts.routes Your {@link unstable_RSCRouteConfigEntry | route definitions}.
1941
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1942
+ * that contains the [RSC](https://react.dev/reference/rsc/server-components)
1943
+ * data for hydration.
1723
1944
  */
1724
1945
  declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
1725
1946
  createTemporaryReferenceSet: () => unknown;