react-router 8.3.0 → 8.4.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 +46 -2
- package/dist/development/dom-export.js +1 -1
- package/dist/development/index-react-server-client.js +1 -1
- package/dist/development/index-react-server.d.ts +50 -48
- package/dist/development/index-react-server.js +96 -43
- package/dist/development/index.d.ts +2 -2
- package/dist/development/index.js +3 -3
- package/dist/development/lib/actions.js +10 -5
- package/dist/development/lib/components.js +50 -10
- package/dist/development/lib/context.d.ts +14 -5
- package/dist/development/lib/context.js +11 -3
- package/dist/development/lib/dom/dom.js +2 -2
- package/dist/development/lib/dom/lib.js +33 -36
- package/dist/development/lib/dom/server.d.ts +6 -1
- package/dist/development/lib/dom/server.js +40 -14
- package/dist/development/lib/dom/ssr/components.js +16 -24
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/entry.d.ts +4 -0
- 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.js +34 -12
- package/dist/development/lib/dom/ssr/hydration.d.ts +3 -1
- package/dist/development/lib/dom/ssr/hydration.js +6 -4
- 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 +5 -2
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
- package/dist/development/lib/dom/ssr/routes.js +1 -1
- package/dist/development/lib/dom/ssr/server.js +2 -2
- package/dist/development/lib/dom/ssr/single-fetch.js +13 -22
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.js +2 -1
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.js +54 -46
- package/dist/development/lib/href.js +1 -1
- package/dist/development/lib/router/history.js +2 -2
- package/dist/development/lib/router/instrumentation.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.d.ts +2 -0
- package/dist/development/lib/router/matcher-route-pattern.js +216 -0
- package/dist/development/lib/router/matcher-route-pattern.preload.d.ts +20 -0
- package/dist/development/lib/router/matcher-route-pattern.preload.js +36 -0
- package/dist/development/lib/router/matcher.d.ts +2 -0
- package/dist/development/lib/router/matcher.js +29 -0
- package/dist/development/lib/router/navigation.js +45 -0
- package/dist/development/lib/router/router.d.ts +21 -7
- package/dist/development/lib/router/router.js +111 -82
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +6 -1
- package/dist/development/lib/router/utils.js +15 -9
- package/dist/development/lib/rsc/browser.js +5 -1
- 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 +3 -5
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +7 -0
- package/dist/development/lib/rsc/server.ssr.js +26 -22
- package/dist/development/lib/server-runtime/cookies.js +2 -2
- package/dist/development/lib/server-runtime/crypto.js +2 -2
- package/dist/development/lib/server-runtime/data.js +1 -1
- package/dist/development/lib/server-runtime/dev.js +2 -2
- 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 +3 -4
- package/dist/development/lib/server-runtime/routes.js +1 -1
- package/dist/development/lib/server-runtime/server.js +8 -7
- 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 +2 -2
- 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/route-pattern.d.ts +3 -0
- package/dist/development/route-pattern.js +12 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +4 -4
- 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.js +1 -1
- package/dist/production/index-react-server-client.js +1 -1
- package/dist/production/index-react-server.d.ts +50 -48
- package/dist/production/index-react-server.js +96 -43
- package/dist/production/index.d.ts +2 -2
- package/dist/production/index.js +3 -3
- package/dist/production/lib/actions.js +10 -5
- package/dist/production/lib/components.js +50 -10
- package/dist/production/lib/context.d.ts +14 -5
- package/dist/production/lib/context.js +11 -3
- package/dist/production/lib/dom/dom.js +2 -2
- package/dist/production/lib/dom/lib.js +33 -36
- package/dist/production/lib/dom/server.d.ts +6 -1
- package/dist/production/lib/dom/server.js +40 -14
- package/dist/production/lib/dom/ssr/components.js +16 -24
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/entry.d.ts +4 -0
- 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.js +34 -12
- package/dist/production/lib/dom/ssr/hydration.d.ts +3 -1
- package/dist/production/lib/dom/ssr/hydration.js +6 -4
- 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 +5 -2
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
- package/dist/production/lib/dom/ssr/routes.js +1 -1
- package/dist/production/lib/dom/ssr/server.js +2 -2
- package/dist/production/lib/dom/ssr/single-fetch.js +13 -22
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.js +2 -1
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.js +54 -46
- package/dist/production/lib/href.js +1 -1
- package/dist/production/lib/router/history.js +2 -2
- package/dist/production/lib/router/instrumentation.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.d.ts +2 -0
- package/dist/production/lib/router/matcher-route-pattern.js +216 -0
- package/dist/production/lib/router/matcher-route-pattern.preload.d.ts +20 -0
- package/dist/production/lib/router/matcher-route-pattern.preload.js +36 -0
- package/dist/production/lib/router/matcher.d.ts +2 -0
- package/dist/production/lib/router/matcher.js +29 -0
- package/dist/production/lib/router/navigation.js +45 -0
- package/dist/production/lib/router/router.d.ts +21 -7
- package/dist/production/lib/router/router.js +111 -82
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +6 -1
- package/dist/production/lib/router/utils.js +15 -9
- package/dist/production/lib/rsc/browser.js +5 -1
- 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 +3 -5
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +7 -0
- package/dist/production/lib/rsc/server.ssr.js +26 -22
- package/dist/production/lib/server-runtime/cookies.js +2 -2
- package/dist/production/lib/server-runtime/crypto.js +2 -2
- package/dist/production/lib/server-runtime/data.js +1 -1
- package/dist/production/lib/server-runtime/dev.js +2 -2
- 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 +3 -4
- package/dist/production/lib/server-runtime/routes.js +1 -1
- package/dist/production/lib/server-runtime/server.js +8 -7
- 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 +2 -2
- 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/route-pattern.d.ts +3 -0
- package/dist/production/route-pattern.js +12 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +4 -4
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/how-to/fetchers.md +6 -1
- package/docs/how-to/middleware.md +3 -1
- package/docs/how-to/optimize-revalidation.md +178 -5
- package/docs/how-to/react-server-components.md +26 -3
- package/docs/how-to/resource-routes.md +3 -0
- package/docs/start/data/actions.md +2 -1
- package/docs/start/data/route-object.md +21 -6
- package/docs/start/framework/actions.md +4 -2
- package/docs/start/framework/route-module.md +32 -5
- package/docs/upgrading/future.md +68 -0
- package/package.json +11 -1
|
@@ -50,7 +50,7 @@ interface Path {
|
|
|
50
50
|
* An entry in a history stack. A location contains information about the
|
|
51
51
|
* URL path, as well as possibly some arbitrary state and a key.
|
|
52
52
|
*/
|
|
53
|
-
interface Location<State = any> extends Path {
|
|
53
|
+
interface Location$1<State = any> extends Path {
|
|
54
54
|
/**
|
|
55
55
|
* A value of arbitrary data associated with this location.
|
|
56
56
|
*/
|
|
@@ -79,7 +79,7 @@ interface Update {
|
|
|
79
79
|
/**
|
|
80
80
|
* The new location.
|
|
81
81
|
*/
|
|
82
|
-
location: Location;
|
|
82
|
+
location: Location$1;
|
|
83
83
|
/**
|
|
84
84
|
* The delta between this location and the former location in the history stack
|
|
85
85
|
*/
|
|
@@ -113,7 +113,7 @@ interface History {
|
|
|
113
113
|
/**
|
|
114
114
|
* The current location. This value is mutable.
|
|
115
115
|
*/
|
|
116
|
-
readonly location: Location;
|
|
116
|
+
readonly location: Location$1;
|
|
117
117
|
/**
|
|
118
118
|
* Returns a valid href for the given `to` value that may be used as
|
|
119
119
|
* the value of an <a href> attribute.
|
|
@@ -597,7 +597,7 @@ interface MapRoutePropertiesFunction {
|
|
|
597
597
|
* onto the route. Either they're meaningful to the router, or they'll get
|
|
598
598
|
* ignored.
|
|
599
599
|
*/
|
|
600
|
-
type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
|
|
600
|
+
type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children" | "unstable_validateParams";
|
|
601
601
|
/**
|
|
602
602
|
* Keys we cannot change from within a lazy() function. We spread all other keys
|
|
603
603
|
* onto the route. Either they're meaningful to the router, or they'll get
|
|
@@ -655,6 +655,11 @@ type BaseRouteObject = {
|
|
|
655
655
|
* See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
|
|
656
656
|
*/
|
|
657
657
|
shouldRevalidate?: ShouldRevalidateFunction;
|
|
658
|
+
/**
|
|
659
|
+
* A map of route param names to regular expressions used to validate params
|
|
660
|
+
* after a route-pattern match.
|
|
661
|
+
*/
|
|
662
|
+
unstable_validateParams?: Record<string, RegExp>;
|
|
658
663
|
/**
|
|
659
664
|
* The route handle.
|
|
660
665
|
*/
|
|
@@ -791,7 +796,7 @@ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {}
|
|
|
791
796
|
* Defaults to `/`.
|
|
792
797
|
* @returns An array of matched routes, or `null` if no matches were found.
|
|
793
798
|
*/
|
|
794
|
-
declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
|
|
799
|
+
declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location$1> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
|
|
795
800
|
interface UIMatch<Data = unknown, Handle = unknown> {
|
|
796
801
|
id: string;
|
|
797
802
|
pathname: string;
|
|
@@ -811,30 +816,6 @@ interface UIMatch<Data = unknown, Handle = unknown> {
|
|
|
811
816
|
*/
|
|
812
817
|
handle: Handle;
|
|
813
818
|
}
|
|
814
|
-
interface RouteMeta<RouteObjectType extends RouteObject = RouteObject> {
|
|
815
|
-
relativePath: string;
|
|
816
|
-
caseSensitive: boolean;
|
|
817
|
-
childrenIndex: number;
|
|
818
|
-
route: RouteObjectType;
|
|
819
|
-
matcher?: RegExp;
|
|
820
|
-
compiledParams?: CompiledPathParam[];
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* @private
|
|
824
|
-
* PRIVATE - DO NOT USE
|
|
825
|
-
*
|
|
826
|
-
* A "branch" of routes that match a given route pattern.
|
|
827
|
-
* This is an internal interface not intended for direct external usage.
|
|
828
|
-
*/
|
|
829
|
-
interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
|
|
830
|
-
path: string;
|
|
831
|
-
score: number;
|
|
832
|
-
routesMeta: RouteMeta<RouteObjectType>[];
|
|
833
|
-
}
|
|
834
|
-
type CompiledPathParam = {
|
|
835
|
-
paramName: string;
|
|
836
|
-
isOptional?: boolean;
|
|
837
|
-
};
|
|
838
819
|
declare class DataWithResponseInit<D> {
|
|
839
820
|
type: string;
|
|
840
821
|
data: D;
|
|
@@ -1143,9 +1124,10 @@ interface Router$1 {
|
|
|
1143
1124
|
* @private
|
|
1144
1125
|
* PRIVATE - DO NOT USE
|
|
1145
1126
|
*
|
|
1146
|
-
*
|
|
1127
|
+
* Match routes against a location using the router's configured route
|
|
1128
|
+
* matching implementation.
|
|
1147
1129
|
*/
|
|
1148
|
-
|
|
1130
|
+
match(locationArg: Partial<Location$1> | string): DataRouteMatch[] | null;
|
|
1149
1131
|
/**
|
|
1150
1132
|
* @private
|
|
1151
1133
|
* PRIVATE - DO NOT USE
|
|
@@ -1230,7 +1212,15 @@ interface Router$1 {
|
|
|
1230
1212
|
* Utility function to create an href for the given location
|
|
1231
1213
|
* @param location
|
|
1232
1214
|
*/
|
|
1233
|
-
createHref(location: Location | URL): string;
|
|
1215
|
+
createHref(location: Location$1 | URL): string;
|
|
1216
|
+
/**
|
|
1217
|
+
* @private
|
|
1218
|
+
* PRIVATE - DO NOT USE
|
|
1219
|
+
*
|
|
1220
|
+
* Utility function to create a URL for the given location
|
|
1221
|
+
* @param location
|
|
1222
|
+
*/
|
|
1223
|
+
createURL?(to: To): URL;
|
|
1234
1224
|
/**
|
|
1235
1225
|
* @private
|
|
1236
1226
|
* PRIVATE - DO NOT USE
|
|
@@ -1338,7 +1328,7 @@ interface RouterState {
|
|
|
1338
1328
|
/**
|
|
1339
1329
|
* The current location reflected by the router
|
|
1340
1330
|
*/
|
|
1341
|
-
location: Location;
|
|
1331
|
+
location: Location$1;
|
|
1342
1332
|
/**
|
|
1343
1333
|
* The current set of route matches
|
|
1344
1334
|
*/
|
|
@@ -1399,7 +1389,10 @@ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "e
|
|
|
1399
1389
|
/**
|
|
1400
1390
|
* Future flags to toggle new feature behavior
|
|
1401
1391
|
*/
|
|
1402
|
-
interface FutureConfig {
|
|
1392
|
+
interface FutureConfig {
|
|
1393
|
+
/** Enables route-pattern matching after calling `unstable_preloadRoutePattern()`. */
|
|
1394
|
+
unstable_routePatternMatching?: boolean;
|
|
1395
|
+
}
|
|
1403
1396
|
/**
|
|
1404
1397
|
* Initialization options for createRouter
|
|
1405
1398
|
*/
|
|
@@ -1431,6 +1424,8 @@ interface StaticHandlerContext {
|
|
|
1431
1424
|
loaderHeaders: Record<string, Headers>;
|
|
1432
1425
|
actionHeaders: Record<string, Headers>;
|
|
1433
1426
|
_deepestRenderedBoundaryId?: string | null;
|
|
1427
|
+
/** @private */
|
|
1428
|
+
_match: StaticHandler["match"];
|
|
1434
1429
|
}
|
|
1435
1430
|
/**
|
|
1436
1431
|
* A StaticHandler instance manages a singular SSR navigation/fetch event
|
|
@@ -1444,10 +1439,10 @@ interface StaticHandler {
|
|
|
1444
1439
|
* @private
|
|
1445
1440
|
* PRIVATE - DO NOT USE
|
|
1446
1441
|
*
|
|
1447
|
-
*
|
|
1448
|
-
* matching
|
|
1442
|
+
* Match routes against a location using the handler's configured route
|
|
1443
|
+
* matching implementation.
|
|
1449
1444
|
*/
|
|
1450
|
-
|
|
1445
|
+
match(locationArg: Partial<Location$1> | string): DataRouteMatch[] | null;
|
|
1451
1446
|
/**
|
|
1452
1447
|
* Perform a query for a given request - executing all matched route
|
|
1453
1448
|
* loaders/actions. Used for document requests.
|
|
@@ -1495,8 +1490,8 @@ interface StaticHandler {
|
|
|
1495
1490
|
}): Promise<any>;
|
|
1496
1491
|
}
|
|
1497
1492
|
type ViewTransitionOpts = {
|
|
1498
|
-
currentLocation: Location;
|
|
1499
|
-
nextLocation: Location;
|
|
1493
|
+
currentLocation: Location$1;
|
|
1494
|
+
nextLocation: Location$1;
|
|
1500
1495
|
};
|
|
1501
1496
|
/**
|
|
1502
1497
|
* Subscriber function signature for changes to router state
|
|
@@ -1514,7 +1509,7 @@ interface RouterSubscriber {
|
|
|
1514
1509
|
* for a given location
|
|
1515
1510
|
*/
|
|
1516
1511
|
interface GetScrollRestorationKeyFunction {
|
|
1517
|
-
(location: Location, matches: UIMatch[]): string | null;
|
|
1512
|
+
(location: Location$1, matches: UIMatch[]): string | null;
|
|
1518
1513
|
}
|
|
1519
1514
|
/**
|
|
1520
1515
|
* Function signature for determining the current scroll position
|
|
@@ -1596,7 +1591,7 @@ type NavigationStates = {
|
|
|
1596
1591
|
};
|
|
1597
1592
|
Loading: {
|
|
1598
1593
|
state: "loading";
|
|
1599
|
-
location: Location;
|
|
1594
|
+
location: Location$1;
|
|
1600
1595
|
matches: DataRouteMatch[];
|
|
1601
1596
|
historyAction: Action;
|
|
1602
1597
|
formMethod: Submission["formMethod"] | undefined;
|
|
@@ -1608,7 +1603,7 @@ type NavigationStates = {
|
|
|
1608
1603
|
};
|
|
1609
1604
|
Submitting: {
|
|
1610
1605
|
state: "submitting";
|
|
1611
|
-
location: Location;
|
|
1606
|
+
location: Location$1;
|
|
1612
1607
|
matches: DataRouteMatch[];
|
|
1613
1608
|
historyAction: Action;
|
|
1614
1609
|
formMethod: Submission["formMethod"];
|
|
@@ -1698,7 +1693,7 @@ interface BlockerBlocked {
|
|
|
1698
1693
|
state: "blocked";
|
|
1699
1694
|
reset: () => void;
|
|
1700
1695
|
proceed: () => void;
|
|
1701
|
-
location: Location;
|
|
1696
|
+
location: Location$1;
|
|
1702
1697
|
}
|
|
1703
1698
|
interface BlockerUnblocked {
|
|
1704
1699
|
state: "unblocked";
|
|
@@ -1710,12 +1705,12 @@ interface BlockerProceeding {
|
|
|
1710
1705
|
state: "proceeding";
|
|
1711
1706
|
reset: undefined;
|
|
1712
1707
|
proceed: undefined;
|
|
1713
|
-
location: Location;
|
|
1708
|
+
location: Location$1;
|
|
1714
1709
|
}
|
|
1715
1710
|
type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
|
|
1716
1711
|
type BlockerFunction = (args: {
|
|
1717
|
-
currentLocation: Location;
|
|
1718
|
-
nextLocation: Location;
|
|
1712
|
+
currentLocation: Location$1;
|
|
1713
|
+
nextLocation: Location$1;
|
|
1719
1714
|
historyAction: Action;
|
|
1720
1715
|
}) => boolean;
|
|
1721
1716
|
interface CreateStaticHandlerOptions {
|
|
@@ -2000,7 +1995,7 @@ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoad
|
|
|
2000
1995
|
interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
|
2001
1996
|
loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
|
2002
1997
|
params: Params;
|
|
2003
|
-
location: Location;
|
|
1998
|
+
location: Location$1;
|
|
2004
1999
|
matches: MetaMatches<MatchLoaders>;
|
|
2005
2000
|
error?: unknown;
|
|
2006
2001
|
}
|
|
@@ -2321,7 +2316,7 @@ type RSCRenderPayload = {
|
|
|
2321
2316
|
clientVersion?: string;
|
|
2322
2317
|
errors: Record<string, any> | null;
|
|
2323
2318
|
loaderData: Record<string, any>;
|
|
2324
|
-
location: Location;
|
|
2319
|
+
location: Location$1;
|
|
2325
2320
|
routeDiscovery: RouteDiscovery;
|
|
2326
2321
|
matches: RSCRouteMatch[];
|
|
2327
2322
|
patches?: Promise<RSCRouteManifest[]>;
|
|
@@ -2369,6 +2364,13 @@ type RouteDiscovery = {
|
|
|
2369
2364
|
* encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
|
|
2370
2365
|
* enabled client router.
|
|
2371
2366
|
*
|
|
2367
|
+
* Treat every React Server Function as a public endpoint. Server Functions are
|
|
2368
|
+
* not inherently associated with a route. Any route middleware that runs is
|
|
2369
|
+
* selected from the URL used to call a Server Function, but the client controls
|
|
2370
|
+
* both the Server Function identifier and the URL. Perform all access control
|
|
2371
|
+
* checks within each Server Function, or use a route action for
|
|
2372
|
+
* middleware-driven access control.
|
|
2373
|
+
*
|
|
2372
2374
|
* @example
|
|
2373
2375
|
* import {
|
|
2374
2376
|
* createTemporaryReferenceSet,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.4.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -24,7 +24,7 @@ function warning(cond, message) {
|
|
|
24
24
|
if (typeof console !== "undefined") console.warn(message);
|
|
25
25
|
try {
|
|
26
26
|
throw new Error(message);
|
|
27
|
-
} catch
|
|
27
|
+
} catch {}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
function createKey$1() {
|
|
@@ -207,7 +207,8 @@ const unsupportedLazyRouteObjectKeys = new Set([
|
|
|
207
207
|
"path",
|
|
208
208
|
"id",
|
|
209
209
|
"index",
|
|
210
|
-
"children"
|
|
210
|
+
"children",
|
|
211
|
+
"unstable_validateParams"
|
|
211
212
|
]);
|
|
212
213
|
function isUnsupportedLazyRouteObjectKey(key) {
|
|
213
214
|
return unsupportedLazyRouteObjectKeys.has(key);
|
|
@@ -219,7 +220,8 @@ const unsupportedLazyRouteFunctionKeys = new Set([
|
|
|
219
220
|
"id",
|
|
220
221
|
"index",
|
|
221
222
|
"middleware",
|
|
222
|
-
"children"
|
|
223
|
+
"children",
|
|
224
|
+
"unstable_validateParams"
|
|
223
225
|
]);
|
|
224
226
|
function isUnsupportedLazyRouteFunctionKey(key) {
|
|
225
227
|
return unsupportedLazyRouteFunctionKeys.has(key);
|
|
@@ -506,13 +508,13 @@ function matchPathImpl(pattern, pathname, matcher, compiledParams) {
|
|
|
506
508
|
let match = pathname.match(matcher);
|
|
507
509
|
if (!match) return null;
|
|
508
510
|
let matchedPathname = match[0];
|
|
509
|
-
let pathnameBase = matchedPathname
|
|
511
|
+
let pathnameBase = removeTrailingSlash(matchedPathname, 1);
|
|
510
512
|
let captureGroups = match.slice(1);
|
|
511
513
|
return {
|
|
512
514
|
params: compiledParams.reduce((memo, { paramName, isOptional }, index) => {
|
|
513
515
|
if (paramName === "*") {
|
|
514
516
|
let splatValue = captureGroups[index] || "";
|
|
515
|
-
pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length)
|
|
517
|
+
pathnameBase = removeTrailingSlash(matchedPathname.slice(0, matchedPathname.length - splatValue.length), 1);
|
|
516
518
|
}
|
|
517
519
|
const value = captureGroups[index];
|
|
518
520
|
if (isOptional && !value) memo[paramName] = void 0;
|
|
@@ -581,7 +583,7 @@ function resolvePath(to, fromPathname = "/") {
|
|
|
581
583
|
let pathname;
|
|
582
584
|
if (toPathname) {
|
|
583
585
|
toPathname = removeDoubleSlashes(toPathname);
|
|
584
|
-
if (toPathname.startsWith("/")) pathname = resolvePathname(toPathname.substring(1), "/");
|
|
586
|
+
if (toPathname.startsWith("/") || toPathname.startsWith("\\")) pathname = resolvePathname(toPathname.substring(1), "/");
|
|
585
587
|
else pathname = resolvePathname(toPathname, fromPathname);
|
|
586
588
|
} else pathname = fromPathname;
|
|
587
589
|
return {
|
|
@@ -642,7 +644,11 @@ function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = fal
|
|
|
642
644
|
}
|
|
643
645
|
const removeDoubleSlashes = (path) => path.replace(/[\\/]{2,}/g, "/");
|
|
644
646
|
const joinPaths = (paths) => removeDoubleSlashes(paths.join("/"));
|
|
645
|
-
|
|
647
|
+
function removeTrailingSlash(path, minLength = 0) {
|
|
648
|
+
let end = path.length;
|
|
649
|
+
while (end > minLength && path.charCodeAt(end - 1) === 47) end--;
|
|
650
|
+
return end === path.length ? path : path.slice(0, end);
|
|
651
|
+
}
|
|
646
652
|
const normalizePathname = (pathname) => removeTrailingSlash(pathname).replace(/^\/*/, "/");
|
|
647
653
|
const normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
|
648
654
|
const normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
|
@@ -1027,6 +1033,23 @@ function getReadonlyContext(context) {
|
|
|
1027
1033
|
return { get: (ctx) => context.get(ctx) };
|
|
1028
1034
|
}
|
|
1029
1035
|
//#endregion
|
|
1036
|
+
//#region lib/router/matcher.ts
|
|
1037
|
+
var V6RegExMatcher = class {
|
|
1038
|
+
#routes = [];
|
|
1039
|
+
#branches = [];
|
|
1040
|
+
#basename;
|
|
1041
|
+
constructor(basename) {
|
|
1042
|
+
this.#basename = basename;
|
|
1043
|
+
}
|
|
1044
|
+
update(routes) {
|
|
1045
|
+
this.#routes = routes;
|
|
1046
|
+
this.#branches = flattenAndRankRoutes(routes);
|
|
1047
|
+
}
|
|
1048
|
+
match(locationArg, allowPartial = false) {
|
|
1049
|
+
return matchRoutesImpl(this.#routes, locationArg, this.#basename, allowPartial, this.#branches);
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
//#endregion
|
|
1030
1053
|
//#region lib/router/router.ts
|
|
1031
1054
|
const validMutationMethodsArr = [
|
|
1032
1055
|
"POST",
|
|
@@ -1045,6 +1068,14 @@ const redirectStatusCodes = new Set([
|
|
|
1045
1068
|
308
|
|
1046
1069
|
]);
|
|
1047
1070
|
const ResetLoaderDataSymbol = Symbol("ResetLoaderData");
|
|
1071
|
+
function createDataRouteMatcher(future, basename) {
|
|
1072
|
+
if (future.unstable_routePatternMatching) {
|
|
1073
|
+
let RoutePatternMatcher = void 0;
|
|
1074
|
+
invariant$1(RoutePatternMatcher, "You must call unstable_preloadRoutePattern() from \"react-router/route-pattern\" before enabling future.unstable_routePatternMatching.");
|
|
1075
|
+
return new RoutePatternMatcher(basename);
|
|
1076
|
+
}
|
|
1077
|
+
return new V6RegExMatcher(basename);
|
|
1078
|
+
}
|
|
1048
1079
|
/**
|
|
1049
1080
|
* Create a static handler to perform server-side data loading
|
|
1050
1081
|
*
|
|
@@ -1081,7 +1112,7 @@ function createStaticHandler(routes, opts) {
|
|
|
1081
1112
|
let basename = (opts ? opts.basename : null) || "/";
|
|
1082
1113
|
let _mapRouteProperties = opts?.mapRouteProperties;
|
|
1083
1114
|
let mapRouteProperties = _mapRouteProperties ? _mapRouteProperties : () => ({});
|
|
1084
|
-
({ ...opts?.future });
|
|
1115
|
+
let dataRouteMatcher = createDataRouteMatcher({ ...opts?.future }, basename);
|
|
1085
1116
|
if (opts?.instrumentations) {
|
|
1086
1117
|
let instrumentations = opts.instrumentations;
|
|
1087
1118
|
mapRouteProperties = (route) => {
|
|
@@ -1092,7 +1123,8 @@ function createStaticHandler(routes, opts) {
|
|
|
1092
1123
|
};
|
|
1093
1124
|
}
|
|
1094
1125
|
let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, void 0, manifest);
|
|
1095
|
-
|
|
1126
|
+
dataRouteMatcher.update(dataRoutes);
|
|
1127
|
+
let match = (locationArg) => dataRouteMatcher.match(locationArg);
|
|
1096
1128
|
/**
|
|
1097
1129
|
* The query() method is intended for document requests, in which we want to
|
|
1098
1130
|
* call an optional action and potentially multiple loaders for all nested
|
|
@@ -1123,7 +1155,7 @@ function createStaticHandler(routes, opts) {
|
|
|
1123
1155
|
let normalizePathImpl = normalizePath || defaultNormalizePath;
|
|
1124
1156
|
let method = request.method;
|
|
1125
1157
|
let location = createLocation("", normalizePathImpl(request), null, "default");
|
|
1126
|
-
let matches =
|
|
1158
|
+
let matches = dataRouteMatcher.match(location);
|
|
1127
1159
|
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
1128
1160
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
1129
1161
|
let error = getInternalRouterError(405, { method });
|
|
@@ -1137,7 +1169,8 @@ function createStaticHandler(routes, opts) {
|
|
|
1137
1169
|
errors: { [route.id]: error },
|
|
1138
1170
|
statusCode: error.status,
|
|
1139
1171
|
loaderHeaders: {},
|
|
1140
|
-
actionHeaders: {}
|
|
1172
|
+
actionHeaders: {},
|
|
1173
|
+
_match: match
|
|
1141
1174
|
};
|
|
1142
1175
|
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
1143
1176
|
} else if (!matches) {
|
|
@@ -1152,7 +1185,8 @@ function createStaticHandler(routes, opts) {
|
|
|
1152
1185
|
errors: { [route.id]: error },
|
|
1153
1186
|
statusCode: error.status,
|
|
1154
1187
|
loaderHeaders: {},
|
|
1155
|
-
actionHeaders: {}
|
|
1188
|
+
actionHeaders: {},
|
|
1189
|
+
_match: match
|
|
1156
1190
|
};
|
|
1157
1191
|
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
1158
1192
|
}
|
|
@@ -1175,7 +1209,8 @@ function createStaticHandler(routes, opts) {
|
|
|
1175
1209
|
renderedStaticContext = {
|
|
1176
1210
|
location,
|
|
1177
1211
|
basename,
|
|
1178
|
-
...result
|
|
1212
|
+
...result,
|
|
1213
|
+
_match: match
|
|
1179
1214
|
};
|
|
1180
1215
|
return renderedStaticContext;
|
|
1181
1216
|
});
|
|
@@ -1201,7 +1236,8 @@ function createStaticHandler(routes, opts) {
|
|
|
1201
1236
|
errors: { [skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, matches.find((m) => m.route.id === routeId || m.route.loader)?.route.id || routeId).route.id]: error },
|
|
1202
1237
|
statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
|
1203
1238
|
actionHeaders: {},
|
|
1204
|
-
loaderHeaders: {}
|
|
1239
|
+
loaderHeaders: {},
|
|
1240
|
+
_match: match
|
|
1205
1241
|
};
|
|
1206
1242
|
return generateMiddlewareResponse(() => Promise.resolve(staticContext));
|
|
1207
1243
|
}
|
|
@@ -1218,7 +1254,8 @@ function createStaticHandler(routes, opts) {
|
|
|
1218
1254
|
return {
|
|
1219
1255
|
location,
|
|
1220
1256
|
basename,
|
|
1221
|
-
...result
|
|
1257
|
+
...result,
|
|
1258
|
+
_match: match
|
|
1222
1259
|
};
|
|
1223
1260
|
}
|
|
1224
1261
|
/**
|
|
@@ -1251,7 +1288,7 @@ function createStaticHandler(routes, opts) {
|
|
|
1251
1288
|
let normalizePathImpl = normalizePath || defaultNormalizePath;
|
|
1252
1289
|
let method = request.method;
|
|
1253
1290
|
let location = createLocation("", normalizePathImpl(request), null, "default");
|
|
1254
|
-
let matches =
|
|
1291
|
+
let matches = dataRouteMatcher.match(location);
|
|
1255
1292
|
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
|
1256
1293
|
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") throw getInternalRouterError(405, { method });
|
|
1257
1294
|
else if (!matches) throw getInternalRouterError(404, { pathname: location.pathname });
|
|
@@ -1432,7 +1469,7 @@ function createStaticHandler(routes, opts) {
|
|
|
1432
1469
|
}
|
|
1433
1470
|
return {
|
|
1434
1471
|
dataRoutes,
|
|
1435
|
-
|
|
1472
|
+
match,
|
|
1436
1473
|
query,
|
|
1437
1474
|
queryRoute
|
|
1438
1475
|
};
|
|
@@ -1807,7 +1844,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, path, matches, fe
|
|
|
1807
1844
|
});
|
|
1808
1845
|
try {
|
|
1809
1846
|
await Promise.all(matches.flatMap((m) => [m._lazyPromises?.handler, m._lazyPromises?.route]));
|
|
1810
|
-
} catch
|
|
1847
|
+
} catch {}
|
|
1811
1848
|
return results;
|
|
1812
1849
|
}
|
|
1813
1850
|
async function callLoaderOrAction({ request, path, pattern, match, lazyHandlerPromise, lazyRoutePromise, handlerOverride, scopedContext }) {
|
|
@@ -2208,14 +2245,19 @@ function getPathsWithAncestors(paths) {
|
|
|
2208
2245
|
function throwIfPotentialCSRFAttack(request, allowedActionOrigins) {
|
|
2209
2246
|
let originHeader = request.headers.get("origin");
|
|
2210
2247
|
let originDomain = null;
|
|
2248
|
+
let originUrl = null;
|
|
2211
2249
|
try {
|
|
2212
|
-
|
|
2250
|
+
if (typeof originHeader === "string" && originHeader !== "null") {
|
|
2251
|
+
originUrl = new URL(originHeader);
|
|
2252
|
+
originDomain = originUrl.host;
|
|
2253
|
+
} else originDomain = originHeader;
|
|
2213
2254
|
} catch {
|
|
2214
2255
|
throw new Error(`\`origin\` header is not a valid URL. Aborting the action.`);
|
|
2215
2256
|
}
|
|
2216
|
-
let
|
|
2217
|
-
|
|
2218
|
-
|
|
2257
|
+
let requestUrl = new URL(request.url);
|
|
2258
|
+
let originMatchesRequest = originUrl ? originUrl.origin === requestUrl.origin : originDomain === requestUrl.host;
|
|
2259
|
+
if (originDomain && !originMatchesRequest) {
|
|
2260
|
+
if (!isAllowedOrigin(originDomain, allowedActionOrigins)) throw new Error("The `request.url` origin does not match `origin` header from a forwarded action request. Aborting the action.");
|
|
2219
2261
|
}
|
|
2220
2262
|
}
|
|
2221
2263
|
function matchWildcardDomain(domain, pattern) {
|
|
@@ -2319,6 +2361,13 @@ const Await = (async ({ children, resolve, errorElement }) => {
|
|
|
2319
2361
|
* encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
|
|
2320
2362
|
* enabled client router.
|
|
2321
2363
|
*
|
|
2364
|
+
* Treat every React Server Function as a public endpoint. Server Functions are
|
|
2365
|
+
* not inherently associated with a route. Any route middleware that runs is
|
|
2366
|
+
* selected from the URL used to call a Server Function, but the client controls
|
|
2367
|
+
* both the Server Function identifier and the URL. Perform all access control
|
|
2368
|
+
* checks within each Server Function, or use a route action for
|
|
2369
|
+
* middleware-driven access control.
|
|
2370
|
+
*
|
|
2322
2371
|
* @example
|
|
2323
2372
|
* import {
|
|
2324
2373
|
* createTemporaryReferenceSet,
|
|
@@ -2406,11 +2455,12 @@ async function matchRSCServerRequest({ allowedActionOrigins, createTemporaryRefe
|
|
|
2406
2455
|
const requestUrl = new URL(request.url);
|
|
2407
2456
|
if (isManifestRequest(requestUrl)) return await generateManifestResponse(routes, basename, request, generateResponse, temporaryReferences, routeDiscovery, clientVersion);
|
|
2408
2457
|
let isDataRequest = isReactServerRequest(requestUrl);
|
|
2409
|
-
let
|
|
2458
|
+
let staticHandler = createStaticHandler(routes, { basename });
|
|
2459
|
+
let matches = staticHandler.match(url.pathname);
|
|
2410
2460
|
if (matches) await Promise.all(matches.map((m) => explodeLazyRoute(m.route)));
|
|
2411
2461
|
const leafMatch = matches?.[matches.length - 1];
|
|
2412
|
-
if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return generateResourceResponse(routerRequest,
|
|
2413
|
-
let response = await generateRenderResponse(routerRequest,
|
|
2462
|
+
if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return generateResourceResponse(routerRequest, staticHandler, leafMatch.route.id, requestContext, onError);
|
|
2463
|
+
let response = await generateRenderResponse(routerRequest, staticHandler, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences, allowedActionOrigins, routeDiscovery, clientVersion);
|
|
2414
2464
|
response.headers.set("X-Remix-Response", "yes");
|
|
2415
2465
|
return response;
|
|
2416
2466
|
}
|
|
@@ -2443,9 +2493,10 @@ async function generateManifestResponse(routes, basename, request, generateRespo
|
|
|
2443
2493
|
}
|
|
2444
2494
|
let pathParam = url.searchParams.get("paths");
|
|
2445
2495
|
let pathnames = pathParam ? pathParam.split(",").filter(Boolean) : [url.pathname.replace(/\.manifest$/, "")];
|
|
2496
|
+
let staticHandler = routes.length > 0 ? createStaticHandler(routes, { basename }) : void 0;
|
|
2446
2497
|
let routeIds = /* @__PURE__ */ new Set();
|
|
2447
|
-
let matchedRoutes = pathnames.flatMap((pathname) => {
|
|
2448
|
-
let pathnameMatches =
|
|
2498
|
+
let matchedRoutes = staticHandler ? pathnames.flatMap((pathname) => {
|
|
2499
|
+
let pathnameMatches = staticHandler.match(pathname);
|
|
2449
2500
|
return pathnameMatches?.map((m, i) => ({
|
|
2450
2501
|
...m.route,
|
|
2451
2502
|
parentId: pathnameMatches[i - 1]?.route.id
|
|
@@ -2456,10 +2507,10 @@ async function generateManifestResponse(routes, basename, request, generateRespo
|
|
|
2456
2507
|
return true;
|
|
2457
2508
|
}
|
|
2458
2509
|
return false;
|
|
2459
|
-
});
|
|
2510
|
+
}) : [];
|
|
2460
2511
|
let payload = {
|
|
2461
2512
|
type: "manifest",
|
|
2462
|
-
patches: Promise.all([...matchedRoutes.map((route) => getManifestRoute(route)), getAdditionalRoutePatches(pathnames,
|
|
2513
|
+
patches: Promise.all([...matchedRoutes.map((route) => getManifestRoute(route)), staticHandler ? getAdditionalRoutePatches(pathnames, staticHandler, Array.from(routeIds)) : Promise.resolve([])]).then((r) => r.flat(1))
|
|
2463
2514
|
};
|
|
2464
2515
|
return generateResponse({
|
|
2465
2516
|
statusCode: 200,
|
|
@@ -2529,9 +2580,9 @@ async function processServerAction(request, basename, decodeReply, loadServerAct
|
|
|
2529
2580
|
}
|
|
2530
2581
|
}
|
|
2531
2582
|
}
|
|
2532
|
-
async function generateResourceResponse(request,
|
|
2583
|
+
async function generateResourceResponse(request, staticHandler, routeId, requestContext, onError) {
|
|
2533
2584
|
try {
|
|
2534
|
-
return await
|
|
2585
|
+
return await staticHandler.queryRoute(request, {
|
|
2535
2586
|
routeId,
|
|
2536
2587
|
requestContext,
|
|
2537
2588
|
async generateMiddlewareResponse(queryRoute) {
|
|
@@ -2572,12 +2623,11 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2572
2623
|
});
|
|
2573
2624
|
}
|
|
2574
2625
|
}
|
|
2575
|
-
async function generateRenderResponse(request,
|
|
2626
|
+
async function generateRenderResponse(request, staticHandler, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences, allowedActionOrigins, routeDiscovery, clientVersion) {
|
|
2576
2627
|
let statusCode = 200;
|
|
2577
2628
|
let url = new URL(request.url);
|
|
2578
2629
|
let isSubmission = isMutationMethod(request.method);
|
|
2579
2630
|
let routeIdsToLoad = !isSubmission && url.searchParams.has("_routes") ? url.searchParams.get("_routes").split(",") : null;
|
|
2580
|
-
const staticHandler = createStaticHandler(routes, { basename });
|
|
2581
2631
|
let actionResult;
|
|
2582
2632
|
const ctx = {
|
|
2583
2633
|
request,
|
|
@@ -2625,7 +2675,7 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2625
2675
|
staticContext.errors[staticContext.matches[0].route.id] = potentialCSRFAttackError;
|
|
2626
2676
|
staticContext.statusCode = 400;
|
|
2627
2677
|
}
|
|
2628
|
-
return generateStaticContextResponse(
|
|
2678
|
+
return generateStaticContextResponse(staticHandler, basename, generateResponse, statusCode, routeIdsToLoad, isDataRequest, isSubmission, actionResult, formState, staticContext, temporaryReferences, skipRevalidation, ctx.redirect?.headers, routeDiscovery, clientVersion);
|
|
2629
2679
|
}
|
|
2630
2680
|
}));
|
|
2631
2681
|
if (isRedirectResponse(result)) return generateRedirectResponse(result, actionResult, basename, isDataRequest, generateResponse, temporaryReferences, ctx.redirect?.headers);
|
|
@@ -2659,7 +2709,7 @@ function generateRedirectResponse(response, actionResult, basename, isDataReques
|
|
|
2659
2709
|
onError: defaultOnError
|
|
2660
2710
|
});
|
|
2661
2711
|
}
|
|
2662
|
-
async function generateStaticContextResponse(
|
|
2712
|
+
async function generateStaticContextResponse(staticHandler, basename, generateResponse, statusCode, routeIdsToLoad, isDataRequest, isSubmission, actionResult, formState, staticContext, temporaryReferences, skipRevalidation, sideEffectRedirectHeaders, routeDiscovery, clientVersion) {
|
|
2663
2713
|
statusCode = staticContext.statusCode ?? statusCode;
|
|
2664
2714
|
if (staticContext.errors) staticContext.errors = Object.fromEntries(Object.entries(staticContext.errors).map(([key, error]) => [key, isRouteErrorResponse(error) ? Object.fromEntries(Object.entries(error)) : error]));
|
|
2665
2715
|
staticContext.matches.forEach((m) => {
|
|
@@ -2680,7 +2730,7 @@ async function generateStaticContextResponse(routes, basename, generateResponse,
|
|
|
2680
2730
|
location: staticContext.location,
|
|
2681
2731
|
formState
|
|
2682
2732
|
};
|
|
2683
|
-
const renderPayloadPromise = () => getRenderPayload(baseRenderPayload,
|
|
2733
|
+
const renderPayloadPromise = () => getRenderPayload(baseRenderPayload, staticHandler, basename, routeIdsToLoad, isDataRequest, staticContext, routeDiscovery);
|
|
2684
2734
|
let payload;
|
|
2685
2735
|
if (actionResult) payload = {
|
|
2686
2736
|
type: "action",
|
|
@@ -2702,7 +2752,8 @@ async function generateStaticContextResponse(routes, basename, generateResponse,
|
|
|
2702
2752
|
onError: defaultOnError
|
|
2703
2753
|
});
|
|
2704
2754
|
}
|
|
2705
|
-
async function getRenderPayload(baseRenderPayload,
|
|
2755
|
+
async function getRenderPayload(baseRenderPayload, staticHandler, basename, routeIdsToLoad, isDataRequest, staticContext, routeDiscovery) {
|
|
2756
|
+
let routes = staticHandler.dataRoutes;
|
|
2706
2757
|
let deepestRenderedRouteIdx = staticContext.matches.length - 1;
|
|
2707
2758
|
let parentIds = {};
|
|
2708
2759
|
staticContext.matches.forEach((m, i) => {
|
|
@@ -2720,7 +2771,9 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2720
2771
|
parentId
|
|
2721
2772
|
});
|
|
2722
2773
|
}));
|
|
2723
|
-
let patches
|
|
2774
|
+
let patches;
|
|
2775
|
+
if (routeDiscovery?.mode === "initial" && !isDataRequest) patches = getAllRoutePatches(routes, basename).then((patches) => patches.filter((patch) => !staticContext.matches.some((m) => m.route.id === patch.id)));
|
|
2776
|
+
else patches = getAdditionalRoutePatches(getPathsWithAncestors([staticContext.location.pathname]), staticHandler, staticContext.matches.map((m) => m.route.id));
|
|
2724
2777
|
return {
|
|
2725
2778
|
...baseRenderPayload,
|
|
2726
2779
|
matches: await matchesPromise,
|
|
@@ -2824,13 +2877,13 @@ async function getAllRoutePatches(routes, basename) {
|
|
|
2824
2877
|
for (let route of routes) await traverse(route, void 0);
|
|
2825
2878
|
return patches.filter((p) => !!p.parentId);
|
|
2826
2879
|
}
|
|
2827
|
-
async function getAdditionalRoutePatches(pathnames,
|
|
2880
|
+
async function getAdditionalRoutePatches(pathnames, staticHandler, matchedRouteIds) {
|
|
2828
2881
|
let patchRouteMatches = /* @__PURE__ */ new Map();
|
|
2829
2882
|
let matchedPaths = /* @__PURE__ */ new Set();
|
|
2830
2883
|
for (const pathname of pathnames) {
|
|
2831
2884
|
if (matchedPaths.has(pathname)) continue;
|
|
2832
2885
|
matchedPaths.add(pathname);
|
|
2833
|
-
let matches =
|
|
2886
|
+
let matches = staticHandler.match(pathname) || [];
|
|
2834
2887
|
matches.forEach((m, i) => {
|
|
2835
2888
|
if (patchRouteMatches.get(m.route.id)) return;
|
|
2836
2889
|
patchRouteMatches.set(m.route.id, {
|
|
@@ -2939,7 +2992,7 @@ const unsign = async (cookie, secret) => {
|
|
|
2939
2992
|
try {
|
|
2940
2993
|
let signature = byteStringToUint8Array(atob(hash));
|
|
2941
2994
|
return await crypto.subtle.verify("HMAC", key, signature, data) ? value : false;
|
|
2942
|
-
} catch
|
|
2995
|
+
} catch {
|
|
2943
2996
|
return false;
|
|
2944
2997
|
}
|
|
2945
2998
|
};
|
|
@@ -3037,7 +3090,7 @@ function encodeData(value) {
|
|
|
3037
3090
|
function decodeData(value) {
|
|
3038
3091
|
try {
|
|
3039
3092
|
return JSON.parse(decodeURIComponent(myEscape(atob(value))));
|
|
3040
|
-
} catch
|
|
3093
|
+
} catch {
|
|
3041
3094
|
return {};
|
|
3042
3095
|
}
|
|
3043
3096
|
}
|