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
|
@@ -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
|
*
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import { ABSOLUTE_URL_REGEX } from "../router/url.js";
|
|
12
|
-
import { createPath, invariant, parsePath } from "../router/history.js";
|
|
12
|
+
import { createPath, invariant, parsePath, warning } from "../router/history.js";
|
|
13
13
|
import { convertRoutesToDataRoutes, isRouteErrorResponse } from "../router/utils.js";
|
|
14
14
|
import { IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION } from "../router/router.js";
|
|
15
|
-
import { DataRouterContext, DataRouterStateContext, FetchersContext, ViewTransitionContext } from "../context.js";
|
|
15
|
+
import { DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, ViewTransitionContext } from "../context.js";
|
|
16
16
|
import { DataRoutes, Router } from "../components.js";
|
|
17
17
|
import { escapeHtml } from "./ssr/markup.js";
|
|
18
18
|
import * as React$1 from "react";
|
|
@@ -91,7 +91,6 @@ function StaticRouterProvider({ context, router, hydrate = true, nonce }) {
|
|
|
91
91
|
staticContext: context,
|
|
92
92
|
basename: context.basename || "/"
|
|
93
93
|
};
|
|
94
|
-
let fetchersContext = /* @__PURE__ */ new Map();
|
|
95
94
|
let hydrateScript = "";
|
|
96
95
|
if (hydrate !== false) {
|
|
97
96
|
let data = {
|
|
@@ -102,7 +101,30 @@ function StaticRouterProvider({ context, router, hydrate = true, nonce }) {
|
|
|
102
101
|
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${escapeHtml(JSON.stringify(JSON.stringify(data)))});`;
|
|
103
102
|
}
|
|
104
103
|
let { state } = dataRouterContext.router;
|
|
105
|
-
|
|
104
|
+
let dataRouterState = {
|
|
105
|
+
historyAction: state.historyAction,
|
|
106
|
+
location: state.location,
|
|
107
|
+
matches: state.matches,
|
|
108
|
+
initialized: state.initialized,
|
|
109
|
+
renderFallback: state.renderFallback,
|
|
110
|
+
restoreScrollPosition: state.restoreScrollPosition,
|
|
111
|
+
preventScrollReset: state.preventScrollReset,
|
|
112
|
+
blockers: state.blockers
|
|
113
|
+
};
|
|
114
|
+
let dataRouterNavigation = {
|
|
115
|
+
navigation: state.navigation,
|
|
116
|
+
revalidation: state.revalidation
|
|
117
|
+
};
|
|
118
|
+
let dataRouterData = {
|
|
119
|
+
loaderData: state.loaderData,
|
|
120
|
+
actionData: state.actionData,
|
|
121
|
+
errors: state.errors
|
|
122
|
+
};
|
|
123
|
+
let fetchersContext = {
|
|
124
|
+
fetchers: state.fetchers,
|
|
125
|
+
fetcherData: /* @__PURE__ */ new Map()
|
|
126
|
+
};
|
|
127
|
+
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement(DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React$1.createElement(DataRouterStateContext.Provider, { value: dataRouterState }, /* @__PURE__ */ React$1.createElement(DataRouterNavigationContext.Provider, { value: dataRouterNavigation }, /* @__PURE__ */ React$1.createElement(DataRouterDataContext.Provider, { value: dataRouterData }, /* @__PURE__ */ React$1.createElement(FetchersContext.Provider, { value: fetchersContext }, /* @__PURE__ */ React$1.createElement(ViewTransitionContext.Provider, { value: { isTransitioning: false } }, /* @__PURE__ */ React$1.createElement(Router, {
|
|
106
128
|
basename: dataRouterContext.basename,
|
|
107
129
|
location: state.location,
|
|
108
130
|
navigationType: state.historyAction,
|
|
@@ -112,10 +134,9 @@ function StaticRouterProvider({ context, router, hydrate = true, nonce }) {
|
|
|
112
134
|
}, /* @__PURE__ */ React$1.createElement(DataRoutes, {
|
|
113
135
|
manifest: router.manifest,
|
|
114
136
|
routes: router.routes,
|
|
115
|
-
future: router.future,
|
|
116
137
|
state,
|
|
117
138
|
isStatic: true
|
|
118
|
-
})))))), hydrateScript ? /* @__PURE__ */ React$1.createElement("script", {
|
|
139
|
+
})))))))), hydrateScript ? /* @__PURE__ */ React$1.createElement("script", {
|
|
119
140
|
suppressHydrationWarning: true,
|
|
120
141
|
nonce,
|
|
121
142
|
dangerouslySetInnerHTML: { __html: hydrateScript }
|
|
@@ -185,26 +206,31 @@ function getStatelessNavigator() {
|
|
|
185
206
|
* `query`
|
|
186
207
|
* @param opts Options
|
|
187
208
|
* @param opts.future Future flags for the static {@link DataRouter}
|
|
188
|
-
* @param opts.branches
|
|
209
|
+
* @param opts.branches Deprecated optional pre-computed route branches. This option
|
|
210
|
+
* is no longer used because branch caching is done automatically inside the static router.
|
|
189
211
|
* @returns A static {@link DataRouter} that can be used to render the provided routes
|
|
190
212
|
*/
|
|
191
213
|
function createStaticRouter(routes, context, opts = {}) {
|
|
214
|
+
warning(opts.branches == null, "`createStaticRouter({ branches })` is deprecated and no longer used. Branch caching is done automatically inside the static router.");
|
|
192
215
|
let manifest = {};
|
|
193
216
|
let dataRoutes = convertRoutesToDataRoutes(routes, void 0, void 0, manifest);
|
|
194
|
-
let
|
|
217
|
+
let future = { ...opts?.future };
|
|
218
|
+
let matchRoutes = context._match;
|
|
219
|
+
let mapRouteMatch = (match) => {
|
|
195
220
|
let route = manifest[match.route.id] || match.route;
|
|
196
221
|
return {
|
|
197
222
|
...match,
|
|
198
223
|
route
|
|
199
224
|
};
|
|
200
|
-
}
|
|
225
|
+
};
|
|
226
|
+
let matches = context.matches.map(mapRouteMatch);
|
|
201
227
|
let msg = (method) => `You cannot use router.${method}() on the server because it is a stateless environment`;
|
|
202
228
|
return {
|
|
203
229
|
get basename() {
|
|
204
230
|
return context.basename;
|
|
205
231
|
},
|
|
206
232
|
get future() {
|
|
207
|
-
return
|
|
233
|
+
return future;
|
|
208
234
|
},
|
|
209
235
|
get state() {
|
|
210
236
|
return {
|
|
@@ -227,13 +253,13 @@ function createStaticRouter(routes, context, opts = {}) {
|
|
|
227
253
|
get routes() {
|
|
228
254
|
return dataRoutes;
|
|
229
255
|
},
|
|
230
|
-
get branches() {
|
|
231
|
-
return opts.branches;
|
|
232
|
-
},
|
|
233
256
|
get manifest() {
|
|
234
257
|
return manifest;
|
|
235
258
|
},
|
|
236
259
|
get window() {},
|
|
260
|
+
match(locationArg) {
|
|
261
|
+
return matchRoutes(locationArg)?.map(mapRouteMatch) ?? null;
|
|
262
|
+
},
|
|
237
263
|
initialize() {
|
|
238
264
|
throw msg("initialize");
|
|
239
265
|
},
|
|
@@ -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
|
*
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { useLocation } from "../../hooks.js";
|
|
11
|
+
import { useIsRSCRouterContext } from "../../context.js";
|
|
12
|
+
import { useDataRouterContext, useDataRouterData, useDataRouterState, useLocation } from "../../hooks.js";
|
|
14
13
|
import { warnOnce } from "../../server-runtime/warnings.js";
|
|
15
14
|
import invariant from "./invariant.js";
|
|
16
15
|
import { getKeyedLinksForMatches, getKeyedPrefetchLinks, getModuleLinkHrefs, getNewMatchesForLinks, isPageLinkDescriptor } from "./links.js";
|
|
@@ -19,16 +18,6 @@ import { singleFetchUrl } from "./single-fetch.js";
|
|
|
19
18
|
import { getPartialManifest, isFogOfWarEnabled } from "./fog-of-war.js";
|
|
20
19
|
import * as React$1 from "react";
|
|
21
20
|
//#region lib/dom/ssr/components.tsx
|
|
22
|
-
function useDataRouterContext() {
|
|
23
|
-
let context = React$1.useContext(DataRouterContext);
|
|
24
|
-
invariant(context, "You must render this element inside a <DataRouterContext.Provider> element");
|
|
25
|
-
return context;
|
|
26
|
-
}
|
|
27
|
-
function useDataRouterStateContext() {
|
|
28
|
-
let context = React$1.useContext(DataRouterStateContext);
|
|
29
|
-
invariant(context, "You must render this element inside a <DataRouterStateContext.Provider> element");
|
|
30
|
-
return context;
|
|
31
|
-
}
|
|
32
21
|
const FrameworkContext = React$1.createContext(void 0);
|
|
33
22
|
FrameworkContext.displayName = "FrameworkContext";
|
|
34
23
|
function useFrameworkContext() {
|
|
@@ -142,7 +131,8 @@ const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
|
|
|
142
131
|
*/
|
|
143
132
|
function Links({ nonce, crossOrigin }) {
|
|
144
133
|
let { isSpaMode, manifest, routeModules, criticalCss, nonce: contextNonce } = useFrameworkContext();
|
|
145
|
-
let {
|
|
134
|
+
let { matches: routerMatches } = useDataRouterState("Links");
|
|
135
|
+
let { errors } = useDataRouterData("Links");
|
|
146
136
|
let matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
|
147
137
|
let keyedLinks = React$1.useMemo(() => getKeyedLinksForMatches(matches, routeModules, manifest), [
|
|
148
138
|
matches,
|
|
@@ -202,11 +192,11 @@ function Links({ nonce, crossOrigin }) {
|
|
|
202
192
|
function PrefetchPageLinks({ page, ...linkProps }) {
|
|
203
193
|
let rsc = useIsRSCRouterContext();
|
|
204
194
|
let { nonce: contextNonce } = useFrameworkContext();
|
|
205
|
-
let { router } = useDataRouterContext();
|
|
206
|
-
let matches = React$1.useMemo(() =>
|
|
195
|
+
let { router } = useDataRouterContext("PrefetchPageLinks");
|
|
196
|
+
let matches = React$1.useMemo(() => router.match(page), [
|
|
197
|
+
router,
|
|
207
198
|
router.routes,
|
|
208
|
-
page
|
|
209
|
-
router.basename
|
|
199
|
+
page
|
|
210
200
|
]);
|
|
211
201
|
if (!matches) return null;
|
|
212
202
|
if (linkProps.nonce == null && contextNonce) linkProps = {
|
|
@@ -269,7 +259,8 @@ function RSCPrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps })
|
|
|
269
259
|
function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
|
|
270
260
|
let location = useLocation();
|
|
271
261
|
let { manifest, routeModules } = useFrameworkContext();
|
|
272
|
-
let {
|
|
262
|
+
let { matches } = useDataRouterState("PrefetchPageLinks");
|
|
263
|
+
let { loaderData } = useDataRouterData("PrefetchPageLinks");
|
|
273
264
|
let newMatchesForData = React$1.useMemo(() => getNewMatchesForLinks(page, nextMatches, matches, manifest, location, "data"), [
|
|
274
265
|
page,
|
|
275
266
|
nextMatches,
|
|
@@ -355,7 +346,8 @@ function PrefetchPageLinksImpl({ page, matches: nextMatches, ...linkProps }) {
|
|
|
355
346
|
*/
|
|
356
347
|
function Meta() {
|
|
357
348
|
let { isSpaMode, routeModules } = useFrameworkContext();
|
|
358
|
-
let {
|
|
349
|
+
let { matches: routerMatches } = useDataRouterState("Meta");
|
|
350
|
+
let { errors, loaderData } = useDataRouterData("Meta");
|
|
359
351
|
let location = useLocation();
|
|
360
352
|
let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
|
361
353
|
let error = null;
|
|
@@ -425,7 +417,7 @@ function Meta() {
|
|
|
425
417
|
type: "application/ld+json",
|
|
426
418
|
dangerouslySetInnerHTML: { __html: escapeHtml(json) }
|
|
427
419
|
});
|
|
428
|
-
} catch
|
|
420
|
+
} catch {
|
|
429
421
|
return null;
|
|
430
422
|
}
|
|
431
423
|
return /* @__PURE__ */ React$1.createElement("meta", {
|
|
@@ -480,8 +472,8 @@ function setIsHydrated() {
|
|
|
480
472
|
*/
|
|
481
473
|
function Scripts(scriptProps) {
|
|
482
474
|
let { manifest, serverHandoffString, isSpaMode, renderMeta, routeDiscovery, ssr, nonce: contextNonce } = useFrameworkContext();
|
|
483
|
-
let { router, static: isStatic, staticContext } = useDataRouterContext();
|
|
484
|
-
let { matches: routerMatches } =
|
|
475
|
+
let { router, static: isStatic, staticContext } = useDataRouterContext("Scripts");
|
|
476
|
+
let { matches: routerMatches } = useDataRouterState("Scripts");
|
|
485
477
|
let isRSCRouterContext = useIsRSCRouterContext();
|
|
486
478
|
let enableFogOfWar = isFogOfWarEnabled(routeDiscovery, ssr);
|
|
487
479
|
if (scriptProps.nonce == null && contextNonce) scriptProps = {
|
|
@@ -33,6 +33,10 @@ interface FrameworkContextObject {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
interface EntryContext extends FrameworkContextObject {
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated This property was an internal implementation detail and was
|
|
38
|
+
* never intended for use in `entry.server.tsx`. It is always an empty array.
|
|
39
|
+
*/
|
|
36
40
|
branches: RouteBranch<DataRouteObject>[];
|
|
37
41
|
staticHandlerContext: StaticHandlerContext;
|
|
38
42
|
serverHandoffStream?: ReadableStream<Uint8Array>;
|
|
@@ -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
|
*
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import { createPath } from "../../router/history.js";
|
|
12
|
-
import { joinPaths
|
|
12
|
+
import { joinPaths } from "../../router/utils.js";
|
|
13
13
|
import { createClientRoutes } from "./routes.js";
|
|
14
14
|
import * as React$1 from "react";
|
|
15
15
|
//#region lib/dom/ssr/fog-of-war.ts
|
|
@@ -39,7 +39,7 @@ function getPartialManifest({ sri, ...manifest }, router) {
|
|
|
39
39
|
segments.pop();
|
|
40
40
|
}
|
|
41
41
|
paths.forEach((path) => {
|
|
42
|
-
let matches =
|
|
42
|
+
let matches = router.match(path);
|
|
43
43
|
if (matches) matches.forEach((m) => routeIds.add(m.route.id));
|
|
44
44
|
});
|
|
45
45
|
let initialRoutes = [...routeIds].reduce((acc, id) => Object.assign(acc, { [id]: manifest.routes[id] }), {});
|
|
@@ -110,7 +110,10 @@ function getManifestPath(_manifestPath, basename) {
|
|
|
110
110
|
return basename == null ? manifestPath : joinPaths([basename, manifestPath]);
|
|
111
111
|
}
|
|
112
112
|
const MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
|
|
113
|
+
const MANIFEST_RELOAD_TIMEOUT = 5e3;
|
|
114
|
+
let pendingManifestReload;
|
|
113
115
|
async function handleClientVersionMismatch(needsReload, version, errorReloadPath) {
|
|
116
|
+
if (pendingManifestReload) return pendingManifestReload;
|
|
114
117
|
if (!needsReload) {
|
|
115
118
|
try {
|
|
116
119
|
sessionStorage.removeItem(MANIFEST_VERSION_STORAGE_KEY);
|
|
@@ -121,17 +124,35 @@ async function handleClientVersionMismatch(needsReload, version, errorReloadPath
|
|
|
121
124
|
console.warn("Detected a manifest version mismatch during eager route discovery. The next navigation/fetch to an undiscovered route will result in a new document navigation to sync up with the latest manifest.");
|
|
122
125
|
return true;
|
|
123
126
|
}
|
|
127
|
+
let alreadyReloaded = false;
|
|
124
128
|
try {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, version);
|
|
129
|
+
alreadyReloaded = sessionStorage.getItem(MANIFEST_VERSION_STORAGE_KEY) === version;
|
|
130
|
+
if (!alreadyReloaded) sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, version);
|
|
130
131
|
} catch {}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
if (alreadyReloaded) throw new Error("Unable to discover routes due to manifest version mismatch.");
|
|
133
|
+
let rejectReload;
|
|
134
|
+
let reloadPromise = new Promise((_, reject) => {
|
|
135
|
+
rejectReload = reject;
|
|
136
|
+
});
|
|
137
|
+
pendingManifestReload = reloadPromise;
|
|
138
|
+
let failReload = () => {
|
|
139
|
+
clearTimeout(timeout);
|
|
140
|
+
window.removeEventListener("pageshow", onPageShow);
|
|
141
|
+
pendingManifestReload = void 0;
|
|
142
|
+
rejectReload(/* @__PURE__ */ new Error("Unable to discover routes due to manifest version mismatch."));
|
|
143
|
+
};
|
|
144
|
+
let timeout = setTimeout(failReload, MANIFEST_RELOAD_TIMEOUT);
|
|
145
|
+
let onPageShow = (event) => {
|
|
146
|
+
if (event.persisted) failReload();
|
|
147
|
+
};
|
|
148
|
+
window.addEventListener("pageshow", onPageShow);
|
|
149
|
+
try {
|
|
150
|
+
window.location.href = errorReloadPath;
|
|
151
|
+
console.warn("Detected manifest version mismatch, reloading...");
|
|
152
|
+
} catch {
|
|
153
|
+
failReload();
|
|
154
|
+
}
|
|
155
|
+
return reloadPromise;
|
|
135
156
|
}
|
|
136
157
|
async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
|
|
137
158
|
paths = getPathsWithAncestors(paths);
|
|
@@ -154,6 +175,7 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
|
|
|
154
175
|
if (signal?.aborted) return;
|
|
155
176
|
throw e;
|
|
156
177
|
}
|
|
178
|
+
if (signal?.aborted) return;
|
|
157
179
|
let knownRoutes = new Set(Object.keys(manifest.routes));
|
|
158
180
|
let patches = Object.values(serverPatches).reduce((acc, route) => {
|
|
159
181
|
if (route && !knownRoutes.has(route.id)) acc[route.id] = route;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { Path } from "../../router/history.js";
|
|
3
3
|
import { DataRouteObject } from "../../router/utils.js";
|
|
4
|
-
import { HydrationState, Router } from "../../router/router.js";
|
|
4
|
+
import { FutureConfig, HydrationState, Router } from "../../router/router.js";
|
|
5
5
|
import { ClientLoaderFunction } from "./routeModules.js";
|
|
6
6
|
|
|
7
7
|
//#region lib/dom/ssr/hydration.d.ts
|
|
@@ -11,6 +11,7 @@ declare function getHydrationData({
|
|
|
11
11
|
getRouteInfo,
|
|
12
12
|
location,
|
|
13
13
|
basename,
|
|
14
|
+
future,
|
|
14
15
|
isSpaMode
|
|
15
16
|
}: {
|
|
16
17
|
state: {
|
|
@@ -26,6 +27,7 @@ declare function getHydrationData({
|
|
|
26
27
|
};
|
|
27
28
|
location: Path;
|
|
28
29
|
basename: string | undefined;
|
|
30
|
+
future: FutureConfig;
|
|
29
31
|
isSpaMode: boolean;
|
|
30
32
|
}): HydrationState;
|
|
31
33
|
//#endregion
|
|
@@ -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
|
*
|
|
@@ -8,15 +8,17 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { createDataRouteMatcher } from "../../router/router.js";
|
|
12
12
|
import { shouldHydrateRouteLoader } from "./routes.js";
|
|
13
13
|
//#region lib/dom/ssr/hydration.tsx
|
|
14
|
-
function getHydrationData({ state, routes, getRouteInfo, location, basename, isSpaMode }) {
|
|
14
|
+
function getHydrationData({ state, routes, getRouteInfo, location, basename, future, isSpaMode }) {
|
|
15
15
|
let hydrationData = {
|
|
16
16
|
...state,
|
|
17
17
|
loaderData: { ...state.loaderData }
|
|
18
18
|
};
|
|
19
|
-
let
|
|
19
|
+
let dataRouteMatcher = createDataRouteMatcher(future, basename || "/");
|
|
20
|
+
dataRouteMatcher.update(routes);
|
|
21
|
+
let initialMatches = dataRouteMatcher.match(location);
|
|
20
22
|
if (initialMatches) for (let match of initialMatches) {
|
|
21
23
|
let routeId = match.route.id;
|
|
22
24
|
let routeInfo = getRouteInfo(routeId);
|
|
@@ -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
|
*
|
|
@@ -20,5 +20,8 @@ const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
|
20
20
|
function escapeHtml(html) {
|
|
21
21
|
return html.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
22
22
|
}
|
|
23
|
+
function escapeAttribute(value) {
|
|
24
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
25
|
+
}
|
|
23
26
|
//#endregion
|
|
24
|
-
export { escapeHtml };
|
|
27
|
+
export { escapeAttribute, escapeHtml };
|
|
@@ -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
|
*
|
|
@@ -40,7 +40,7 @@ function ServerRouter({ context, url, nonce }) {
|
|
|
40
40
|
let manifestRoute = context.manifest.routes[routeId];
|
|
41
41
|
if (route && manifestRoute && shouldHydrateRouteLoader(routeId, route.clientLoader, manifestRoute.hasLoader, context.isSpaMode) && (route.HydrateFallback || !manifestRoute.hasLoader)) delete context.staticHandlerContext.loaderData[routeId];
|
|
42
42
|
}
|
|
43
|
-
let router = createStaticRouter(routes, context.staticHandlerContext, {
|
|
43
|
+
let router = createStaticRouter(routes, context.staticHandlerContext, { future: context.future });
|
|
44
44
|
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: {
|
|
45
45
|
manifest,
|
|
46
46
|
routeModules,
|
|
@@ -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
|
*
|
|
@@ -101,25 +101,16 @@ async function singleFetchActionStrategy(args, fetchAndDecode) {
|
|
|
101
101
|
async function nonSsrStrategy(args, getRouteInfo, fetchAndDecode) {
|
|
102
102
|
let matchesToLoad = args.matches.filter((m) => m.shouldCallHandler());
|
|
103
103
|
let results = {};
|
|
104
|
-
await Promise.all(matchesToLoad.map(
|
|
105
|
-
|
|
104
|
+
await Promise.all(matchesToLoad.map(async (m) => {
|
|
105
|
+
let routeId = m.route.id;
|
|
106
|
+
results[routeId] = await m.resolve(async (handler) => {
|
|
106
107
|
let { hasClientLoader } = getRouteInfo(m);
|
|
107
|
-
|
|
108
|
-
let result = hasClientLoader ? await handler(async () => {
|
|
108
|
+
return hasClientLoader ? handler(async () => {
|
|
109
109
|
let { data } = await fetchAndDecode(args, [routeId]);
|
|
110
110
|
return unwrapSingleFetchResult(data, routeId);
|
|
111
|
-
}) :
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
result
|
|
115
|
-
};
|
|
116
|
-
} catch (e) {
|
|
117
|
-
results[m.route.id] = {
|
|
118
|
-
type: "error",
|
|
119
|
-
result: e
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
})));
|
|
111
|
+
}) : handler();
|
|
112
|
+
});
|
|
113
|
+
}));
|
|
123
114
|
return results;
|
|
124
115
|
}
|
|
125
116
|
async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, fetchAndDecode, ssr, shouldAllowOptOut = () => true) {
|
|
@@ -205,7 +196,7 @@ async function bubbleMiddlewareErrors(singleFetchPromise, matches, routesParams,
|
|
|
205
196
|
if (middlewareError !== void 0) Array.from(routesParams.values()).forEach((routeId) => {
|
|
206
197
|
if (results[routeId].result instanceof SingleFetchNoResultError) results[routeId].result = middlewareError;
|
|
207
198
|
});
|
|
208
|
-
} catch
|
|
199
|
+
} catch {}
|
|
209
200
|
}
|
|
210
201
|
async function singleFetchLoaderFetcherStrategy(args, fetchAndDecode) {
|
|
211
202
|
let fetcherMatch = args.matches.find((m) => m.shouldCallHandler());
|
|
@@ -277,8 +268,8 @@ async function fetchAndDecodeViaTurboStream(args, targetRoutes) {
|
|
|
277
268
|
status: res.status,
|
|
278
269
|
data
|
|
279
270
|
};
|
|
280
|
-
} catch (
|
|
281
|
-
throw new Error("Unable to decode turbo-stream response");
|
|
271
|
+
} catch (cause) {
|
|
272
|
+
throw new Error("Unable to decode turbo-stream response", { cause });
|
|
282
273
|
}
|
|
283
274
|
}
|
|
284
275
|
function decodeViaTurboStream(body, global) {
|
|
@@ -326,13 +317,13 @@ function createDeferred() {
|
|
|
326
317
|
res(val);
|
|
327
318
|
try {
|
|
328
319
|
await promise;
|
|
329
|
-
} catch
|
|
320
|
+
} catch {}
|
|
330
321
|
};
|
|
331
322
|
reject = async (error) => {
|
|
332
323
|
rej(error);
|
|
333
324
|
try {
|
|
334
325
|
await promise;
|
|
335
|
-
} catch
|
|
326
|
+
} catch {}
|
|
336
327
|
};
|
|
337
328
|
});
|
|
338
329
|
return {
|
|
@@ -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
|
*
|
|
@@ -67,6 +67,7 @@ function createHydratedRouter({ getContext, instrumentations }) {
|
|
|
67
67
|
}),
|
|
68
68
|
location: window.location,
|
|
69
69
|
basename: window.__reactRouterContext?.basename,
|
|
70
|
+
future: ssrInfo.context.future,
|
|
70
71
|
isSpaMode: ssrInfo.context.isSpaMode
|
|
71
72
|
});
|
|
72
73
|
if (window.history.state && window.history.state.masked) window.history.replaceState({
|