react-router 8.0.1 → 8.2.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 +24 -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 +35 -9
- package/dist/development/index-react-server.js +190 -157
- package/dist/development/index.d.ts +2 -2
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/components.js +1 -1
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.js +1 -1
- package/dist/development/lib/dom/lib.js +2 -2
- package/dist/development/lib/dom/server.js +1 -1
- package/dist/development/lib/dom/ssr/components.js +1 -1
- package/dist/development/lib/dom/ssr/data.js +1 -1
- 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 +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/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 +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 +33 -6
- package/dist/development/lib/hooks.js +34 -7
- package/dist/development/lib/href.js +6 -3
- package/dist/development/lib/router/history.js +1 -1
- package/dist/development/lib/router/instrumentation.d.ts +33 -8
- package/dist/development/lib/router/instrumentation.js +176 -99
- package/dist/development/lib/router/router.js +20 -20
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.js +21 -4
- package/dist/development/lib/rsc/browser.js +1 -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 +1 -1
- 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/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 +12 -5
- 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/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.js +1 -1
- package/dist/production/index-react-server-client.js +1 -1
- package/dist/production/index-react-server.d.ts +35 -9
- package/dist/production/index-react-server.js +190 -157
- package/dist/production/index.d.ts +2 -2
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/components.js +1 -1
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.js +1 -1
- package/dist/production/lib/dom/lib.js +2 -2
- package/dist/production/lib/dom/server.js +1 -1
- package/dist/production/lib/dom/ssr/components.js +1 -1
- package/dist/production/lib/dom/ssr/data.js +1 -1
- 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 +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/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 +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 +33 -6
- package/dist/production/lib/hooks.js +34 -7
- package/dist/production/lib/href.js +6 -3
- package/dist/production/lib/router/history.js +1 -1
- package/dist/production/lib/router/instrumentation.d.ts +33 -8
- package/dist/production/lib/router/instrumentation.js +176 -99
- package/dist/production/lib/router/router.js +20 -20
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.js +21 -4
- package/dist/production/lib/rsc/browser.js +1 -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 +1 -1
- 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/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 +12 -5
- 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/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/hot-module-replacement.md +1 -1
- package/docs/how-to/data-strategy.md +1 -1
- package/docs/how-to/instrumentation.md +131 -26
- package/docs/start/framework/deploying.md +4 -0
- package/docs/upgrading/component-routes.md +2 -2
- package/docs/upgrading/future.md +33 -0
- package/docs/upgrading/router-provider.md +6 -6
- package/docs/upgrading/v7.md +39 -22
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.0
|
|
2
|
+
* react-router v8.2.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
|
|
12
12
|
import { createBrowserURLImpl, createLocation, createPath, invariant, parsePath, warning } from "./history.js";
|
|
13
|
-
import { ErrorResponseImpl, RouterContextProvider, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, flattenAndRankRoutes, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, matchRoutesImpl, prependBasename, removeDoubleSlashes, resolveTo, stripBasename } from "./utils.js";
|
|
14
|
-
import { getRouteInstrumentationUpdates, instrumentClientSideRouter } from "./instrumentation.js";
|
|
13
|
+
import { ErrorResponseImpl, RouterContextProvider, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createDataFunctionUrl, flattenAndRankRoutes, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, matchRoutesImpl, prependBasename, removeDoubleSlashes, resolveTo, stripBasename } from "./utils.js";
|
|
14
|
+
import { consumeInstrumentationClientResultMetaReceiver, getRouteInstrumentationUpdates, instrumentClientSideRouter } from "./instrumentation.js";
|
|
15
15
|
//#region lib/router/router.ts
|
|
16
16
|
const validMutationMethodsArr = [
|
|
17
17
|
"POST",
|
|
@@ -341,7 +341,7 @@ function createRouter(init) {
|
|
|
341
341
|
else actionData = null;
|
|
342
342
|
let loaderData = newState.loaderData ? mergeLoaderData(state.loaderData, newState.loaderData, newState.matches || [], newState.errors) : state.loaderData;
|
|
343
343
|
let blockers = state.blockers;
|
|
344
|
-
if (blockers.size > 0) {
|
|
344
|
+
if (blockers.size > 0 && !isUninterruptedRevalidation) {
|
|
345
345
|
blockers = new Map(blockers);
|
|
346
346
|
blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER));
|
|
347
347
|
}
|
|
@@ -409,6 +409,7 @@ function createRouter(init) {
|
|
|
409
409
|
init.history.go(to);
|
|
410
410
|
return promise;
|
|
411
411
|
}
|
|
412
|
+
let instrumentationNavigateMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
|
|
412
413
|
let { path, submission, error } = normalizeNavigateOptions(false, normalizeTo(state.location, state.matches, basename, to, opts?.fromRouteId, opts?.relative), opts);
|
|
413
414
|
let maskPath;
|
|
414
415
|
if (opts?.mask) maskPath = {
|
|
@@ -465,7 +466,8 @@ function createRouter(init) {
|
|
|
465
466
|
replace: opts && opts.replace,
|
|
466
467
|
enableViewTransition: opts && opts.viewTransition,
|
|
467
468
|
flushSync,
|
|
468
|
-
callSiteDefaultShouldRevalidate: opts && opts.defaultShouldRevalidate
|
|
469
|
+
callSiteDefaultShouldRevalidate: opts && opts.defaultShouldRevalidate,
|
|
470
|
+
instrumentationNavigateMetaReceiver
|
|
469
471
|
});
|
|
470
472
|
}
|
|
471
473
|
function revalidate() {
|
|
@@ -501,6 +503,10 @@ function createRouter(init) {
|
|
|
501
503
|
}
|
|
502
504
|
let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
|
503
505
|
if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
|
|
506
|
+
if (opts?.instrumentationNavigateMetaReceiver) {
|
|
507
|
+
let meta = getInstrumentationNavigateMeta(init.history, location, matches);
|
|
508
|
+
opts.instrumentationNavigateMetaReceiver(meta);
|
|
509
|
+
}
|
|
504
510
|
if (!matches) {
|
|
505
511
|
let { error, notFoundMatches, route } = handleNavigational404(location.pathname);
|
|
506
512
|
completeNavigation(location, {
|
|
@@ -760,11 +766,13 @@ function createRouter(init) {
|
|
|
760
766
|
async function fetch(key, routeId, href, opts) {
|
|
761
767
|
abortFetcher(key);
|
|
762
768
|
let flushSync = (opts && opts.flushSync) === true;
|
|
769
|
+
let instrumentationResultMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
|
|
763
770
|
let routesToUse = dataRoutes.activeRoutes;
|
|
764
771
|
let normalizedPath = normalizeTo(state.location, state.matches, basename, href, routeId, opts?.relative);
|
|
765
772
|
let matches = matchRoutesImpl(routesToUse, normalizedPath, basename, false, dataRoutes.branches);
|
|
766
773
|
let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath);
|
|
767
774
|
if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
|
|
775
|
+
if (instrumentationResultMetaReceiver) instrumentationResultMetaReceiver(getInstrumentationNavigateMeta(init.history, normalizedPath, matches));
|
|
768
776
|
if (!matches) {
|
|
769
777
|
setFetcherError(key, routeId, getInternalRouterError(404, { pathname: normalizedPath }), { flushSync });
|
|
770
778
|
return;
|
|
@@ -2608,21 +2616,6 @@ function createClientSideRequest(history, location, signal, submission) {
|
|
|
2608
2616
|
}
|
|
2609
2617
|
return new Request(url, init);
|
|
2610
2618
|
}
|
|
2611
|
-
function createDataFunctionUrl(request, path) {
|
|
2612
|
-
let url = new URL(request.url);
|
|
2613
|
-
let parsed = typeof path === "string" ? parsePath(path) : path;
|
|
2614
|
-
url.pathname = parsed.pathname || "/";
|
|
2615
|
-
if (parsed.search) {
|
|
2616
|
-
let searchParams = new URLSearchParams(parsed.search);
|
|
2617
|
-
let indexValues = searchParams.getAll("index");
|
|
2618
|
-
searchParams.delete("index");
|
|
2619
|
-
for (let value of indexValues.filter(Boolean)) searchParams.append("index", value);
|
|
2620
|
-
let search = searchParams.toString();
|
|
2621
|
-
url.search = search ? `?${search}` : "";
|
|
2622
|
-
} else url.search = "";
|
|
2623
|
-
url.hash = parsed.hash || "";
|
|
2624
|
-
return url;
|
|
2625
|
-
}
|
|
2626
2619
|
function convertFormDataToSearchParams(formData) {
|
|
2627
2620
|
let searchParams = new URLSearchParams();
|
|
2628
2621
|
for (let [key, value] of formData.entries()) searchParams.append(key, typeof value === "string" ? value : value.name);
|
|
@@ -2827,6 +2820,13 @@ function getTargetMatch(matches, location) {
|
|
|
2827
2820
|
let pathMatches = getPathContributingMatches(matches);
|
|
2828
2821
|
return pathMatches[pathMatches.length - 1];
|
|
2829
2822
|
}
|
|
2823
|
+
function getInstrumentationNavigateMeta(history, location, matches) {
|
|
2824
|
+
return {
|
|
2825
|
+
url: createDataFunctionUrl(history.createURL(location), location),
|
|
2826
|
+
pattern: matches ? getRoutePattern(matches) : "",
|
|
2827
|
+
params: matches?.[0]?.params ? { ...matches[0].params } : {}
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2830
2830
|
function getSubmissionFromNavigation(navigation) {
|
|
2831
2831
|
let { formMethod, formAction, formEncType, text, formData, json } = navigation;
|
|
2832
2832
|
if (!formMethod || !formAction || !formEncType) return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.0
|
|
2
|
+
* react-router v8.2.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -314,6 +314,8 @@ function rankRouteBranches(branches) {
|
|
|
314
314
|
branches.sort((a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(a.routesMeta.map((meta) => meta.childrenIndex), b.routesMeta.map((meta) => meta.childrenIndex)));
|
|
315
315
|
}
|
|
316
316
|
const paramRe = /^:[\w-]+$/;
|
|
317
|
+
const partialParamRe = /^:[\w-]+/;
|
|
318
|
+
const partialDynamicSegmentValue = 3.5;
|
|
317
319
|
const dynamicSegmentValue = 3;
|
|
318
320
|
const indexRouteValue = 2;
|
|
319
321
|
const emptySegmentValue = 1;
|
|
@@ -325,7 +327,7 @@ function computeScore(path, index) {
|
|
|
325
327
|
let initialScore = segments.length;
|
|
326
328
|
if (segments.some(isSplat)) initialScore += splatPenalty;
|
|
327
329
|
if (index) initialScore += indexRouteValue;
|
|
328
|
-
return segments.filter((s) => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
|
|
330
|
+
return segments.filter((s) => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : partialParamRe.test(segment) ? partialDynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
|
|
329
331
|
}
|
|
330
332
|
function compareIndexes(a, b) {
|
|
331
333
|
return a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]) ? a[a.length - 1] - b[b.length - 1] : 0;
|
|
@@ -456,7 +458,7 @@ function compilePath(path, caseSensitive = false, end = true) {
|
|
|
456
458
|
return "(?:/([^\\/]*))?";
|
|
457
459
|
}
|
|
458
460
|
return "/([^\\/]+)";
|
|
459
|
-
}).replace(/\/([\w-]+)\?(
|
|
461
|
+
}).replace(/\/([\w-]+)\?(?=\/|$|\()/g, "(?:/$1)?");
|
|
460
462
|
if (path.endsWith("*")) {
|
|
461
463
|
params.push({ paramName: "*" });
|
|
462
464
|
regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
|
@@ -772,6 +774,21 @@ function isRouteErrorResponse(error) {
|
|
|
772
774
|
function getRoutePattern(matches) {
|
|
773
775
|
return joinPaths(matches.map((m) => m.route.path).filter(Boolean)) || "/";
|
|
774
776
|
}
|
|
777
|
+
function createDataFunctionUrl(request, path) {
|
|
778
|
+
let url = new URL(typeof request === "string" || request instanceof URL ? request : request.url);
|
|
779
|
+
let parsed = typeof path === "string" ? parsePath(path) : path;
|
|
780
|
+
url.pathname = parsed.pathname || "/";
|
|
781
|
+
if (parsed.search) {
|
|
782
|
+
let searchParams = new URLSearchParams(parsed.search);
|
|
783
|
+
let indexValues = searchParams.getAll("index");
|
|
784
|
+
searchParams.delete("index");
|
|
785
|
+
for (let value of indexValues.filter(Boolean)) searchParams.append("index", value);
|
|
786
|
+
let search = searchParams.toString();
|
|
787
|
+
url.search = search ? `?${search}` : "";
|
|
788
|
+
} else url.search = "";
|
|
789
|
+
url.hash = parsed.hash || "";
|
|
790
|
+
return url;
|
|
791
|
+
}
|
|
775
792
|
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
776
793
|
function parseToInfo(_to, basename) {
|
|
777
794
|
let to = _to;
|
|
@@ -798,4 +815,4 @@ function parseToInfo(_to, basename) {
|
|
|
798
815
|
};
|
|
799
816
|
}
|
|
800
817
|
//#endregion
|
|
801
|
-
export { ErrorResponseImpl, RouterContextProvider, SUPPORTED_ERROR_TYPES, compilePath, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createContext, data, decodePath, defaultMapRouteProperties, flattenAndRankRoutes, generatePath, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isBrowser, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, joinPaths, matchPath, matchRoutes, matchRoutesImpl, parseToInfo, prependBasename, redirect, redirectDocument, removeDoubleSlashes, removeTrailingSlash, replace, resolvePath, resolveTo, stripBasename };
|
|
818
|
+
export { ErrorResponseImpl, RouterContextProvider, SUPPORTED_ERROR_TYPES, compilePath, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createContext, createDataFunctionUrl, data, decodePath, defaultMapRouteProperties, flattenAndRankRoutes, generatePath, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isBrowser, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, joinPaths, matchPath, matchRoutes, matchRoutesImpl, parseToInfo, prependBasename, redirect, redirectDocument, removeDoubleSlashes, removeTrailingSlash, replace, resolvePath, resolveTo, stripBasename };
|
|
@@ -3,6 +3,7 @@ import { Location } from "../router/history.js";
|
|
|
3
3
|
import { ActionFunction, LoaderFunction, Params, RouterContextProvider, ShouldRevalidateFunction } from "../router/utils.js";
|
|
4
4
|
import { ClientActionFunction, ClientLoaderFunction, HeadersFunction, LinksFunction, MetaFunction } from "../dom/ssr/routeModules.js";
|
|
5
5
|
import * as React$1 from "react";
|
|
6
|
+
import { ReactFormState } from "react-dom/client";
|
|
6
7
|
|
|
7
8
|
//#region lib/rsc/server.rsc.d.ts
|
|
8
9
|
declare function getRequest(): Request;
|
|
@@ -71,7 +72,7 @@ type RSCRenderPayload = {
|
|
|
71
72
|
matches: RSCRouteMatch[];
|
|
72
73
|
patches?: Promise<RSCRouteManifest[]>;
|
|
73
74
|
nonce?: string;
|
|
74
|
-
formState?:
|
|
75
|
+
formState?: ReactFormState;
|
|
75
76
|
};
|
|
76
77
|
type RSCManifestPayload = {
|
|
77
78
|
type: "manifest";
|
|
@@ -97,7 +98,7 @@ type RSCMatch = {
|
|
|
97
98
|
payload: RSCPayload;
|
|
98
99
|
};
|
|
99
100
|
type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
|
|
100
|
-
type DecodeFormStateFunction = (result: unknown, formData: FormData) =>
|
|
101
|
+
type DecodeFormStateFunction = (result: unknown, formData: FormData) => Promise<ReactFormState | undefined>;
|
|
101
102
|
type DecodeReplyFunction = (reply: FormData | string, options: {
|
|
102
103
|
temporaryReferences: unknown;
|
|
103
104
|
}) => Promise<unknown[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.0
|
|
2
|
+
* react-router v8.2.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { ErrorResponseImpl, RouterContextProvider, defaultMapRouteProperties, isRouteErrorResponse, removeTrailingSlash, stripBasename } from "../router/utils.js";
|
|
12
|
-
import { instrumentHandler } from "../router/instrumentation.js";
|
|
11
|
+
import { ErrorResponseImpl, RouterContextProvider, createDataFunctionUrl, defaultMapRouteProperties, getRoutePattern, isRouteErrorResponse, removeTrailingSlash, stripBasename } from "../router/utils.js";
|
|
12
|
+
import { instrumentHandler, instrumentationResultMetaContext } from "../router/instrumentation.js";
|
|
13
13
|
import { createStaticHandler, getStaticContextFromError, isMutationMethod, isRedirectResponse, isResponse } from "../router/router.js";
|
|
14
14
|
import { getManifestPath } from "../dom/ssr/fog-of-war.js";
|
|
15
15
|
import { createEntryRouteModules } from "./entry.js";
|
|
@@ -36,6 +36,7 @@ function derive(build, mode) {
|
|
|
36
36
|
let errorHandler = build.entry.module.handleError || ((error, { request }) => {
|
|
37
37
|
if (serverMode !== "test" && !request.signal.aborted) console.error(isRouteErrorResponse(error) && error.error ? error.error : error);
|
|
38
38
|
});
|
|
39
|
+
let requestHandlerInstrumentations = build.entry.module.instrumentations?.map((i) => i.handler).filter(Boolean);
|
|
39
40
|
let requestHandler = async (request, initialContext) => {
|
|
40
41
|
let params = {};
|
|
41
42
|
let loadContext;
|
|
@@ -54,7 +55,8 @@ function derive(build, mode) {
|
|
|
54
55
|
}
|
|
55
56
|
loadContext = initialContext || new RouterContextProvider();
|
|
56
57
|
let requestUrl = new URL(request.url);
|
|
57
|
-
let
|
|
58
|
+
let normalizedPath = getNormalizedPath(request);
|
|
59
|
+
let normalizedPathname = normalizedPath.pathname;
|
|
58
60
|
let isSpaMode = getBuildTimeHeader(request, "X-React-Router-SPA-Mode") === "yes";
|
|
59
61
|
if (!build.ssr) {
|
|
60
62
|
let decodedPath = decodeURI(normalizedPathname);
|
|
@@ -95,6 +97,11 @@ function derive(build, mode) {
|
|
|
95
97
|
}
|
|
96
98
|
let matches = matchServerRoutes(build.routes, staticHandler.dataRoutes, staticHandler._internalRouteBranches, normalizedPathname, build.basename);
|
|
97
99
|
if (matches && matches.length > 0) Object.assign(params, matches[0].params);
|
|
100
|
+
if (requestHandlerInstrumentations?.length) loadContext.set(instrumentationResultMetaContext, {
|
|
101
|
+
url: createDataFunctionUrl(request, normalizedPath),
|
|
102
|
+
pattern: matches ? getRoutePattern(matches) : "",
|
|
103
|
+
params: matches?.[0]?.params ? { ...matches[0].params } : {}
|
|
104
|
+
});
|
|
98
105
|
let response;
|
|
99
106
|
if (requestUrl.pathname.endsWith(".data")) {
|
|
100
107
|
response = await handleSingleFetchRequest(serverMode, build, staticHandler, request, loadContext, handleError);
|
|
@@ -122,7 +129,7 @@ function derive(build, mode) {
|
|
|
122
129
|
});
|
|
123
130
|
return response;
|
|
124
131
|
};
|
|
125
|
-
if (
|
|
132
|
+
if (requestHandlerInstrumentations?.length) requestHandler = instrumentHandler(requestHandler, requestHandlerInstrumentations);
|
|
126
133
|
return {
|
|
127
134
|
serverMode,
|
|
128
135
|
staticHandler,
|
|
@@ -111,7 +111,7 @@ export default function Component({ loaderData }) {
|
|
|
111
111
|
|
|
112
112
|
If you change the key `pet` to `dog`:
|
|
113
113
|
|
|
114
|
-
```diff
|
|
114
|
+
```tsx diff
|
|
115
115
|
export default function Component() {
|
|
116
116
|
- const { pet } = useMyCustomHook();
|
|
117
117
|
+ const { dog } = useMyCustomHook();
|
|
@@ -166,7 +166,7 @@ With `shouldCallHandler`, you are in charge of which handlers should be called s
|
|
|
166
166
|
|
|
167
167
|
Here's an example change from the prior API to the new API. Note that we pre-filter the `matchesToLoad` before calling `resolve()`:
|
|
168
168
|
|
|
169
|
-
```diff
|
|
169
|
+
```tsx diff
|
|
170
170
|
let results = {};
|
|
171
171
|
+let matchesToLoad = matches.filter(m => m.shouldCallHandler());
|
|
172
172
|
await Promise.all(() =>
|