react-router 0.0.0-experimental-2a6c7bc → 0.0.0-experimental-e89ad3012

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 (61) hide show
  1. package/dist/development/{chunk-VEWXUMGM.mjs → chunk-3O4L5GVQ.mjs} +90 -125
  2. package/dist/development/{chunk-JRLTRGBE.js → chunk-JJHCVRDZ.js} +89 -124
  3. package/dist/development/{chunk-GSZ4XTPZ.js → chunk-ROJMZUUV.js} +130 -130
  4. package/dist/{production/chunk-ATNMTWNA.mjs → development/chunk-XKV32KFX.mjs} +157 -141
  5. package/dist/development/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
  6. package/dist/development/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
  7. package/dist/development/dom-export.d.mts +3 -3
  8. package/dist/development/dom-export.d.ts +1 -1
  9. package/dist/development/dom-export.js +3 -3
  10. package/dist/development/dom-export.mjs +3 -3
  11. package/dist/{production/index-react-server-client-DIZWnqdE.d.ts → development/index-react-server-client-D-lyvxf_.d.ts} +25 -26
  12. package/dist/{production/index-react-server-client-BuCmY0hu.d.mts → development/index-react-server-client-pe1TAKAq.d.mts} +12 -13
  13. package/dist/development/index-react-server-client.d.mts +4 -4
  14. package/dist/development/index-react-server-client.d.ts +2 -2
  15. package/dist/development/index-react-server-client.js +4 -4
  16. package/dist/development/index-react-server-client.mjs +2 -2
  17. package/dist/development/index-react-server.d.mts +193 -14
  18. package/dist/development/index-react-server.d.ts +193 -14
  19. package/dist/development/index-react-server.js +115 -147
  20. package/dist/development/index-react-server.mjs +115 -147
  21. package/dist/development/index.d.mts +8 -8
  22. package/dist/development/index.d.ts +4 -4
  23. package/dist/development/index.js +240 -224
  24. package/dist/development/index.mjs +3 -3
  25. package/dist/development/lib/types/internal.d.mts +2 -2
  26. package/dist/development/lib/types/internal.d.ts +1 -1
  27. package/dist/development/lib/types/internal.js +1 -1
  28. package/dist/development/lib/types/internal.mjs +1 -1
  29. package/dist/development/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
  30. package/dist/development/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
  31. package/dist/{development/chunk-M2KD4YIT.mjs → production/chunk-J6PLTU3O.mjs} +157 -141
  32. package/dist/production/{chunk-3UOGQQWX.js → chunk-NFNPXIQE.js} +89 -124
  33. package/dist/production/{chunk-P2JVUBYL.mjs → chunk-QI3NR5VQ.mjs} +90 -125
  34. package/dist/production/{chunk-ZIOZTUIH.js → chunk-X3M2F3OK.js} +130 -130
  35. package/dist/production/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
  36. package/dist/production/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
  37. package/dist/production/dom-export.d.mts +3 -3
  38. package/dist/production/dom-export.d.ts +1 -1
  39. package/dist/production/dom-export.js +3 -3
  40. package/dist/production/dom-export.mjs +3 -3
  41. package/dist/{development/index-react-server-client-DIZWnqdE.d.ts → production/index-react-server-client-D-lyvxf_.d.ts} +25 -26
  42. package/dist/{development/index-react-server-client-BuCmY0hu.d.mts → production/index-react-server-client-pe1TAKAq.d.mts} +12 -13
  43. package/dist/production/index-react-server-client.d.mts +4 -4
  44. package/dist/production/index-react-server-client.d.ts +2 -2
  45. package/dist/production/index-react-server-client.js +4 -4
  46. package/dist/production/index-react-server-client.mjs +2 -2
  47. package/dist/production/index-react-server.d.mts +193 -14
  48. package/dist/production/index-react-server.d.ts +193 -14
  49. package/dist/production/index-react-server.js +115 -147
  50. package/dist/production/index-react-server.mjs +115 -147
  51. package/dist/production/index.d.mts +8 -8
  52. package/dist/production/index.d.ts +4 -4
  53. package/dist/production/index.js +240 -224
  54. package/dist/production/index.mjs +3 -3
  55. package/dist/production/lib/types/internal.d.mts +2 -2
  56. package/dist/production/lib/types/internal.d.ts +1 -1
  57. package/dist/production/lib/types/internal.js +1 -1
  58. package/dist/production/lib/types/internal.mjs +1 -1
  59. package/dist/production/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
  60. package/dist/production/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
  61. package/package.json +1 -1
@@ -227,27 +227,117 @@ type Submission = {
227
227
  json: undefined;
228
228
  text: string;
229
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
+ */
230
235
  interface unstable_RouterContext<T = unknown> {
231
236
  defaultValue?: T;
232
237
  }
233
238
  /**
234
- * Creates a context object that may be used to store and retrieve arbitrary values.
239
+ * Creates a type-safe context object that can be used to store and retrieve
240
+ * values in middleware, [loaders](../../start/framework/route-module#loader),
241
+ * and [actions](../../start/framework/route-module#action). Similar to React's
242
+ * [`createContext`](https://react.dev/reference/react/createContext), but
243
+ * designed for React Router's request/response lifecycle.
244
+ *
245
+ * If a `defaultValue` is provided, it will be returned from `context.get()` when
246
+ * no value has been set for the context. Otherwise reading this context when no
247
+ * value has been set will throw an error.
235
248
  *
236
- * If a `defaultValue` is provided, it will be returned from `context.get()` when no value has been
237
- * set for the context. Otherwise reading this context when no value has been set will throw an
238
- * error.
249
+ * ```tsx filename=app/context.ts
250
+ * import { unstable_createContext } from "react-router";
251
+ *
252
+ * // Create a context for user data
253
+ * export const userContext =
254
+ * unstable_createContext<User | null>(null);
255
+ * ```
256
+ *
257
+ * ```tsx filename=app/middleware/auth.ts
258
+ * import { userContext } from "~/context";
259
+ * import { getUserFromSession } from "~/auth.server";
260
+ *
261
+ * export const authMiddleware = async ({
262
+ * request,
263
+ * context,
264
+ * }) => {
265
+ * const user = await getUserFromSession(request);
266
+ * context.set(userContext, user);
267
+ * };
268
+ * ```
239
269
  *
240
- * @param defaultValue The default value for the context
241
- * @returns A context object
270
+ * ```tsx filename=app/routes/profile.tsx
271
+ * import { userContext } from "~/context";
272
+ *
273
+ * export async function loader({
274
+ * context,
275
+ * }: Route.LoaderArgs) {
276
+ * const user = context.get(userContext);
277
+ *
278
+ * if (!user) {
279
+ * throw new Response("Unauthorized", { status: 401 });
280
+ * }
281
+ *
282
+ * return { user };
283
+ * }
284
+ * ```
285
+ *
286
+ * @public
287
+ * @category Utils
288
+ * @mode framework
289
+ * @mode data
290
+ * @param defaultValue An optional default value for the context. This value will
291
+ * be returned if no value has been set for this context.
292
+ * @returns A {@link unstable_RouterContext} object that can be used with
293
+ * `context.get()` and `context.set()` in middleware, loaders, and actions.
242
294
  */
243
295
  declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
244
296
  /**
245
- * Provides methods for writing/reading values in application context in a typesafe way.
297
+ * Provides methods for writing/reading values in application context in a
298
+ * type-safe way. Primarily for usage with [Middleware](../../how-to/middleware).
299
+ *
300
+ * @example
301
+ * import {
302
+ * unstable_createContext,
303
+ * unstable_RouterContextProvider
304
+ * } from "react-router";
305
+ *
306
+ * const userContext = unstable_createContext<User | null>(null);
307
+ * const contextProvider = new unstable_RouterContextProvider();
308
+ * contextProvider.set(userContext, getUser());
309
+ * const user = contextProvider.get(userContext);
310
+ * // ^ User
311
+ *
312
+ * @public
313
+ * @category Utils
314
+ * @mode framework
315
+ * @mode data
246
316
  */
247
317
  declare class unstable_RouterContextProvider {
248
318
  #private;
319
+ /**
320
+ * Create a new `unstable_RouterContextProvider` instance
321
+ * @param init An optional initial context map to populate the provider with
322
+ */
249
323
  constructor(init?: Map<unstable_RouterContext, unknown>);
324
+ /**
325
+ * Access a value from the context. If no value has been set for the
326
+ * context, it will return the context's `defaultValue` if provided, or throw an
327
+ * error if no `defaultValue` was set.
328
+ * @param context The context to get the value for
329
+ * @returns The value for the context, or the contexts `defaultValue` if no
330
+ * value was set
331
+ */
250
332
  get<T>(context: unstable_RouterContext<T>): T;
333
+ /**
334
+ * Set a value for the context. If the context already has a value set,
335
+ * this will overwrite it.
336
+ *
337
+ * @param context The context to set the value for
338
+ * @param value The value to set for the context
339
+ * @returns {void}
340
+ */
251
341
  set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
252
342
  }
253
343
  type DefaultContext = MiddlewareEnabled extends true ? Readonly<unstable_RouterContextProvider> : any;
@@ -272,7 +362,7 @@ interface DataFunctionArgs<Context> {
272
362
  * params.teamId;
273
363
  * // ^ string
274
364
  * }
275
- **/
365
+ */
276
366
  params: Params;
277
367
  /**
278
368
  * This is the context passed in to your server adapter's getLoadContext() function.
@@ -587,7 +677,27 @@ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticData
587
677
  /**
588
678
  * Matches the given routes to a location and returns the match data.
589
679
  *
680
+ * @example
681
+ * import { matchRoutes } from "react-router";
682
+ *
683
+ * let routes = [{
684
+ * path: "/",
685
+ * Component: Root,
686
+ * children: [{
687
+ * path: "dashboard",
688
+ * Component: Dashboard,
689
+ * }]
690
+ * }];
691
+ *
692
+ * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
693
+ *
694
+ * @public
590
695
  * @category Utils
696
+ * @param routes The array of route objects to match against.
697
+ * @param locationArg The location to match against, either a string path or a
698
+ * partial {@link Location} object
699
+ * @param basename Optional base path to strip from the location before matching.
700
+ * @returns An array of matched routes, or `null` if no matches were found.
591
701
  */
592
702
  declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
593
703
  interface UIMatch<Data = unknown, Handle = unknown> {
@@ -595,7 +705,7 @@ interface UIMatch<Data = unknown, Handle = unknown> {
595
705
  pathname: string;
596
706
  /**
597
707
  * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
598
- **/
708
+ */
599
709
  params: AgnosticRouteMatch["params"];
600
710
  /**
601
711
  * The return value from the matched route's loader or clientLoader
@@ -616,9 +726,29 @@ declare class DataWithResponseInit<D> {
616
726
  }
617
727
  /**
618
728
  * Create "responses" that contain `status`/`headers` without forcing
619
- * serialization into an actual `Response` - used by Remix single fetch
729
+ * serialization into an actual `Response`
620
730
  *
731
+ * @example
732
+ * import { data } from "react-router";
733
+ *
734
+ * export async function action({ request }) {
735
+ * let formData = await request.formData();
736
+ * let item = await createItem(formData);
737
+ * return data(item, {
738
+ * status: 201,
739
+ * headers: { "X-Custom-Header": "value" }
740
+ * });
741
+ * }
742
+ *
743
+ * @public
621
744
  * @category Utils
745
+ * @mode framework
746
+ * @mode data
747
+ * @param data The data to be included in the response.
748
+ * @param init The status code or a `ResponseInit` object to be included in the
749
+ * response.
750
+ * @returns A `DataWithResponseInit` instance containing the data and response
751
+ * init.
622
752
  */
623
753
  declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
624
754
  type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
@@ -626,7 +756,25 @@ type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
626
756
  * A redirect response. Sets the status code and the `Location` header.
627
757
  * Defaults to "302 Found".
628
758
  *
759
+ * @example
760
+ * import { redirect } from "react-router";
761
+ *
762
+ * export function loader({ request }) {
763
+ * if (!isLoggedIn(request))
764
+ * throw redirect("/login");
765
+ * }
766
+ *
767
+ * // ...
768
+ * }
769
+ *
770
+ * @public
629
771
  * @category Utils
772
+ * @mode framework
773
+ * @mode data
774
+ * @param url The URL to redirect to.
775
+ * @param init The status code or a `ResponseInit` object to be included in the
776
+ * response.
777
+ * @returns A `Response` object with the redirect status and `Location` header.
630
778
  */
631
779
  declare const redirect$1: RedirectFunction;
632
780
  /**
@@ -634,7 +782,26 @@ declare const redirect$1: RedirectFunction;
634
782
  * Sets the status code and the `Location` header.
635
783
  * Defaults to "302 Found".
636
784
  *
785
+ * @example
786
+ * // routes/logout.tsx
787
+ * import { redirectDocument } from "react-router";
788
+ * import { destroySession } from "../sessions.server";
789
+ *
790
+ * export async function action({ request }) {
791
+ * let session = await getSession(request.headers.get("Cookie"));
792
+ * return redirectDocument("/", {
793
+ * headers: { "Set-Cookie": await destroySession(session) }
794
+ * });
795
+ * }
796
+ *
797
+ * @public
637
798
  * @category Utils
799
+ * @mode framework
800
+ * @mode data
801
+ * @param url The URL to redirect to.
802
+ * @param init The status code or a `ResponseInit` object to be included in the
803
+ * response.
804
+ * @returns A `Response` object with the redirect status and `Location` header.
638
805
  */
639
806
  declare const redirectDocument$1: RedirectFunction;
640
807
  /**
@@ -643,7 +810,21 @@ declare const redirectDocument$1: RedirectFunction;
643
810
  * Sets the status code and the `Location` header.
644
811
  * Defaults to "302 Found".
645
812
  *
813
+ * @example
814
+ * import { replace } from "react-router";
815
+ *
816
+ * export function loader() {
817
+ * return replace("/new-location");
818
+ * }
819
+ *
820
+ * @public
646
821
  * @category Utils
822
+ * @mode framework
823
+ * @mode data
824
+ * @param url The URL to redirect to.
825
+ * @param init The status code or a `ResponseInit` object to be included in the
826
+ * response.
827
+ * @returns A `Response` object with the redirect status and `Location` header.
647
828
  */
648
829
  declare const replace$1: RedirectFunction;
649
830
 
@@ -956,15 +1137,13 @@ interface StaticHandler {
956
1137
  skipLoaderErrorBubbling?: boolean;
957
1138
  skipRevalidation?: boolean;
958
1139
  dataStrategy?: DataStrategyFunction<unknown>;
959
- unstable_respond?: (staticContext: StaticHandlerContext) => MaybePromise<Response>;
960
- unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
1140
+ unstable_generateMiddlewareResponse?: (query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
961
1141
  }): Promise<StaticHandlerContext | Response>;
962
1142
  queryRoute(request: Request, opts?: {
963
1143
  routeId?: string;
964
1144
  requestContext?: unknown;
965
1145
  dataStrategy?: DataStrategyFunction<unknown>;
966
- unstable_respond?: (res: Response) => MaybePromise<Response>;
967
- unstable_stream?: (context: unstable_RouterContextProvider, queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
1146
+ unstable_generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
968
1147
  }): Promise<any>;
969
1148
  }
970
1149
  type ViewTransitionOpts = {