react-router 8.5.2 → 8.5.3
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 +50 -0
- 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 +3 -2
- package/dist/development/index-react-server.js +41 -36
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/await.js +1 -1
- package/dist/development/lib/components.js +10 -8
- package/dist/development/lib/context.js +3 -2
- package/dist/development/lib/dom/dom.js +4 -2
- package/dist/development/lib/dom/lib.js +12 -5
- package/dist/development/lib/dom/server.js +5 -3
- package/dist/development/lib/dom/ssr/components.js +4 -1
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/errorBoundaries.js +2 -1
- package/dist/development/lib/dom/ssr/fallback.js +2 -1
- package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
- 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.js +1 -1
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +3 -1
- package/dist/development/lib/dom/ssr/routes.js +2 -1
- package/dist/development/lib/dom/ssr/server.js +1 -1
- package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.js +1 -1
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.d.ts +30 -0
- package/dist/development/lib/hooks.js +39 -5
- package/dist/development/lib/href.js +1 -1
- package/dist/development/lib/router/history.js +10 -4
- 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.js +22 -8
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +2 -0
- package/dist/development/lib/router/utils.js +8 -2
- package/dist/development/lib/rsc/browser.js +2 -2
- package/dist/development/lib/rsc/errorBoundaries.js +3 -2
- package/dist/development/lib/rsc/html-stream/browser.js +1 -1
- package/dist/development/lib/rsc/html-stream/server.js +1 -1
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +2 -1
- package/dist/development/lib/rsc/server.ssr.d.ts +1 -0
- package/dist/development/lib/rsc/server.ssr.js +5 -4
- 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.js +1 -1
- package/dist/development/lib/server-runtime/server.js +1 -1
- package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +3 -2
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions.d.ts +1 -1
- package/dist/development/lib/server-runtime/sessions.js +5 -3
- 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-module-annotations.d.ts +16 -9
- 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 +9 -8
- 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 +3 -2
- package/dist/production/index-react-server.js +41 -36
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/await.js +1 -1
- package/dist/production/lib/components.js +10 -8
- package/dist/production/lib/context.js +3 -2
- package/dist/production/lib/dom/dom.js +4 -2
- package/dist/production/lib/dom/lib.js +12 -5
- package/dist/production/lib/dom/server.js +5 -3
- package/dist/production/lib/dom/ssr/components.js +4 -1
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/errorBoundaries.js +2 -1
- package/dist/production/lib/dom/ssr/fallback.js +1 -1
- package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
- 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.js +1 -1
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +3 -1
- package/dist/production/lib/dom/ssr/routes.js +2 -1
- package/dist/production/lib/dom/ssr/server.js +1 -1
- package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.js +1 -1
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.d.ts +30 -0
- package/dist/production/lib/hooks.js +38 -4
- package/dist/production/lib/href.js +1 -1
- package/dist/production/lib/router/history.js +10 -4
- 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.js +22 -8
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +2 -0
- package/dist/production/lib/router/utils.js +8 -2
- package/dist/production/lib/rsc/browser.js +2 -2
- package/dist/production/lib/rsc/errorBoundaries.js +3 -2
- package/dist/production/lib/rsc/html-stream/browser.js +1 -1
- package/dist/production/lib/rsc/html-stream/server.js +1 -1
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +2 -1
- package/dist/production/lib/rsc/server.ssr.d.ts +1 -0
- package/dist/production/lib/rsc/server.ssr.js +5 -4
- 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.js +1 -1
- package/dist/production/lib/server-runtime/server.js +1 -1
- package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +3 -2
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions.d.ts +1 -1
- package/dist/production/lib/server-runtime/sessions.js +5 -3
- 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-module-annotations.d.ts +16 -9
- 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 +9 -8
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/package.json +1 -1
|
@@ -884,6 +884,36 @@ type UseRoute<RouteId extends keyof RouteModules | unknown> = {
|
|
|
884
884
|
loaderData: RouteId extends keyof RouteModules ? GetLoaderData<RouteModules[RouteId]> | undefined : unknown;
|
|
885
885
|
actionData: RouteId extends keyof RouteModules ? GetActionData<RouteModules[RouteId]> | undefined : unknown;
|
|
886
886
|
};
|
|
887
|
+
/**
|
|
888
|
+
* Returns the current route's `handle`, `loaderData`, and `actionData`, or
|
|
889
|
+
* those of a matched route identified by `routeId`.
|
|
890
|
+
*
|
|
891
|
+
* Omit `routeId` to read the current route. Pass a route ID to infer the
|
|
892
|
+
* fields from registered route module types. Without an ID, the fields
|
|
893
|
+
* are typed as `unknown`.
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* import { unstable_useRoute as useRoute } from "react-router";
|
|
897
|
+
*
|
|
898
|
+
* let currentRoute = useRoute();
|
|
899
|
+
* let rootRoute = useRoute("root");
|
|
900
|
+
*
|
|
901
|
+
* // A registered non-root route may not currently be matched:
|
|
902
|
+
* let dashboard = useRoute("routes/dashboard");
|
|
903
|
+
* if (dashboard) {
|
|
904
|
+
* console.log(dashboard.handle, dashboard.loaderData);
|
|
905
|
+
* }
|
|
906
|
+
*
|
|
907
|
+
* @name unstable_useRoute
|
|
908
|
+
* @public
|
|
909
|
+
* @category Hooks
|
|
910
|
+
* @mode framework
|
|
911
|
+
* @mode data
|
|
912
|
+
* @param args An optional route ID. Omit it to read the current route.
|
|
913
|
+
* @returns An object with the route's `handle`, `loaderData`, and
|
|
914
|
+
* `actionData`, or `undefined` if the specified route is not matched.
|
|
915
|
+
* Individual fields can be `undefined` when the handle or data is unavailable.
|
|
916
|
+
*/
|
|
887
917
|
declare function useRoute<Args extends UseRouteArgs>(...args: Args): UseRouteResult<Args>;
|
|
888
918
|
/**
|
|
889
919
|
* A single route match returned from {@link unstable_useRouterState}. Mirrors
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -12,7 +12,7 @@ import { createPath, invariant, parsePath, warning } from "./router/history.js";
|
|
|
12
12
|
import { getNavigatorCurrentUrl, validateNavigationTarget } from "./router/navigation.js";
|
|
13
13
|
import { convertRouteMatchToUiMatch, decodePath, getResolveToMatches, getRoutePattern, isBrowser, isRouteErrorResponse, joinPaths, matchPath, matchRoutes, parseToInfo, resolveTo, stripBasename } from "./router/utils.js";
|
|
14
14
|
import { IDLE_BLOCKER, hasInvalidProtocol } from "./router/router.js";
|
|
15
|
-
import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
|
|
15
|
+
import { AwaitContext, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, IsDataRouteContext, LocationContext, NavigationContext, RSCErrorAlreadyReportedContext, RSCRouterContext, RouteContext, RouteErrorContext, RouteIdContext } from "./context.js";
|
|
16
16
|
import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "./errors.js";
|
|
17
17
|
import * as React$1 from "react";
|
|
18
18
|
//#region lib/hooks.tsx
|
|
@@ -626,6 +626,7 @@ function useRoutesImpl(routes, locationArg, dataRouterOpts) {
|
|
|
626
626
|
}
|
|
627
627
|
function DefaultErrorComponent() {
|
|
628
628
|
let error = useRouteError();
|
|
629
|
+
let alreadyReported = React$1.useContext(RSCErrorAlreadyReportedContext);
|
|
629
630
|
let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
|
|
630
631
|
let stack = error instanceof Error ? error.stack : null;
|
|
631
632
|
let lightgrey = "rgba(200,200,200, 0.5)";
|
|
@@ -638,7 +639,7 @@ function DefaultErrorComponent() {
|
|
|
638
639
|
backgroundColor: lightgrey
|
|
639
640
|
};
|
|
640
641
|
let devInfo = null;
|
|
641
|
-
console.error("Error handled by React Router default ErrorBoundary:", error);
|
|
642
|
+
if (!alreadyReported) console.error("Error handled by React Router default ErrorBoundary:", error);
|
|
642
643
|
devInfo = /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ React$1.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React$1.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React$1.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
|
|
643
644
|
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React$1.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React$1.createElement("pre", { style: preStyles }, stack) : null, devInfo);
|
|
644
645
|
}
|
|
@@ -1270,17 +1271,20 @@ function useBlocker(shouldBlock) {
|
|
|
1270
1271
|
});
|
|
1271
1272
|
}, [basename, shouldBlock]);
|
|
1272
1273
|
let activeBlockerKey = React$1.useRef("");
|
|
1274
|
+
let activeBlockerRouter = React$1.useRef(null);
|
|
1273
1275
|
React$1.useEffect(() => {
|
|
1274
1276
|
let key = String(++blockerId);
|
|
1275
1277
|
activeBlockerKey.current = key;
|
|
1278
|
+
activeBlockerRouter.current = router;
|
|
1276
1279
|
setBlockerKey(key);
|
|
1277
1280
|
return () => {
|
|
1278
1281
|
activeBlockerKey.current = "";
|
|
1282
|
+
activeBlockerRouter.current = null;
|
|
1279
1283
|
router.deleteBlocker(key);
|
|
1280
1284
|
};
|
|
1281
1285
|
}, [router]);
|
|
1282
|
-
React$1.
|
|
1283
|
-
if (blockerKey !== "" && blockerKey === activeBlockerKey.current) router.getBlocker(blockerKey, blockerFunction);
|
|
1286
|
+
React$1.useLayoutEffect(() => {
|
|
1287
|
+
if (blockerKey !== "" && blockerKey === activeBlockerKey.current && router === activeBlockerRouter.current) router.getBlocker(blockerKey, blockerFunction);
|
|
1284
1288
|
}, [
|
|
1285
1289
|
router,
|
|
1286
1290
|
blockerKey,
|
|
@@ -1312,6 +1316,36 @@ function warningOnce(key, cond, message) {
|
|
|
1312
1316
|
warning(false, message);
|
|
1313
1317
|
}
|
|
1314
1318
|
}
|
|
1319
|
+
/**
|
|
1320
|
+
* Returns the current route's `handle`, `loaderData`, and `actionData`, or
|
|
1321
|
+
* those of a matched route identified by `routeId`.
|
|
1322
|
+
*
|
|
1323
|
+
* Omit `routeId` to read the current route. Pass a route ID to infer the
|
|
1324
|
+
* fields from registered route module types. Without an ID, the fields
|
|
1325
|
+
* are typed as `unknown`.
|
|
1326
|
+
*
|
|
1327
|
+
* @example
|
|
1328
|
+
* import { unstable_useRoute as useRoute } from "react-router";
|
|
1329
|
+
*
|
|
1330
|
+
* let currentRoute = useRoute();
|
|
1331
|
+
* let rootRoute = useRoute("root");
|
|
1332
|
+
*
|
|
1333
|
+
* // A registered non-root route may not currently be matched:
|
|
1334
|
+
* let dashboard = useRoute("routes/dashboard");
|
|
1335
|
+
* if (dashboard) {
|
|
1336
|
+
* console.log(dashboard.handle, dashboard.loaderData);
|
|
1337
|
+
* }
|
|
1338
|
+
*
|
|
1339
|
+
* @name unstable_useRoute
|
|
1340
|
+
* @public
|
|
1341
|
+
* @category Hooks
|
|
1342
|
+
* @mode framework
|
|
1343
|
+
* @mode data
|
|
1344
|
+
* @param args An optional route ID. Omit it to read the current route.
|
|
1345
|
+
* @returns An object with the route's `handle`, `loaderData`, and
|
|
1346
|
+
* `actionData`, or `undefined` if the specified route is not matched.
|
|
1347
|
+
* Individual fields can be `undefined` when the handle or data is unavailable.
|
|
1348
|
+
*/
|
|
1315
1349
|
function useRoute(...args) {
|
|
1316
1350
|
const currentRouteId = useCurrentRouteId("useRoute");
|
|
1317
1351
|
const id = args[0] ?? currentRouteId;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -111,11 +111,12 @@ function createMemoryHistory(options = {}) {
|
|
|
111
111
|
action = "POP";
|
|
112
112
|
let nextIndex = clampIndex(index + delta);
|
|
113
113
|
let nextLocation = entries[nextIndex];
|
|
114
|
+
let actualDelta = nextIndex - index;
|
|
114
115
|
index = nextIndex;
|
|
115
116
|
if (listener) listener({
|
|
116
117
|
action,
|
|
117
118
|
location: nextLocation,
|
|
118
|
-
delta
|
|
119
|
+
delta: actualDelta
|
|
119
120
|
});
|
|
120
121
|
},
|
|
121
122
|
listen(fn) {
|
|
@@ -164,11 +165,16 @@ function createHashHistory(options = {}) {
|
|
|
164
165
|
function createHashLocation(window, globalHistory) {
|
|
165
166
|
let { pathname = "/", search = "", hash = "" } = parsePath(window.location.hash.substring(1));
|
|
166
167
|
if (!pathname.startsWith("/") && !pathname.startsWith(".")) pathname = "/" + pathname;
|
|
167
|
-
|
|
168
|
+
let maskedLocation = globalHistory.state?.masked;
|
|
169
|
+
return createLocation("", maskedLocation || {
|
|
168
170
|
pathname,
|
|
169
171
|
search,
|
|
170
172
|
hash
|
|
171
|
-
}, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default"
|
|
173
|
+
}, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default", maskedLocation ? {
|
|
174
|
+
pathname,
|
|
175
|
+
search,
|
|
176
|
+
hash
|
|
177
|
+
} : void 0);
|
|
172
178
|
}
|
|
173
179
|
function createHashHref(window, to) {
|
|
174
180
|
let base = window.document.querySelector("base");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -213,6 +213,7 @@ function createRouter(init) {
|
|
|
213
213
|
blockers: /* @__PURE__ */ new Map()
|
|
214
214
|
};
|
|
215
215
|
let pendingAction = "POP";
|
|
216
|
+
let pendingActionData;
|
|
216
217
|
let pendingPopstateDelta = 0;
|
|
217
218
|
let pendingDiscoveryCancellation;
|
|
218
219
|
let pendingPopstateNavigationDfd = null;
|
|
@@ -227,6 +228,7 @@ function createRouter(init) {
|
|
|
227
228
|
let fetchControllers = /* @__PURE__ */ new Map();
|
|
228
229
|
let incrementingLoadId = 0;
|
|
229
230
|
let pendingNavigationLoadId = -1;
|
|
231
|
+
let pendingNavigationDiscoverySignal = null;
|
|
230
232
|
let fetchReloadIds = /* @__PURE__ */ new Map();
|
|
231
233
|
let fetchRedirectIds = /* @__PURE__ */ new Set();
|
|
232
234
|
let fetchLoadMatches = /* @__PURE__ */ new Map();
|
|
@@ -340,10 +342,10 @@ function createRouter(init) {
|
|
|
340
342
|
}
|
|
341
343
|
function completeNavigation(location, newState, { flushSync } = {}) {
|
|
342
344
|
let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && location.state?._isRedirect !== true;
|
|
345
|
+
let actionDataForCommit = newState.actionData || (isActionReload ? pendingActionData : void 0);
|
|
343
346
|
let actionData;
|
|
344
|
-
if (
|
|
347
|
+
if (actionDataForCommit) if (Object.keys(actionDataForCommit).length > 0) actionData = actionDataForCommit;
|
|
345
348
|
else actionData = null;
|
|
346
|
-
else if (isActionReload) actionData = state.actionData;
|
|
347
349
|
else actionData = null;
|
|
348
350
|
let loaderData = newState.loaderData ? mergeLoaderData(state.loaderData, newState.loaderData, newState.matches || [], newState.errors) : state.loaderData;
|
|
349
351
|
let blockers = state.blockers;
|
|
@@ -405,6 +407,7 @@ function createRouter(init) {
|
|
|
405
407
|
function resetPendingNavigation() {
|
|
406
408
|
pendingPopstateDelta = 0;
|
|
407
409
|
pendingAction = "POP";
|
|
410
|
+
pendingActionData = void 0;
|
|
408
411
|
pendingPreventScrollReset = false;
|
|
409
412
|
pendingViewTransitionEnabled = false;
|
|
410
413
|
isUninterruptedRevalidation = false;
|
|
@@ -514,6 +517,7 @@ function createRouter(init) {
|
|
|
514
517
|
pendingNavigationController && pendingNavigationController.abort();
|
|
515
518
|
pendingNavigationController = null;
|
|
516
519
|
pendingAction = historyAction;
|
|
520
|
+
if (!opts?.overrideNavigation) pendingActionData = void 0;
|
|
517
521
|
isUninterruptedRevalidation = (opts && opts.startUninterruptedRevalidation) === true;
|
|
518
522
|
saveScrollPosition(state.location, state.matches);
|
|
519
523
|
pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
@@ -579,6 +583,7 @@ function createRouter(init) {
|
|
|
579
583
|
fogOfWar.active = false;
|
|
580
584
|
request = createClientSideRequest(init.history, request.url, request.signal);
|
|
581
585
|
}
|
|
586
|
+
if (pendingActionResult) pendingActionData = getActionDataForCommit(pendingActionResult).actionData;
|
|
582
587
|
let { shortCircuited, matches: updatedMatches, loaderData, errors, workingFetchers } = await handleLoaders(request, dataStrategyInitiator, location, matches, historyAction, scopedContext, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult, opts && opts.callSiteDefaultShouldRevalidate);
|
|
583
588
|
if (shortCircuited) return;
|
|
584
589
|
pendingNavigationController = null;
|
|
@@ -724,6 +729,7 @@ function createRouter(init) {
|
|
|
724
729
|
let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
|
725
730
|
let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
|
|
726
731
|
if (isFogOfWar) {
|
|
732
|
+
pendingNavigationDiscoverySignal = request.signal;
|
|
727
733
|
if (shouldUpdateNavigationState) {
|
|
728
734
|
let actionData = getUpdatedActionData(pendingActionResult);
|
|
729
735
|
updateState({
|
|
@@ -732,6 +738,7 @@ function createRouter(init) {
|
|
|
732
738
|
}, { flushSync });
|
|
733
739
|
}
|
|
734
740
|
let discoverResult = await discoverRoutes(matches, location.pathname, request.signal);
|
|
741
|
+
if (pendingNavigationDiscoverySignal === request.signal) pendingNavigationDiscoverySignal = null;
|
|
735
742
|
if (future.unstable_customRouteDiscovery && request.signal.aborted || discoverResult.type === "aborted") return { shortCircuited: true };
|
|
736
743
|
else if (discoverResult.type === "cancelled") {
|
|
737
744
|
await cancelDiscoveryNavigation();
|
|
@@ -833,7 +840,10 @@ function createRouter(init) {
|
|
|
833
840
|
};
|
|
834
841
|
}
|
|
835
842
|
function getUpdatedActionData(pendingActionResult) {
|
|
836
|
-
if (pendingActionResult && !isErrorResult(pendingActionResult[1])) return {
|
|
843
|
+
if (pendingActionResult && !isErrorResult(pendingActionResult[1])) return {
|
|
844
|
+
...state.actionData,
|
|
845
|
+
[pendingActionResult[0]]: pendingActionResult[1].data
|
|
846
|
+
};
|
|
837
847
|
else if (state.actionData) if (Object.keys(state.actionData).length === 0) return null;
|
|
838
848
|
else return state.actionData;
|
|
839
849
|
}
|
|
@@ -880,6 +890,9 @@ function createRouter(init) {
|
|
|
880
890
|
fetchLoadMatches.set(key, loadMatch);
|
|
881
891
|
await handleFetcherLoader(key, loadMatch, matches, scopedContext, flushSync, preventScrollReset, submission);
|
|
882
892
|
}
|
|
893
|
+
function isNavigationAwaitingDiscovery() {
|
|
894
|
+
return pendingNavigationDiscoverySignal?.aborted === false;
|
|
895
|
+
}
|
|
883
896
|
async function handleFetcherAction(key, routeId, path, requestMatches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission, callSiteDefaultShouldRevalidate) {
|
|
884
897
|
if (!future.unstable_customRouteDiscovery) interruptActiveLoads();
|
|
885
898
|
fetchLoadMatches.delete(key);
|
|
@@ -963,9 +976,10 @@ function createRouter(init) {
|
|
|
963
976
|
}
|
|
964
977
|
}
|
|
965
978
|
isRevalidationRequired = true;
|
|
966
|
-
let
|
|
979
|
+
let revalidationLocation = !isNavigationAwaitingDiscovery() ? state.navigation.location : void 0;
|
|
980
|
+
let nextLocation = revalidationLocation || state.location;
|
|
967
981
|
let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal);
|
|
968
|
-
let matches =
|
|
982
|
+
let matches = revalidationLocation ? dataRouteMatcher.match(revalidationLocation) : state.matches;
|
|
969
983
|
invariant(matches, "Didn't find any matches after fetcher action");
|
|
970
984
|
let loadId = ++incrementingLoadId;
|
|
971
985
|
fetchReloadIds.set(key, loadId);
|
|
@@ -1022,7 +1036,7 @@ function createRouter(init) {
|
|
|
1022
1036
|
if (fetcherIsMounted) finalFetchers.set(key, getDoneFetcher(actionResult.data));
|
|
1023
1037
|
let { loaderData, errors } = processLoaderData(state, matches, loaderResults, void 0, revalidatingFetchers, fetcherResults, finalFetchers);
|
|
1024
1038
|
abortStaleFetchLoads(loadId, finalFetchers);
|
|
1025
|
-
if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
|
|
1039
|
+
if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId && !isNavigationAwaitingDiscovery()) {
|
|
1026
1040
|
invariant(pendingAction, "Expected pending action");
|
|
1027
1041
|
pendingNavigationController && pendingNavigationController.abort();
|
|
1028
1042
|
markFetchRedirectsDone(finalFetchers);
|
|
@@ -1035,7 +1049,7 @@ function createRouter(init) {
|
|
|
1035
1049
|
} else {
|
|
1036
1050
|
updateState({
|
|
1037
1051
|
errors,
|
|
1038
|
-
loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
|
|
1052
|
+
loaderData: mergeLoaderData(state.loaderData, loaderData, state.matches, errors),
|
|
1039
1053
|
fetchers: finalFetchers
|
|
1040
1054
|
});
|
|
1041
1055
|
isRevalidationRequired = fetchReloadIds.size > 0;
|
|
@@ -788,6 +788,8 @@ interface PathMatch<ParamKey extends string = string> {
|
|
|
788
788
|
* Performs pattern matching on a URL pathname and returns information about
|
|
789
789
|
* the match.
|
|
790
790
|
*
|
|
791
|
+
* Throws if the pattern contains more than 12 optional (`?`) markers.
|
|
792
|
+
*
|
|
791
793
|
* @public
|
|
792
794
|
* @category Utils
|
|
793
795
|
* @param pattern The pattern to match against the URL pathname. This can be a
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -470,10 +470,13 @@ function generatePath(originalPath, params = {}) {
|
|
|
470
470
|
validateDocumentNavigationTarget(result);
|
|
471
471
|
return result;
|
|
472
472
|
}
|
|
473
|
+
const MAX_OPTIONAL_PATH_SEGMENTS = 12;
|
|
473
474
|
/**
|
|
474
475
|
* Performs pattern matching on a URL pathname and returns information about
|
|
475
476
|
* the match.
|
|
476
477
|
*
|
|
478
|
+
* Throws if the pattern contains more than 12 optional (`?`) markers.
|
|
479
|
+
*
|
|
477
480
|
* @public
|
|
478
481
|
* @category Utils
|
|
479
482
|
* @param pattern The pattern to match against the URL pathname. This can be a
|
|
@@ -490,7 +493,10 @@ function matchPath(pattern, pathname) {
|
|
|
490
493
|
caseSensitive: false,
|
|
491
494
|
end: true
|
|
492
495
|
};
|
|
493
|
-
let
|
|
496
|
+
let { path } = pattern;
|
|
497
|
+
let optionalSegments = 0;
|
|
498
|
+
for (let index = path.indexOf("?"); index !== -1; index = path.indexOf("?", index + 1)) if (++optionalSegments > MAX_OPTIONAL_PATH_SEGMENTS) throw new Error(`Path pattern ${JSON.stringify(path)} exceeds the limit of ${MAX_OPTIONAL_PATH_SEGMENTS} optional segments.`);
|
|
499
|
+
let [matcher, compiledParams] = compilePath(path, pattern.caseSensitive, pattern.end);
|
|
494
500
|
return matchPathImpl(pattern, pathname, matcher, compiledParams);
|
|
495
501
|
}
|
|
496
502
|
function matchPathImpl(pattern, pathname, matcher, compiledParams) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -583,13 +583,13 @@ async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fet
|
|
|
583
583
|
if (!response.body || response.status < 200 || response.status >= 300) throw new Error("Unable to fetch new route matches from the server");
|
|
584
584
|
let payload = await createFromReadableStream(response.body, { temporaryReferences: void 0 });
|
|
585
585
|
if (payload.type !== "manifest") throw new Error("Failed to patch routes");
|
|
586
|
-
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
587
586
|
let patches = await payload.patches;
|
|
588
587
|
React$1.startTransition(() => {
|
|
589
588
|
patches.forEach((p) => {
|
|
590
589
|
window.__reactRouterDataRouter.patchRoutes(p.parentId ?? null, [createRouteFromServerManifest(p)]);
|
|
591
590
|
});
|
|
592
591
|
});
|
|
592
|
+
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
593
593
|
}
|
|
594
594
|
function addToFifoQueue(path, queue) {
|
|
595
595
|
if (queue.size >= discoveredPathsMaxSize) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import { isRouteErrorResponse } from "../router/utils.js";
|
|
12
|
+
import { RSCErrorAlreadyReportedContext } from "../context.js";
|
|
12
13
|
import { useRouteError } from "../hooks.js";
|
|
13
14
|
import React from "react";
|
|
14
15
|
//#region lib/rsc/errorBoundaries.tsx
|
|
@@ -52,7 +53,7 @@ function ErrorWrapper({ renderAppShell, title, children }) {
|
|
|
52
53
|
} }, children)));
|
|
53
54
|
}
|
|
54
55
|
function RSCDefaultRootErrorBoundaryImpl({ error, renderAppShell }) {
|
|
55
|
-
console.error(error);
|
|
56
|
+
if (!React.useContext(RSCErrorAlreadyReportedContext)) console.error(error);
|
|
56
57
|
let heyDeveloper = /* @__PURE__ */ React.createElement("script", { dangerouslySetInnerHTML: { __html: `
|
|
57
58
|
console.log(
|
|
58
59
|
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
|
|
@@ -181,7 +181,8 @@ type RouteDiscovery = {
|
|
|
181
181
|
* @param opts.clientVersion A version derived from the client build output used
|
|
182
182
|
* to detect stale clients during lazy route discovery.
|
|
183
183
|
* @param opts.onError An optional error handler that will be called with any
|
|
184
|
-
* errors that occur during the request processing.
|
|
184
|
+
* errors that occur during the request processing. Defaults to logging errors
|
|
185
|
+
* with `console.error` unless the request was aborted.
|
|
185
186
|
* @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
186
187
|
* to match against.
|
|
187
188
|
* @param opts.requestContext An instance of {@link RouterContextProvider}
|
|
@@ -5,6 +5,7 @@ import * as React$1 from "react";
|
|
|
5
5
|
//#region lib/rsc/server.ssr.d.ts
|
|
6
6
|
type DecodedPayload = Promise<RSCPayload> & {
|
|
7
7
|
_deepestRenderedBoundaryId?: string | null;
|
|
8
|
+
_isErrorRender?: boolean;
|
|
8
9
|
formState: Promise<any>;
|
|
9
10
|
};
|
|
10
11
|
type SSRCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.3
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { isRouteErrorResponse } from "../router/utils.js";
|
|
12
12
|
import { createDataRouteMatcher, hasInvalidProtocol } from "../router/router.js";
|
|
13
|
-
import { RSCRouterContext } from "../context.js";
|
|
13
|
+
import { RSCErrorAlreadyReportedContext, RSCRouterContext } from "../context.js";
|
|
14
14
|
import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "../errors.js";
|
|
15
15
|
import { escapeAttribute } from "../dom/ssr/markup.js";
|
|
16
16
|
import { shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
|
|
@@ -214,6 +214,7 @@ async function routeRSCServerRequest({ request, serverResponse, createFromReadab
|
|
|
214
214
|
errors: deepestRenderedBoundaryId ? { [deepestRenderedBoundaryId]: normalizedError } : {}
|
|
215
215
|
}));
|
|
216
216
|
return Object.defineProperties(payloadPromise, {
|
|
217
|
+
_isErrorRender: { value: true },
|
|
217
218
|
_deepestRenderedBoundaryId: {
|
|
218
219
|
get() {
|
|
219
220
|
return deepestRenderedBoundaryId;
|
|
@@ -407,11 +408,11 @@ function RSCStaticRouter({ getPayload, nonce }) {
|
|
|
407
408
|
routeModules: createRSCRouteModules(payload),
|
|
408
409
|
nonce
|
|
409
410
|
};
|
|
410
|
-
return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
|
|
411
|
+
return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(RSCErrorAlreadyReportedContext.Provider, { value: payload.errors != null && !decoded._isErrorRender }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
|
|
411
412
|
context,
|
|
412
413
|
router,
|
|
413
414
|
hydrate: false
|
|
414
|
-
}))));
|
|
415
|
+
})))));
|
|
415
416
|
}
|
|
416
417
|
function isReactServerRequest(url) {
|
|
417
418
|
return url.pathname.endsWith(".rsc");
|