react-router 8.4.0 → 8.5.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 +51 -1
- package/dist/development/dom-export.d.ts +2 -1
- package/dist/development/dom-export.js +1 -1
- package/dist/development/index-react-server-client.js +2 -2
- package/dist/development/index-react-server.d.ts +583 -165
- package/dist/development/index-react-server.js +27 -19
- package/dist/development/index.d.ts +9 -8
- package/dist/development/index.js +5 -4
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/components.js +22 -3
- package/dist/development/lib/context.d.ts +6 -1
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.d.ts +3 -0
- package/dist/development/lib/dom/dom.js +1 -1
- package/dist/development/lib/dom/global.d.ts +35 -0
- package/dist/development/lib/dom/lib.d.ts +34 -9
- package/dist/development/lib/dom/lib.js +17 -6
- package/dist/development/lib/dom/server.js +2 -2
- package/dist/development/lib/dom/ssr/components.js +12 -9
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/entry.d.ts +9 -2
- package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/development/lib/dom/ssr/fallback.js +1 -1
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +3 -2
- package/dist/development/lib/dom/ssr/fog-of-war.js +14 -11
- package/dist/development/lib/dom/ssr/hydration.js +1 -1
- package/dist/development/lib/dom/ssr/invariant.js +1 -1
- package/dist/development/lib/dom/ssr/links.js +1 -1
- package/dist/development/lib/dom/ssr/markup.js +1 -1
- package/dist/development/lib/dom/ssr/route-discovery.d.ts +120 -0
- package/dist/development/lib/dom/ssr/route-discovery.js +415 -0
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +2 -2
- package/dist/development/lib/dom/ssr/routes.d.ts +2 -2
- package/dist/development/lib/dom/ssr/routes.js +8 -8
- package/dist/development/lib/dom/ssr/server.js +3 -1
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +28 -2
- package/dist/development/lib/dom/ssr/single-fetch.js +73 -55
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.d.ts +28 -0
- package/dist/development/lib/dom-export/hydrated-router.js +32 -12
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.d.ts +3 -3
- package/dist/development/lib/hooks.js +4 -4
- package/dist/development/lib/href.js +1 -1
- package/dist/development/lib/router/history.js +1 -1
- package/dist/development/lib/router/instrumentation.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/development/lib/router/matcher.js +1 -1
- package/dist/development/lib/router/navigation.js +1 -1
- package/dist/development/lib/router/router.d.ts +6 -0
- package/dist/development/lib/router/router.js +157 -65
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +24 -4
- package/dist/development/lib/router/utils.js +4 -3
- package/dist/development/lib/rsc/browser.js +2 -2
- package/dist/development/lib/rsc/errorBoundaries.js +1 -1
- package/dist/development/lib/rsc/html-stream/browser.js +1 -1
- package/dist/development/lib/rsc/html-stream/server.js +24 -12
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +3 -2
- package/dist/development/lib/rsc/server.ssr.js +1 -1
- package/dist/development/lib/server-runtime/build.d.ts +14 -0
- package/dist/development/lib/server-runtime/cookies.js +1 -1
- package/dist/development/lib/server-runtime/crypto.js +1 -1
- package/dist/development/lib/server-runtime/data.js +1 -1
- package/dist/development/lib/server-runtime/dev.js +1 -1
- package/dist/development/lib/server-runtime/entry.js +1 -1
- package/dist/development/lib/server-runtime/errors.js +1 -1
- package/dist/development/lib/server-runtime/headers.js +1 -1
- package/dist/development/lib/server-runtime/invariant.js +1 -1
- package/dist/development/lib/server-runtime/mode.js +1 -1
- package/dist/development/lib/server-runtime/routeMatching.js +1 -1
- package/dist/development/lib/server-runtime/routes.d.ts +1 -1
- package/dist/development/lib/server-runtime/routes.js +1 -1
- package/dist/development/lib/server-runtime/server.js +12 -4
- package/dist/development/lib/server-runtime/serverHandoff.d.ts +17 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions.js +1 -1
- package/dist/development/lib/server-runtime/single-fetch.js +1 -1
- package/dist/development/lib/server-runtime/urls.js +1 -1
- package/dist/development/lib/server-runtime/warnings.js +1 -1
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/route-data.d.ts +2 -2
- package/dist/development/lib/types/route-module-annotations.d.ts +1 -1
- package/dist/development/route-pattern.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
- package/dist/production/dom-export.d.ts +2 -1
- package/dist/production/dom-export.js +1 -1
- package/dist/production/index-react-server-client.js +2 -2
- package/dist/production/index-react-server.d.ts +583 -165
- package/dist/production/index-react-server.js +27 -19
- package/dist/production/index.d.ts +9 -8
- package/dist/production/index.js +5 -4
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/components.js +22 -3
- package/dist/production/lib/context.d.ts +6 -1
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.d.ts +3 -0
- package/dist/production/lib/dom/dom.js +1 -1
- package/dist/production/lib/dom/global.d.ts +35 -0
- package/dist/production/lib/dom/lib.d.ts +34 -9
- package/dist/production/lib/dom/lib.js +17 -6
- package/dist/production/lib/dom/server.js +2 -2
- package/dist/production/lib/dom/ssr/components.js +12 -9
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/entry.d.ts +9 -2
- package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/production/lib/dom/ssr/fallback.js +1 -1
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +3 -2
- package/dist/production/lib/dom/ssr/fog-of-war.js +14 -11
- package/dist/production/lib/dom/ssr/hydration.js +1 -1
- package/dist/production/lib/dom/ssr/invariant.js +1 -1
- package/dist/production/lib/dom/ssr/links.js +1 -1
- package/dist/production/lib/dom/ssr/markup.js +1 -1
- package/dist/production/lib/dom/ssr/route-discovery.d.ts +120 -0
- package/dist/production/lib/dom/ssr/route-discovery.js +415 -0
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +2 -2
- package/dist/production/lib/dom/ssr/routes.d.ts +2 -2
- package/dist/production/lib/dom/ssr/routes.js +8 -8
- package/dist/production/lib/dom/ssr/server.js +3 -1
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +28 -2
- package/dist/production/lib/dom/ssr/single-fetch.js +73 -55
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.d.ts +28 -0
- package/dist/production/lib/dom-export/hydrated-router.js +32 -12
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.d.ts +3 -3
- package/dist/production/lib/hooks.js +3 -3
- package/dist/production/lib/href.js +1 -1
- package/dist/production/lib/router/history.js +1 -1
- package/dist/production/lib/router/instrumentation.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/production/lib/router/matcher.js +1 -1
- package/dist/production/lib/router/navigation.js +1 -1
- package/dist/production/lib/router/router.d.ts +6 -0
- package/dist/production/lib/router/router.js +157 -65
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +24 -4
- package/dist/production/lib/router/utils.js +4 -3
- package/dist/production/lib/rsc/browser.js +2 -2
- package/dist/production/lib/rsc/errorBoundaries.js +1 -1
- package/dist/production/lib/rsc/html-stream/browser.js +1 -1
- package/dist/production/lib/rsc/html-stream/server.js +24 -12
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +3 -2
- package/dist/production/lib/rsc/server.ssr.js +1 -1
- package/dist/production/lib/server-runtime/build.d.ts +14 -0
- package/dist/production/lib/server-runtime/cookies.js +1 -1
- package/dist/production/lib/server-runtime/crypto.js +1 -1
- package/dist/production/lib/server-runtime/data.js +1 -1
- package/dist/production/lib/server-runtime/dev.js +1 -1
- package/dist/production/lib/server-runtime/entry.js +1 -1
- package/dist/production/lib/server-runtime/errors.js +1 -1
- package/dist/production/lib/server-runtime/headers.js +1 -1
- package/dist/production/lib/server-runtime/invariant.js +1 -1
- package/dist/production/lib/server-runtime/mode.js +1 -1
- package/dist/production/lib/server-runtime/routeMatching.js +1 -1
- package/dist/production/lib/server-runtime/routes.d.ts +1 -1
- package/dist/production/lib/server-runtime/routes.js +1 -1
- package/dist/production/lib/server-runtime/server.js +12 -4
- package/dist/production/lib/server-runtime/serverHandoff.d.ts +17 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions.js +1 -1
- package/dist/production/lib/server-runtime/single-fetch.js +1 -1
- package/dist/production/lib/server-runtime/urls.js +1 -1
- package/dist/production/lib/server-runtime/warnings.js +1 -1
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/route-data.d.ts +2 -2
- package/dist/production/lib/types/route-module-annotations.d.ts +1 -1
- package/dist/production/route-pattern.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/explanation/lazy-route-discovery.md +4 -0
- package/docs/explanation/sessions-and-cookies.md +108 -4
- package/docs/how-to/custom-fetch.md +218 -0
- package/docs/how-to/data-strategy.md +23 -1
- package/docs/how-to/middleware.md +1 -0
- package/docs/how-to/optimize-revalidation.md +2 -2
- package/docs/how-to/pre-rendering.md +23 -1
- package/docs/how-to/route-discovery.md +145 -0
- package/docs/how-to/spa.md +2 -0
- package/docs/how-to/view-transitions.md +80 -13
- package/docs/start/framework/navigating.md +5 -9
- package/docs/start/framework/rendering.md +37 -0
- package/package.json +9 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import { ComponentType, ReactElement } from "react";
|
|
3
4
|
import { CookieParseOptions, CookieParseOptions as CookieParseOptions$1, CookieSerializeOptions, CookieSerializeOptions as CookieSerializeOptions$1 } from "cookie-es";
|
|
4
5
|
import { 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";
|
|
5
6
|
import { ReactFormState } from "react-dom/client";
|
|
@@ -556,6 +557,11 @@ interface DataStrategyMatch extends RouteMatch<string, DataRouteObject> {
|
|
|
556
557
|
*/
|
|
557
558
|
resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
|
|
558
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* The operation that initiated a data strategy execution. Static handler
|
|
562
|
+
* executions use `"static"`.
|
|
563
|
+
*/
|
|
564
|
+
type DataStrategyInitiator = "initialization" | "navigation" | "fetcher" | "revalidation" | "static";
|
|
559
565
|
interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
|
|
560
566
|
/**
|
|
561
567
|
* Matches for this route extended with Data strategy APIs
|
|
@@ -563,8 +569,23 @@ interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctio
|
|
|
563
569
|
matches: DataStrategyMatch[];
|
|
564
570
|
runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
|
|
565
571
|
/**
|
|
566
|
-
* The
|
|
567
|
-
*
|
|
572
|
+
* The operation that initiated this data strategy execution
|
|
573
|
+
*
|
|
574
|
+
* This field is experimental and subject to breaking changes.
|
|
575
|
+
*/
|
|
576
|
+
unstable_initiator: DataStrategyInitiator;
|
|
577
|
+
/**
|
|
578
|
+
* The history action (`"PUSH"`, `"REPLACE"`, or `"POP"`) for a navigation-
|
|
579
|
+
* initiated execution, including fetchers reloaded by that navigation.
|
|
580
|
+
* `null` for initialization, fetcher, revalidation, and static executions.
|
|
581
|
+
*
|
|
582
|
+
* This field is experimental and subject to breaking changes.
|
|
583
|
+
*/
|
|
584
|
+
unstable_navigationType: Action | null;
|
|
585
|
+
/**
|
|
586
|
+
* The key of the fetcher targeted by this data strategy execution, otherwise
|
|
587
|
+
* `null`. Fetchers reloaded during a navigation or revalidation retain that
|
|
588
|
+
* `unstable_initiator` while providing their key here.
|
|
568
589
|
*/
|
|
569
590
|
fetcherKey: string | null;
|
|
570
591
|
}
|
|
@@ -816,6 +837,30 @@ interface UIMatch<Data = unknown, Handle = unknown> {
|
|
|
816
837
|
*/
|
|
817
838
|
handle: Handle;
|
|
818
839
|
}
|
|
840
|
+
interface RouteMeta<RouteObjectType extends RouteObject = RouteObject> {
|
|
841
|
+
relativePath: string;
|
|
842
|
+
caseSensitive: boolean;
|
|
843
|
+
childrenIndex: number;
|
|
844
|
+
route: RouteObjectType;
|
|
845
|
+
matcher?: RegExp;
|
|
846
|
+
compiledParams?: CompiledPathParam[];
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* @private
|
|
850
|
+
* PRIVATE - DO NOT USE
|
|
851
|
+
*
|
|
852
|
+
* A "branch" of routes that match a given route pattern.
|
|
853
|
+
* This is an internal interface not intended for direct external usage.
|
|
854
|
+
*/
|
|
855
|
+
interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
|
|
856
|
+
path: string;
|
|
857
|
+
score: number;
|
|
858
|
+
routesMeta: RouteMeta<RouteObjectType>[];
|
|
859
|
+
}
|
|
860
|
+
type CompiledPathParam = {
|
|
861
|
+
paramName: string;
|
|
862
|
+
isOptional?: boolean;
|
|
863
|
+
};
|
|
819
864
|
declare class DataWithResponseInit<D> {
|
|
820
865
|
type: string;
|
|
821
866
|
data: D;
|
|
@@ -979,6 +1024,461 @@ type ErrorResponse = {
|
|
|
979
1024
|
*/
|
|
980
1025
|
declare function isRouteErrorResponse(error: any): error is ErrorResponse;
|
|
981
1026
|
//#endregion
|
|
1027
|
+
//#region lib/components.d.ts
|
|
1028
|
+
/**
|
|
1029
|
+
* Function signature for client side error handling for loader/actions errors
|
|
1030
|
+
* and rendering errors via `componentDidCatch`
|
|
1031
|
+
*/
|
|
1032
|
+
interface ClientOnErrorFunction {
|
|
1033
|
+
(error: unknown, info: {
|
|
1034
|
+
location: Location$1;
|
|
1035
|
+
params: Params;
|
|
1036
|
+
pattern: string;
|
|
1037
|
+
errorInfo?: React.ErrorInfo;
|
|
1038
|
+
}): void;
|
|
1039
|
+
}
|
|
1040
|
+
interface AwaitResolveRenderFunction<Resolve = any> {
|
|
1041
|
+
(data: Awaited<Resolve>): React.ReactNode;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* @category Types
|
|
1045
|
+
*/
|
|
1046
|
+
interface AwaitProps<Resolve> {
|
|
1047
|
+
/**
|
|
1048
|
+
* When using a function, the resolved value is provided as the parameter.
|
|
1049
|
+
*
|
|
1050
|
+
* ```tsx [2]
|
|
1051
|
+
* <Await resolve={reviewsPromise}>
|
|
1052
|
+
* {(resolvedReviews) => <Reviews items={resolvedReviews} />}
|
|
1053
|
+
* </Await>
|
|
1054
|
+
* ```
|
|
1055
|
+
*
|
|
1056
|
+
* When using React elements, {@link useAsyncValue} will provide the
|
|
1057
|
+
* resolved value:
|
|
1058
|
+
*
|
|
1059
|
+
* ```tsx [2]
|
|
1060
|
+
* <Await resolve={reviewsPromise}>
|
|
1061
|
+
* <Reviews />
|
|
1062
|
+
* </Await>
|
|
1063
|
+
*
|
|
1064
|
+
* function Reviews() {
|
|
1065
|
+
* const resolvedReviews = useAsyncValue();
|
|
1066
|
+
* return <div>...</div>;
|
|
1067
|
+
* }
|
|
1068
|
+
* ```
|
|
1069
|
+
*/
|
|
1070
|
+
children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
|
|
1071
|
+
/**
|
|
1072
|
+
* The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
1073
|
+
* rejects.
|
|
1074
|
+
*
|
|
1075
|
+
* ```tsx
|
|
1076
|
+
* <Await
|
|
1077
|
+
* errorElement={<div>Oops</div>}
|
|
1078
|
+
* resolve={reviewsPromise}
|
|
1079
|
+
* >
|
|
1080
|
+
* <Reviews />
|
|
1081
|
+
* </Await>
|
|
1082
|
+
* ```
|
|
1083
|
+
*
|
|
1084
|
+
* To provide a more contextual error, you can use the {@link useAsyncError} in a
|
|
1085
|
+
* child component
|
|
1086
|
+
*
|
|
1087
|
+
* ```tsx
|
|
1088
|
+
* <Await
|
|
1089
|
+
* errorElement={<ReviewsError />}
|
|
1090
|
+
* resolve={reviewsPromise}
|
|
1091
|
+
* >
|
|
1092
|
+
* <Reviews />
|
|
1093
|
+
* </Await>
|
|
1094
|
+
*
|
|
1095
|
+
* function ReviewsError() {
|
|
1096
|
+
* const error = useAsyncError();
|
|
1097
|
+
* return <div>Error loading reviews: {error.message}</div>;
|
|
1098
|
+
* }
|
|
1099
|
+
* ```
|
|
1100
|
+
*
|
|
1101
|
+
* If you do not provide an `errorElement`, the rejected value will bubble up
|
|
1102
|
+
* to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
|
|
1103
|
+
* and be accessible via the {@link useRouteError} hook.
|
|
1104
|
+
*/
|
|
1105
|
+
errorElement?: React.ReactNode;
|
|
1106
|
+
/**
|
|
1107
|
+
* Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
1108
|
+
* returned from a [`loader`](../../start/framework/route-module#loader) to be
|
|
1109
|
+
* resolved and rendered.
|
|
1110
|
+
*
|
|
1111
|
+
* ```tsx
|
|
1112
|
+
* import { Await, useLoaderData } from "react-router";
|
|
1113
|
+
*
|
|
1114
|
+
* export async function loader() {
|
|
1115
|
+
* let reviews = getReviews(); // not awaited
|
|
1116
|
+
* let book = await getBook();
|
|
1117
|
+
* return {
|
|
1118
|
+
* book,
|
|
1119
|
+
* reviews, // this is a promise
|
|
1120
|
+
* };
|
|
1121
|
+
* }
|
|
1122
|
+
*
|
|
1123
|
+
* export default function Book() {
|
|
1124
|
+
* const {
|
|
1125
|
+
* book,
|
|
1126
|
+
* reviews, // this is the same promise
|
|
1127
|
+
* } = useLoaderData();
|
|
1128
|
+
*
|
|
1129
|
+
* return (
|
|
1130
|
+
* <div>
|
|
1131
|
+
* <h1>{book.title}</h1>
|
|
1132
|
+
* <p>{book.description}</p>
|
|
1133
|
+
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
1134
|
+
* <Await
|
|
1135
|
+
* // and is the promise we pass to Await
|
|
1136
|
+
* resolve={reviews}
|
|
1137
|
+
* >
|
|
1138
|
+
* <Reviews />
|
|
1139
|
+
* </Await>
|
|
1140
|
+
* </React.Suspense>
|
|
1141
|
+
* </div>
|
|
1142
|
+
* );
|
|
1143
|
+
* }
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
resolve: Resolve;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Used to render promise values with automatic error handling.
|
|
1150
|
+
*
|
|
1151
|
+
* **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
|
|
1152
|
+
*
|
|
1153
|
+
* @example
|
|
1154
|
+
* import { Await, useLoaderData } from "react-router";
|
|
1155
|
+
*
|
|
1156
|
+
* export async function loader() {
|
|
1157
|
+
* // not awaited
|
|
1158
|
+
* const reviews = getReviews();
|
|
1159
|
+
* // awaited (blocks the transition)
|
|
1160
|
+
* const book = await fetch("/api/book").then((res) => res.json());
|
|
1161
|
+
* return { book, reviews };
|
|
1162
|
+
* }
|
|
1163
|
+
*
|
|
1164
|
+
* function Book() {
|
|
1165
|
+
* const { book, reviews } = useLoaderData();
|
|
1166
|
+
* return (
|
|
1167
|
+
* <div>
|
|
1168
|
+
* <h1>{book.title}</h1>
|
|
1169
|
+
* <p>{book.description}</p>
|
|
1170
|
+
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
1171
|
+
* <Await
|
|
1172
|
+
* resolve={reviews}
|
|
1173
|
+
* errorElement={
|
|
1174
|
+
* <div>Could not load reviews 😬</div>
|
|
1175
|
+
* }
|
|
1176
|
+
* children={(resolvedReviews) => (
|
|
1177
|
+
* <Reviews items={resolvedReviews} />
|
|
1178
|
+
* )}
|
|
1179
|
+
* />
|
|
1180
|
+
* </React.Suspense>
|
|
1181
|
+
* </div>
|
|
1182
|
+
* );
|
|
1183
|
+
* }
|
|
1184
|
+
*
|
|
1185
|
+
* @public
|
|
1186
|
+
* @category Components
|
|
1187
|
+
* @mode framework
|
|
1188
|
+
* @mode data
|
|
1189
|
+
* @param props Props
|
|
1190
|
+
* @param {AwaitProps.children} props.children n/a
|
|
1191
|
+
* @param {AwaitProps.errorElement} props.errorElement n/a
|
|
1192
|
+
* @param {AwaitProps.resolve} props.resolve n/a
|
|
1193
|
+
* @returns React element for the rendered awaited value
|
|
1194
|
+
*/
|
|
1195
|
+
declare function Await$1<Resolve>({
|
|
1196
|
+
children,
|
|
1197
|
+
errorElement,
|
|
1198
|
+
resolve
|
|
1199
|
+
}: AwaitProps<Resolve>): React.JSX.Element;
|
|
1200
|
+
//#endregion
|
|
1201
|
+
//#region lib/server-runtime/serverHandoff.d.ts
|
|
1202
|
+
type ServerHandoff = {
|
|
1203
|
+
criticalCss?: CriticalCss;
|
|
1204
|
+
basename: string | undefined;
|
|
1205
|
+
future: FutureConfig$1;
|
|
1206
|
+
ssr: boolean;
|
|
1207
|
+
isSpaMode: boolean;
|
|
1208
|
+
unstable_apiOnly?: boolean;
|
|
1209
|
+
unstable_apiServerOrigin?: string;
|
|
1210
|
+
routeDiscovery: ServerBuild["routeDiscovery"];
|
|
1211
|
+
};
|
|
1212
|
+
//#endregion
|
|
1213
|
+
//#region lib/dom/global.d.ts
|
|
1214
|
+
type WindowReactRouterContext = ServerHandoff & {
|
|
1215
|
+
state: HydrationState;
|
|
1216
|
+
stream: ReadableStream<Uint8Array> | undefined;
|
|
1217
|
+
streamController: ReadableStreamDefaultController<Uint8Array>;
|
|
1218
|
+
};
|
|
1219
|
+
interface ViewTransition {
|
|
1220
|
+
finished: Promise<void>;
|
|
1221
|
+
ready: Promise<void>;
|
|
1222
|
+
updateCallbackDone: Promise<void>;
|
|
1223
|
+
skipTransition(): void;
|
|
1224
|
+
}
|
|
1225
|
+
declare global {
|
|
1226
|
+
var __staticRouterHydrationData: HydrationState | undefined;
|
|
1227
|
+
var __reactRouterVersion: string;
|
|
1228
|
+
interface Document {
|
|
1229
|
+
startViewTransition(cb: () => Promise<void> | void): ViewTransition;
|
|
1230
|
+
}
|
|
1231
|
+
var __reactRouterContext: WindowReactRouterContext | undefined;
|
|
1232
|
+
var __reactRouterManifest: AssetsManifest | undefined;
|
|
1233
|
+
var __reactRouterRouteModules: RouteModules | undefined;
|
|
1234
|
+
var __reactRouterDataRouter: Router$1 | undefined;
|
|
1235
|
+
var __reactRouterHdrActive: boolean;
|
|
1236
|
+
var $RefreshRuntime$: {
|
|
1237
|
+
performReactRefresh: () => void;
|
|
1238
|
+
} | undefined;
|
|
1239
|
+
}
|
|
1240
|
+
//#endregion
|
|
1241
|
+
//#region lib/dom/ssr/single-fetch.d.ts
|
|
1242
|
+
/**
|
|
1243
|
+
* Describes the operation that initiated an internal router request.
|
|
1244
|
+
*
|
|
1245
|
+
* Requests that reload fetchers as part of a navigation, revalidation, or
|
|
1246
|
+
* initialization redirect keep that initiating `type`. `fetcherKey` identifies
|
|
1247
|
+
* the fetcher being loaded, or is `null` when the request targets route loaders
|
|
1248
|
+
* or actions.
|
|
1249
|
+
*
|
|
1250
|
+
* `navigationType` is the history action (`"PUSH"`, `"REPLACE"`, or `"POP"`)
|
|
1251
|
+
* for navigation-initiated data requests, including reloaded fetchers. It is
|
|
1252
|
+
* `null` for initialization, fetcher, and revalidation requests. Manifest
|
|
1253
|
+
* requests have no navigation type.
|
|
1254
|
+
*/
|
|
1255
|
+
type RouterFetchContext = {
|
|
1256
|
+
type: "manifest";
|
|
1257
|
+
} | {
|
|
1258
|
+
type: "navigation";
|
|
1259
|
+
fetcherKey: string | null;
|
|
1260
|
+
navigationType: Action;
|
|
1261
|
+
} | {
|
|
1262
|
+
type: "initialization" | "fetcher" | "revalidation";
|
|
1263
|
+
fetcherKey: string | null;
|
|
1264
|
+
navigationType: null;
|
|
1265
|
+
};
|
|
1266
|
+
type RouterFetch = (request: Request, context: RouterFetchContext) => Promise<Response>;
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region lib/dom/ssr/route-discovery.d.ts
|
|
1269
|
+
/** A discovery response from a different build. */
|
|
1270
|
+
type ManifestMismatchEvent = {
|
|
1271
|
+
source: "eager" | "navigation" | "fetcher" | "imperative";
|
|
1272
|
+
version: string;
|
|
1273
|
+
reloadUrl: string | null;
|
|
1274
|
+
loadAllRoutes(): Promise<void>;
|
|
1275
|
+
stopPropagation(): void; /** Run built-in recovery for this source, at most once per mismatch event. */
|
|
1276
|
+
defaultBehavior(): Promise<void>;
|
|
1277
|
+
};
|
|
1278
|
+
/** The result of imperative route discovery. */
|
|
1279
|
+
type DiscoveryResult = {
|
|
1280
|
+
type: "success";
|
|
1281
|
+
} | {
|
|
1282
|
+
type: "version-mismatch";
|
|
1283
|
+
} | {
|
|
1284
|
+
type: "aborted";
|
|
1285
|
+
};
|
|
1286
|
+
/** Options for {@link unstable_useRouteDiscovery}. */
|
|
1287
|
+
type RouteDiscoveryOptions = {
|
|
1288
|
+
onManifestMismatch?: (event: ManifestMismatchEvent) => void | Promise<void>;
|
|
1289
|
+
};
|
|
1290
|
+
type Registration = {
|
|
1291
|
+
current: RouteDiscoveryOptions;
|
|
1292
|
+
};
|
|
1293
|
+
type DiscoveryState = "partial" | "loading" | "complete";
|
|
1294
|
+
type RouteDiscoverySsrInfo = {
|
|
1295
|
+
manifest: AssetsManifest;
|
|
1296
|
+
routeModules: RouteModules;
|
|
1297
|
+
router: Router$1 | undefined;
|
|
1298
|
+
context: Pick<WindowReactRouterContext, "ssr" | "routeDiscovery" | "isSpaMode" | "basename" | "unstable_apiServerOrigin" | "unstable_apiOnly">;
|
|
1299
|
+
};
|
|
1300
|
+
declare class RouteDiscoveryRuntime {
|
|
1301
|
+
private ssrInfo;
|
|
1302
|
+
readonly enabled: boolean;
|
|
1303
|
+
readonly discoveredPaths: Set<string>;
|
|
1304
|
+
readonly nextPaths: Set<string>;
|
|
1305
|
+
state: DiscoveryState;
|
|
1306
|
+
ready: boolean;
|
|
1307
|
+
private registrations;
|
|
1308
|
+
private listeners;
|
|
1309
|
+
private fullLoadErrorListeners;
|
|
1310
|
+
private fullLoad?;
|
|
1311
|
+
private loadedManifest?;
|
|
1312
|
+
private mismatch?;
|
|
1313
|
+
private fetchImplementation;
|
|
1314
|
+
private loadManifest;
|
|
1315
|
+
onError?: ClientOnErrorFunction;
|
|
1316
|
+
constructor(ssrInfo: RouteDiscoverySsrInfo, {
|
|
1317
|
+
fetch: fetchImplementation,
|
|
1318
|
+
loadManifest
|
|
1319
|
+
}?: {
|
|
1320
|
+
fetch?: RouterFetch;
|
|
1321
|
+
loadManifest?: () => Promise<AssetsManifest>;
|
|
1322
|
+
});
|
|
1323
|
+
private get router();
|
|
1324
|
+
private loadManifestAsset;
|
|
1325
|
+
subscribe: (listener: () => void) => () => void;
|
|
1326
|
+
private update;
|
|
1327
|
+
markReady: () => void;
|
|
1328
|
+
register(registration: Registration): () => void;
|
|
1329
|
+
private isComplete;
|
|
1330
|
+
loadAllRoutes: () => Promise<void>;
|
|
1331
|
+
reportError(error: unknown): void;
|
|
1332
|
+
private dispatchMismatch;
|
|
1333
|
+
private requestUrl;
|
|
1334
|
+
discoverRoutes: (paths: string[], options?: {
|
|
1335
|
+
signal?: AbortSignal;
|
|
1336
|
+
}) => Promise<DiscoveryResult>;
|
|
1337
|
+
discover(paths: string[], source: ManifestMismatchEvent["source"], reloadUrl: string | null, signal?: AbortSignal, patch?: (routeId: string | null, children: RouteObject[], unstable_allowElementMutations?: boolean) => void): Promise<DiscoveryResult>;
|
|
1338
|
+
}
|
|
1339
|
+
//#endregion
|
|
1340
|
+
//#region lib/dom/ssr/entry.d.ts
|
|
1341
|
+
type SerializedError = {
|
|
1342
|
+
message: string;
|
|
1343
|
+
stack?: string;
|
|
1344
|
+
};
|
|
1345
|
+
interface FrameworkContextObject {
|
|
1346
|
+
routeDiscoveryRuntime?: RouteDiscoveryRuntime;
|
|
1347
|
+
routeDiscoveryState?: DiscoveryState;
|
|
1348
|
+
manifest: AssetsManifest;
|
|
1349
|
+
routeModules: RouteModules;
|
|
1350
|
+
criticalCss?: CriticalCss;
|
|
1351
|
+
serverHandoffString?: string;
|
|
1352
|
+
future: FutureConfig$1;
|
|
1353
|
+
ssr: boolean;
|
|
1354
|
+
isSpaMode: boolean;
|
|
1355
|
+
unstable_apiOnly?: boolean;
|
|
1356
|
+
unstable_apiServerOrigin?: string;
|
|
1357
|
+
routeDiscovery: ServerBuild["routeDiscovery"];
|
|
1358
|
+
nonce?: string;
|
|
1359
|
+
serializeError?(error: Error): SerializedError;
|
|
1360
|
+
renderMeta?: {
|
|
1361
|
+
didRenderScripts?: boolean;
|
|
1362
|
+
streamCache?: Record<number, Promise<void> & {
|
|
1363
|
+
result?: {
|
|
1364
|
+
done: boolean;
|
|
1365
|
+
value: string;
|
|
1366
|
+
};
|
|
1367
|
+
error?: unknown;
|
|
1368
|
+
}>;
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
interface EntryContext extends FrameworkContextObject {
|
|
1372
|
+
/**
|
|
1373
|
+
* @deprecated This property was an internal implementation detail and was
|
|
1374
|
+
* never intended for use in `entry.server.tsx`. It is always an empty array.
|
|
1375
|
+
*/
|
|
1376
|
+
branches: RouteBranch<DataRouteObject>[];
|
|
1377
|
+
staticHandlerContext: StaticHandlerContext;
|
|
1378
|
+
serverHandoffStream?: ReadableStream<Uint8Array>;
|
|
1379
|
+
}
|
|
1380
|
+
interface FutureConfig$1 {
|
|
1381
|
+
unstable_customRouteDiscovery?: boolean;
|
|
1382
|
+
}
|
|
1383
|
+
type CriticalCss = string | {
|
|
1384
|
+
rel: "stylesheet";
|
|
1385
|
+
href: string;
|
|
1386
|
+
};
|
|
1387
|
+
interface AssetsManifest {
|
|
1388
|
+
entry: {
|
|
1389
|
+
imports: string[];
|
|
1390
|
+
module: string;
|
|
1391
|
+
};
|
|
1392
|
+
routes: RouteManifest<EntryRoute>;
|
|
1393
|
+
url: string;
|
|
1394
|
+
version: string;
|
|
1395
|
+
hmr?: {
|
|
1396
|
+
timestamp?: number;
|
|
1397
|
+
runtime: string;
|
|
1398
|
+
};
|
|
1399
|
+
sri?: Record<string, string> | true;
|
|
1400
|
+
}
|
|
1401
|
+
//#endregion
|
|
1402
|
+
//#region lib/server-runtime/routes.d.ts
|
|
1403
|
+
type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
|
|
1404
|
+
interface ServerRoute extends Route$1 {
|
|
1405
|
+
children: ServerRoute[];
|
|
1406
|
+
module: ServerRouteModule;
|
|
1407
|
+
}
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region lib/server-runtime/build.d.ts
|
|
1410
|
+
type OptionalCriticalCss = CriticalCss | undefined;
|
|
1411
|
+
/**
|
|
1412
|
+
* The output of the compiler for the server build.
|
|
1413
|
+
*/
|
|
1414
|
+
interface ServerBuild {
|
|
1415
|
+
entry: {
|
|
1416
|
+
module: ServerEntryModule;
|
|
1417
|
+
};
|
|
1418
|
+
routes: ServerRouteManifest;
|
|
1419
|
+
assets: AssetsManifest;
|
|
1420
|
+
basename?: string;
|
|
1421
|
+
publicPath: string;
|
|
1422
|
+
assetsBuildDirectory: string;
|
|
1423
|
+
future: FutureConfig$1;
|
|
1424
|
+
/**
|
|
1425
|
+
* Whether runtime server requests are supported, including API-only builds.
|
|
1426
|
+
*/
|
|
1427
|
+
ssr: boolean;
|
|
1428
|
+
/**
|
|
1429
|
+
* The origin to use for server requests in API-only mode.
|
|
1430
|
+
* @internal
|
|
1431
|
+
*/
|
|
1432
|
+
unstable_apiServerOrigin?: string;
|
|
1433
|
+
/**
|
|
1434
|
+
* Whether production document rendering is disabled while data and route
|
|
1435
|
+
* discovery requests remain supported.
|
|
1436
|
+
* @internal
|
|
1437
|
+
*/
|
|
1438
|
+
unstable_apiOnly?: boolean;
|
|
1439
|
+
unstable_getCriticalCss?: (args: {
|
|
1440
|
+
pathname: string;
|
|
1441
|
+
}) => OptionalCriticalCss | Promise<OptionalCriticalCss>;
|
|
1442
|
+
/**
|
|
1443
|
+
* @deprecated This is now done via a custom header during prerendering
|
|
1444
|
+
*/
|
|
1445
|
+
isSpaMode: boolean;
|
|
1446
|
+
prerender: string[];
|
|
1447
|
+
routeDiscovery: {
|
|
1448
|
+
mode: "lazy" | "initial";
|
|
1449
|
+
manifestPath: string;
|
|
1450
|
+
};
|
|
1451
|
+
allowedActionOrigins?: string[] | false;
|
|
1452
|
+
}
|
|
1453
|
+
interface HandleDocumentRequestFunction {
|
|
1454
|
+
(request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: RouterContextProvider): Promise<Response> | Response;
|
|
1455
|
+
}
|
|
1456
|
+
interface HandleDataRequestFunction {
|
|
1457
|
+
(response: Response, args: {
|
|
1458
|
+
request: LoaderFunctionArgs["request"] | ActionFunctionArgs["request"];
|
|
1459
|
+
context: LoaderFunctionArgs["context"] | ActionFunctionArgs["context"];
|
|
1460
|
+
params: LoaderFunctionArgs["params"] | ActionFunctionArgs["params"];
|
|
1461
|
+
}): Promise<Response> | Response;
|
|
1462
|
+
}
|
|
1463
|
+
interface HandleErrorFunction {
|
|
1464
|
+
(error: unknown, args: {
|
|
1465
|
+
request: LoaderFunctionArgs["request"] | ActionFunctionArgs["request"];
|
|
1466
|
+
context: LoaderFunctionArgs["context"] | ActionFunctionArgs["context"];
|
|
1467
|
+
params: LoaderFunctionArgs["params"] | ActionFunctionArgs["params"];
|
|
1468
|
+
}): void;
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* A module that serves as the entry point for a Remix app during server
|
|
1472
|
+
* rendering.
|
|
1473
|
+
*/
|
|
1474
|
+
interface ServerEntryModule {
|
|
1475
|
+
default: HandleDocumentRequestFunction;
|
|
1476
|
+
handleDataRequest?: HandleDataRequestFunction;
|
|
1477
|
+
handleError?: HandleErrorFunction;
|
|
1478
|
+
instrumentations?: ServerInstrumentation[];
|
|
1479
|
+
streamTimeout?: number;
|
|
1480
|
+
}
|
|
1481
|
+
//#endregion
|
|
982
1482
|
//#region lib/router/instrumentation.d.ts
|
|
983
1483
|
type ServerInstrumentation = {
|
|
984
1484
|
handler?: InstrumentRequestHandlerFunction;
|
|
@@ -1390,6 +1890,8 @@ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "e
|
|
|
1390
1890
|
* Future flags to toggle new feature behavior
|
|
1391
1891
|
*/
|
|
1392
1892
|
interface FutureConfig {
|
|
1893
|
+
/** @internal Enables application-controlled Framework route discovery. */
|
|
1894
|
+
unstable_customRouteDiscovery?: boolean;
|
|
1393
1895
|
/** Enables route-pattern matching after calling `unstable_preloadRoutePattern()`. */
|
|
1394
1896
|
unstable_routePatternMatching?: boolean;
|
|
1395
1897
|
}
|
|
@@ -1536,6 +2038,10 @@ type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
|
|
|
1536
2038
|
replace?: boolean;
|
|
1537
2039
|
state?: any;
|
|
1538
2040
|
fromRouteId?: string;
|
|
2041
|
+
/**
|
|
2042
|
+
* @deprecated Use React's `<ViewTransition>` component instead. See the
|
|
2043
|
+
* [migration guide](https://reactrouter.com/how-to/view-transitions).
|
|
2044
|
+
*/
|
|
1539
2045
|
viewTransition?: boolean;
|
|
1540
2046
|
mask?: To;
|
|
1541
2047
|
};
|
|
@@ -1751,6 +2257,31 @@ interface CreateStaticHandlerOptions {
|
|
|
1751
2257
|
*/
|
|
1752
2258
|
declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
|
|
1753
2259
|
//#endregion
|
|
2260
|
+
//#region lib/dom/ssr/routes.d.ts
|
|
2261
|
+
interface Route$1 {
|
|
2262
|
+
index?: boolean;
|
|
2263
|
+
caseSensitive?: boolean;
|
|
2264
|
+
id: string;
|
|
2265
|
+
parentId?: string;
|
|
2266
|
+
path?: string;
|
|
2267
|
+
}
|
|
2268
|
+
interface EntryRoute extends Route$1 {
|
|
2269
|
+
hasAction: boolean;
|
|
2270
|
+
hasLoader: boolean;
|
|
2271
|
+
hasClientAction: boolean;
|
|
2272
|
+
hasClientLoader: boolean;
|
|
2273
|
+
hasClientMiddleware: boolean;
|
|
2274
|
+
hasErrorBoundary: boolean;
|
|
2275
|
+
imports?: string[];
|
|
2276
|
+
css?: string[];
|
|
2277
|
+
module: string;
|
|
2278
|
+
clientActionModule: string | undefined;
|
|
2279
|
+
clientLoaderModule: string | undefined;
|
|
2280
|
+
clientMiddlewareModule: string | undefined;
|
|
2281
|
+
hydrateFallbackModule: string | undefined;
|
|
2282
|
+
parentId?: string;
|
|
2283
|
+
}
|
|
2284
|
+
//#endregion
|
|
1754
2285
|
//#region lib/router/links.d.ts
|
|
1755
2286
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
1756
2287
|
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
@@ -1938,6 +2469,36 @@ type ClientDataFunctionArgs<Params> = {
|
|
|
1938
2469
|
type SerializeFrom<T> = T extends ((...args: infer Args) => unknown) ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
|
|
1939
2470
|
//#endregion
|
|
1940
2471
|
//#region lib/dom/ssr/routeModules.d.ts
|
|
2472
|
+
interface RouteModules {
|
|
2473
|
+
[routeId: string]: RouteModule | undefined;
|
|
2474
|
+
}
|
|
2475
|
+
/**
|
|
2476
|
+
* The shape of a route module shipped to the client
|
|
2477
|
+
*/
|
|
2478
|
+
interface RouteModule {
|
|
2479
|
+
clientAction?: ClientActionFunction;
|
|
2480
|
+
clientLoader?: ClientLoaderFunction;
|
|
2481
|
+
clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
|
|
2482
|
+
ErrorBoundary?: ErrorBoundaryComponent;
|
|
2483
|
+
HydrateFallback?: HydrateFallbackComponent;
|
|
2484
|
+
Layout?: LayoutComponent;
|
|
2485
|
+
default: RouteComponent;
|
|
2486
|
+
handle?: RouteHandle;
|
|
2487
|
+
links?: LinksFunction;
|
|
2488
|
+
meta?: MetaFunction;
|
|
2489
|
+
shouldRevalidate?: ShouldRevalidateFunction;
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* The shape of a route module on the server
|
|
2493
|
+
*/
|
|
2494
|
+
interface ServerRouteModule extends RouteModule {
|
|
2495
|
+
action?: ActionFunction;
|
|
2496
|
+
headers?: HeadersFunction | {
|
|
2497
|
+
[name: string]: string;
|
|
2498
|
+
};
|
|
2499
|
+
loader?: LoaderFunction;
|
|
2500
|
+
middleware?: MiddlewareFunction<Response>[];
|
|
2501
|
+
}
|
|
1941
2502
|
/**
|
|
1942
2503
|
* A function that handles data mutations for a route on the client
|
|
1943
2504
|
*/
|
|
@@ -1960,6 +2521,10 @@ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<Load
|
|
|
1960
2521
|
type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
|
|
1961
2522
|
serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
|
|
1962
2523
|
};
|
|
2524
|
+
/**
|
|
2525
|
+
* ErrorBoundary to display for this route
|
|
2526
|
+
*/
|
|
2527
|
+
type ErrorBoundaryComponent = ComponentType;
|
|
1963
2528
|
type HeadersArgs = {
|
|
1964
2529
|
loaderHeaders: Headers;
|
|
1965
2530
|
parentHeaders: Headers;
|
|
@@ -1973,6 +2538,19 @@ type HeadersArgs = {
|
|
|
1973
2538
|
interface HeadersFunction {
|
|
1974
2539
|
(args: HeadersArgs): Headers | HeadersInit;
|
|
1975
2540
|
}
|
|
2541
|
+
/**
|
|
2542
|
+
* `<Route HydrateFallback>` component to render on initial loads
|
|
2543
|
+
* when client loaders are present
|
|
2544
|
+
*/
|
|
2545
|
+
type HydrateFallbackComponent = ComponentType;
|
|
2546
|
+
/**
|
|
2547
|
+
* Optional, root-only `<Route Layout>` component to wrap the root content in.
|
|
2548
|
+
* Useful for defining the <html>/<head>/<body> document shell shared by the
|
|
2549
|
+
* Component, HydrateFallback, and ErrorBoundary
|
|
2550
|
+
*/
|
|
2551
|
+
type LayoutComponent = ComponentType<{
|
|
2552
|
+
children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
|
|
2553
|
+
}>;
|
|
1976
2554
|
/**
|
|
1977
2555
|
* A function that defines `<link>` tags to be inserted into the `<head>` of
|
|
1978
2556
|
* the document on route transitions.
|
|
@@ -2080,6 +2658,7 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
|
2080
2658
|
/**
|
|
2081
2659
|
* A React component that is rendered for a route.
|
|
2082
2660
|
*/
|
|
2661
|
+
type RouteComponent = ComponentType<{}>;
|
|
2083
2662
|
/**
|
|
2084
2663
|
* An arbitrary object that is associated with a route.
|
|
2085
2664
|
*
|
|
@@ -2087,168 +2666,6 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
|
2087
2666
|
*/
|
|
2088
2667
|
type RouteHandle = unknown;
|
|
2089
2668
|
//#endregion
|
|
2090
|
-
//#region lib/components.d.ts
|
|
2091
|
-
interface AwaitResolveRenderFunction<Resolve = any> {
|
|
2092
|
-
(data: Awaited<Resolve>): React.ReactNode;
|
|
2093
|
-
}
|
|
2094
|
-
/**
|
|
2095
|
-
* @category Types
|
|
2096
|
-
*/
|
|
2097
|
-
interface AwaitProps<Resolve> {
|
|
2098
|
-
/**
|
|
2099
|
-
* When using a function, the resolved value is provided as the parameter.
|
|
2100
|
-
*
|
|
2101
|
-
* ```tsx [2]
|
|
2102
|
-
* <Await resolve={reviewsPromise}>
|
|
2103
|
-
* {(resolvedReviews) => <Reviews items={resolvedReviews} />}
|
|
2104
|
-
* </Await>
|
|
2105
|
-
* ```
|
|
2106
|
-
*
|
|
2107
|
-
* When using React elements, {@link useAsyncValue} will provide the
|
|
2108
|
-
* resolved value:
|
|
2109
|
-
*
|
|
2110
|
-
* ```tsx [2]
|
|
2111
|
-
* <Await resolve={reviewsPromise}>
|
|
2112
|
-
* <Reviews />
|
|
2113
|
-
* </Await>
|
|
2114
|
-
*
|
|
2115
|
-
* function Reviews() {
|
|
2116
|
-
* const resolvedReviews = useAsyncValue();
|
|
2117
|
-
* return <div>...</div>;
|
|
2118
|
-
* }
|
|
2119
|
-
* ```
|
|
2120
|
-
*/
|
|
2121
|
-
children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
|
|
2122
|
-
/**
|
|
2123
|
-
* The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
2124
|
-
* rejects.
|
|
2125
|
-
*
|
|
2126
|
-
* ```tsx
|
|
2127
|
-
* <Await
|
|
2128
|
-
* errorElement={<div>Oops</div>}
|
|
2129
|
-
* resolve={reviewsPromise}
|
|
2130
|
-
* >
|
|
2131
|
-
* <Reviews />
|
|
2132
|
-
* </Await>
|
|
2133
|
-
* ```
|
|
2134
|
-
*
|
|
2135
|
-
* To provide a more contextual error, you can use the {@link useAsyncError} in a
|
|
2136
|
-
* child component
|
|
2137
|
-
*
|
|
2138
|
-
* ```tsx
|
|
2139
|
-
* <Await
|
|
2140
|
-
* errorElement={<ReviewsError />}
|
|
2141
|
-
* resolve={reviewsPromise}
|
|
2142
|
-
* >
|
|
2143
|
-
* <Reviews />
|
|
2144
|
-
* </Await>
|
|
2145
|
-
*
|
|
2146
|
-
* function ReviewsError() {
|
|
2147
|
-
* const error = useAsyncError();
|
|
2148
|
-
* return <div>Error loading reviews: {error.message}</div>;
|
|
2149
|
-
* }
|
|
2150
|
-
* ```
|
|
2151
|
-
*
|
|
2152
|
-
* If you do not provide an `errorElement`, the rejected value will bubble up
|
|
2153
|
-
* to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
|
|
2154
|
-
* and be accessible via the {@link useRouteError} hook.
|
|
2155
|
-
*/
|
|
2156
|
-
errorElement?: React.ReactNode;
|
|
2157
|
-
/**
|
|
2158
|
-
* Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
2159
|
-
* returned from a [`loader`](../../start/framework/route-module#loader) to be
|
|
2160
|
-
* resolved and rendered.
|
|
2161
|
-
*
|
|
2162
|
-
* ```tsx
|
|
2163
|
-
* import { Await, useLoaderData } from "react-router";
|
|
2164
|
-
*
|
|
2165
|
-
* export async function loader() {
|
|
2166
|
-
* let reviews = getReviews(); // not awaited
|
|
2167
|
-
* let book = await getBook();
|
|
2168
|
-
* return {
|
|
2169
|
-
* book,
|
|
2170
|
-
* reviews, // this is a promise
|
|
2171
|
-
* };
|
|
2172
|
-
* }
|
|
2173
|
-
*
|
|
2174
|
-
* export default function Book() {
|
|
2175
|
-
* const {
|
|
2176
|
-
* book,
|
|
2177
|
-
* reviews, // this is the same promise
|
|
2178
|
-
* } = useLoaderData();
|
|
2179
|
-
*
|
|
2180
|
-
* return (
|
|
2181
|
-
* <div>
|
|
2182
|
-
* <h1>{book.title}</h1>
|
|
2183
|
-
* <p>{book.description}</p>
|
|
2184
|
-
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
2185
|
-
* <Await
|
|
2186
|
-
* // and is the promise we pass to Await
|
|
2187
|
-
* resolve={reviews}
|
|
2188
|
-
* >
|
|
2189
|
-
* <Reviews />
|
|
2190
|
-
* </Await>
|
|
2191
|
-
* </React.Suspense>
|
|
2192
|
-
* </div>
|
|
2193
|
-
* );
|
|
2194
|
-
* }
|
|
2195
|
-
* ```
|
|
2196
|
-
*/
|
|
2197
|
-
resolve: Resolve;
|
|
2198
|
-
}
|
|
2199
|
-
/**
|
|
2200
|
-
* Used to render promise values with automatic error handling.
|
|
2201
|
-
*
|
|
2202
|
-
* **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
|
|
2203
|
-
*
|
|
2204
|
-
* @example
|
|
2205
|
-
* import { Await, useLoaderData } from "react-router";
|
|
2206
|
-
*
|
|
2207
|
-
* export async function loader() {
|
|
2208
|
-
* // not awaited
|
|
2209
|
-
* const reviews = getReviews();
|
|
2210
|
-
* // awaited (blocks the transition)
|
|
2211
|
-
* const book = await fetch("/api/book").then((res) => res.json());
|
|
2212
|
-
* return { book, reviews };
|
|
2213
|
-
* }
|
|
2214
|
-
*
|
|
2215
|
-
* function Book() {
|
|
2216
|
-
* const { book, reviews } = useLoaderData();
|
|
2217
|
-
* return (
|
|
2218
|
-
* <div>
|
|
2219
|
-
* <h1>{book.title}</h1>
|
|
2220
|
-
* <p>{book.description}</p>
|
|
2221
|
-
* <React.Suspense fallback={<ReviewsSkeleton />}>
|
|
2222
|
-
* <Await
|
|
2223
|
-
* resolve={reviews}
|
|
2224
|
-
* errorElement={
|
|
2225
|
-
* <div>Could not load reviews 😬</div>
|
|
2226
|
-
* }
|
|
2227
|
-
* children={(resolvedReviews) => (
|
|
2228
|
-
* <Reviews items={resolvedReviews} />
|
|
2229
|
-
* )}
|
|
2230
|
-
* />
|
|
2231
|
-
* </React.Suspense>
|
|
2232
|
-
* </div>
|
|
2233
|
-
* );
|
|
2234
|
-
* }
|
|
2235
|
-
*
|
|
2236
|
-
* @public
|
|
2237
|
-
* @category Components
|
|
2238
|
-
* @mode framework
|
|
2239
|
-
* @mode data
|
|
2240
|
-
* @param props Props
|
|
2241
|
-
* @param {AwaitProps.children} props.children n/a
|
|
2242
|
-
* @param {AwaitProps.errorElement} props.errorElement n/a
|
|
2243
|
-
* @param {AwaitProps.resolve} props.resolve n/a
|
|
2244
|
-
* @returns React element for the rendered awaited value
|
|
2245
|
-
*/
|
|
2246
|
-
declare function Await$1<Resolve>({
|
|
2247
|
-
children,
|
|
2248
|
-
errorElement,
|
|
2249
|
-
resolve
|
|
2250
|
-
}: AwaitProps<Resolve>): React.JSX.Element;
|
|
2251
|
-
//#endregion
|
|
2252
2669
|
//#region lib/rsc/server.rsc.d.ts
|
|
2253
2670
|
declare function getRequest(): Request;
|
|
2254
2671
|
declare const redirect: typeof redirect$1;
|
|
@@ -2267,6 +2684,7 @@ type RSCRouteConfigEntryBase = {
|
|
|
2267
2684
|
links?: LinksFunction;
|
|
2268
2685
|
loader?: LoaderFunction;
|
|
2269
2686
|
meta?: MetaFunction;
|
|
2687
|
+
middleware?: MiddlewareFunction<any>[];
|
|
2270
2688
|
shouldRevalidate?: ShouldRevalidateFunction;
|
|
2271
2689
|
};
|
|
2272
2690
|
type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
|
|
@@ -2452,7 +2870,7 @@ declare function matchRSCServerRequest({
|
|
|
2452
2870
|
onError,
|
|
2453
2871
|
request,
|
|
2454
2872
|
routes,
|
|
2455
|
-
generateResponse
|
|
2873
|
+
generateResponse: encodeResponse
|
|
2456
2874
|
}: {
|
|
2457
2875
|
allowedActionOrigins?: string[];
|
|
2458
2876
|
createTemporaryReferenceSet: () => unknown;
|