react-router 8.5.0 → 8.5.2
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 +70 -1
- 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 +75 -415
- package/dist/development/index-react-server.js +106 -20
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/await.js +58 -0
- package/dist/development/lib/components.d.ts +65 -25
- package/dist/development/lib/components.js +69 -15
- package/dist/development/lib/context.d.ts +2 -2
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.js +13 -4
- package/dist/development/lib/dom/lib.d.ts +2 -2
- package/dist/development/lib/dom/lib.js +11 -4
- 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 +12 -3
- package/dist/development/lib/dom/ssr/hydration.d.ts +1 -0
- package/dist/development/lib/dom/ssr/hydration.js +1 -1
- package/dist/development/lib/dom/ssr/invariant.js +1 -1
- package/dist/development/lib/dom/ssr/links.js +1 -1
- package/dist/development/lib/dom/ssr/markup.js +1 -1
- package/dist/development/lib/dom/ssr/route-discovery.d.ts +2 -2
- package/dist/development/lib/dom/ssr/route-discovery.js +3 -3
- 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.d.ts +1 -1
- package/dist/development/lib/dom/ssr/single-fetch.js +7 -7
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.d.ts +1 -1
- package/dist/development/lib/dom-export/hydrated-router.js +5 -3
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.d.ts +0 -3
- package/dist/development/lib/hooks.js +13 -9
- package/dist/development/lib/href.js +4 -4
- package/dist/development/lib/router/history.js +1 -1
- package/dist/development/lib/router/instrumentation.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.js +1 -1
- package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/development/lib/router/matcher.js +6 -1
- package/dist/development/lib/router/navigation.js +17 -2
- package/dist/development/lib/router/router.d.ts +2 -0
- package/dist/development/lib/router/router.js +62 -29
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +13 -5
- package/dist/development/lib/router/utils.js +17 -8
- package/dist/development/lib/rsc/browser.js +28 -5
- 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 +2 -0
- 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 +21 -10
- 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 +2 -2
- 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 +1 -1
- package/dist/development/route-pattern.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +75 -66
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +23 -3
- 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 +75 -415
- package/dist/production/index-react-server.js +106 -20
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/await.js +58 -0
- package/dist/production/lib/components.d.ts +65 -25
- package/dist/production/lib/components.js +69 -15
- package/dist/production/lib/context.d.ts +2 -2
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.js +13 -4
- package/dist/production/lib/dom/lib.d.ts +2 -2
- package/dist/production/lib/dom/lib.js +11 -4
- 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 +12 -3
- package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
- package/dist/production/lib/dom/ssr/hydration.js +1 -1
- package/dist/production/lib/dom/ssr/invariant.js +1 -1
- package/dist/production/lib/dom/ssr/links.js +1 -1
- package/dist/production/lib/dom/ssr/markup.js +1 -1
- package/dist/production/lib/dom/ssr/route-discovery.d.ts +2 -2
- package/dist/production/lib/dom/ssr/route-discovery.js +3 -3
- 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.d.ts +1 -1
- package/dist/production/lib/dom/ssr/single-fetch.js +7 -7
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
- package/dist/production/lib/dom-export/hydrated-router.js +5 -3
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.d.ts +0 -3
- package/dist/production/lib/hooks.js +13 -9
- package/dist/production/lib/href.js +4 -4
- package/dist/production/lib/router/history.js +1 -1
- package/dist/production/lib/router/instrumentation.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.js +1 -1
- package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
- package/dist/production/lib/router/matcher.js +6 -1
- package/dist/production/lib/router/navigation.js +17 -2
- package/dist/production/lib/router/router.d.ts +2 -0
- package/dist/production/lib/router/router.js +62 -29
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +13 -5
- package/dist/production/lib/router/utils.js +17 -8
- package/dist/production/lib/rsc/browser.js +28 -5
- 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 +2 -0
- 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 +21 -10
- 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 +2 -2
- 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 +1 -1
- package/dist/production/route-pattern.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +75 -66
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +23 -3
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/explanation/backend-for-frontend.md +0 -3
- package/docs/explanation/code-splitting.md +0 -3
- package/docs/explanation/concurrency.md +0 -3
- package/docs/explanation/hot-module-replacement.md +0 -3
- package/docs/explanation/lazy-route-discovery.md +0 -3
- package/docs/explanation/progressive-enhancement.md +0 -3
- package/docs/explanation/race-conditions.md +0 -3
- package/docs/explanation/react-transitions.md +0 -3
- package/docs/explanation/sessions-and-cookies.md +1 -1
- package/docs/explanation/state-management.md +0 -3
- package/docs/explanation/styling.md +0 -3
- package/docs/explanation/type-safety.md +0 -3
- package/docs/how-to/accessibility.md +0 -6
- package/docs/how-to/client-data.md +0 -3
- package/docs/how-to/data-strategy.md +0 -3
- package/docs/how-to/error-boundary.md +0 -3
- package/docs/how-to/error-reporting.md +0 -3
- package/docs/how-to/fetchers.md +0 -3
- package/docs/how-to/file-route-conventions.md +0 -3
- package/docs/how-to/file-uploads.md +0 -3
- package/docs/how-to/form-validation.md +0 -3
- package/docs/how-to/headers.md +0 -3
- package/docs/how-to/instrumentation.md +0 -3
- package/docs/how-to/middleware.md +6 -3
- package/docs/how-to/navigation-blocking.md +0 -3
- package/docs/how-to/optimize-revalidation.md +0 -3
- package/docs/how-to/pre-rendering.md +0 -3
- package/docs/how-to/presets.md +0 -3
- package/docs/how-to/react-server-components.md +0 -3
- package/docs/how-to/resource-routes.md +0 -3
- package/docs/how-to/route-discovery.md +4 -2
- package/docs/how-to/route-module-type-safety.md +0 -3
- package/docs/how-to/security.md +0 -3
- package/docs/how-to/server-bundles.md +0 -3
- package/docs/how-to/spa.md +0 -3
- package/docs/how-to/status.md +0 -3
- package/docs/how-to/suspense.md +22 -6
- package/docs/how-to/using-handle.md +0 -3
- package/docs/how-to/view-transitions.md +0 -3
- package/docs/start/framework/data-loading.md +9 -0
- package/docs/upgrading/future.md +0 -12
- package/docs/upgrading/v7.md +14 -33
- package/package.json +1 -1
- package/dist/development/lib/dom/global.d.ts +0 -35
- package/dist/production/lib/dom/global.d.ts +0 -35
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { ErrorResponseImpl, RouterContextProvider, createDataFunctionUrl, defaultMapRouteProperties, getRoutePattern, isRouteErrorResponse, removeTrailingSlash, stripBasename } from "../router/utils.js";
|
|
12
12
|
import { instrumentHandler, instrumentationResultMetaContext } from "../router/instrumentation.js";
|
|
13
13
|
import { createStaticHandler, getStaticContextFromError, isMutationMethod, isRedirectResponse, isResponse } from "../router/router.js";
|
|
14
|
-
import { getManifestPath } from "../dom/ssr/fog-of-war.js";
|
|
14
|
+
import { getManifestPath, isFogOfWarEnabled, shouldUseInitialRouteDiscovery } from "../dom/ssr/fog-of-war.js";
|
|
15
15
|
import { createEntryRouteModules } from "./entry.js";
|
|
16
16
|
import { isServerMode } from "./mode.js";
|
|
17
17
|
import { sanitizeErrors, serializeError } from "./errors.js";
|
|
@@ -59,7 +59,10 @@ function derive(build, mode) {
|
|
|
59
59
|
let normalizedPathname = normalizedPath.pathname;
|
|
60
60
|
let isSpaMode = getBuildTimeHeader(request, "X-React-Router-SPA-Mode") === "yes";
|
|
61
61
|
if (!build.ssr || build.unstable_apiOnly) {
|
|
62
|
-
let decodedPath =
|
|
62
|
+
let decodedPath = normalizedPathname;
|
|
63
|
+
try {
|
|
64
|
+
decodedPath = decodeURI(normalizedPathname);
|
|
65
|
+
} catch {}
|
|
63
66
|
if (build.basename && build.basename !== "/") {
|
|
64
67
|
let strippedPath = stripBasename(decodedPath, build.basename);
|
|
65
68
|
if (strippedPath == null) {
|
|
@@ -126,11 +129,14 @@ function derive(build, mode) {
|
|
|
126
129
|
else if (mode === "development" && getDevServerHooks()?.getCriticalCss) criticalCss = await getDevServerHooks()?.getCriticalCss?.(pathname);
|
|
127
130
|
response = await handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss);
|
|
128
131
|
}
|
|
129
|
-
if (request.method === "HEAD")
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
if (request.method === "HEAD") {
|
|
133
|
+
response.body?.cancel().catch(() => {});
|
|
134
|
+
return new Response(null, {
|
|
135
|
+
headers: response.headers,
|
|
136
|
+
status: response.status,
|
|
137
|
+
statusText: response.statusText
|
|
138
|
+
});
|
|
139
|
+
}
|
|
134
140
|
return response;
|
|
135
141
|
};
|
|
136
142
|
if (requestHandlerInstrumentations?.length) requestHandler = instrumentHandler(requestHandler, requestHandlerInstrumentations);
|
|
@@ -251,10 +257,15 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
|
|
|
251
257
|
actionData: context.actionData,
|
|
252
258
|
errors: context.errors
|
|
253
259
|
};
|
|
260
|
+
let routeDiscovery = build.routeDiscovery;
|
|
261
|
+
if (isFogOfWarEnabled(routeDiscovery, build.ssr) && shouldUseInitialRouteDiscovery(context.location.pathname, staticHandler._matchCost)) routeDiscovery = {
|
|
262
|
+
...routeDiscovery,
|
|
263
|
+
mode: "initial"
|
|
264
|
+
};
|
|
254
265
|
let baseServerHandoff = {
|
|
255
266
|
basename: build.basename,
|
|
256
267
|
future: build.future,
|
|
257
|
-
routeDiscovery
|
|
268
|
+
routeDiscovery,
|
|
258
269
|
ssr: build.ssr,
|
|
259
270
|
isSpaMode,
|
|
260
271
|
unstable_apiOnly: build.unstable_apiOnly,
|
|
@@ -274,7 +285,7 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
|
|
|
274
285
|
renderMeta: {},
|
|
275
286
|
future: build.future,
|
|
276
287
|
ssr: build.ssr,
|
|
277
|
-
routeDiscovery
|
|
288
|
+
routeDiscovery,
|
|
278
289
|
isSpaMode,
|
|
279
290
|
unstable_apiOnly: build.unstable_apiOnly,
|
|
280
291
|
unstable_apiServerOrigin: build.unstable_apiServerOrigin,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -99,7 +99,7 @@ function createSessionStorage({ cookie: cookieArg, createData, readData, updateD
|
|
|
99
99
|
return cookie.serialize(id, options);
|
|
100
100
|
},
|
|
101
101
|
async destroySession(session, options) {
|
|
102
|
-
await deleteData(session.id);
|
|
102
|
+
if (session.id) await deleteData(session.id);
|
|
103
103
|
return cookie.serialize("", {
|
|
104
104
|
...options,
|
|
105
105
|
maxAge: void 0,
|
|
@@ -31,7 +31,7 @@ type MetaMatch<T extends MatchInfo> = Pretty<{
|
|
|
31
31
|
handle?: unknown;
|
|
32
32
|
error?: unknown;
|
|
33
33
|
}>;
|
|
34
|
-
type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : Array<MetaMatch<MatchInfo> | undefined>;
|
|
34
|
+
type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : T extends [] ? [] : Array<MetaMatch<MatchInfo> | undefined>;
|
|
35
35
|
type HasErrorBoundary<T extends RouteInfo> = T["module"] extends {
|
|
36
36
|
ErrorBoundary: Func;
|
|
37
37
|
} ? true : false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -105,75 +105,84 @@ function encode(input, options) {
|
|
|
105
105
|
};
|
|
106
106
|
const textEncoder = new TextEncoder();
|
|
107
107
|
let lastSentIndex = 0;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (seenPromises.has(deferred)) continue;
|
|
133
|
-
seenPromises.add(encoder.deferred[Number(deferredId)] = Promise.race([racePromise, deferred]).then((resolved) => {
|
|
134
|
-
processingChain = processingChain.then(async () => {
|
|
135
|
-
const id = await flatten.call(encoder, resolved);
|
|
136
|
-
if (Array.isArray(id)) {
|
|
137
|
-
controller.enqueue(textEncoder.encode(`P${deferredId}:[["Z",${id[0]}]]\n`));
|
|
138
|
-
encoder.index++;
|
|
139
|
-
lastSentIndex++;
|
|
140
|
-
} else if (id < 0) controller.enqueue(textEncoder.encode(`P${deferredId}:${id}\n`));
|
|
141
|
-
else {
|
|
142
|
-
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
|
143
|
-
controller.enqueue(textEncoder.encode(`P${deferredId}:[${values}]\n`));
|
|
144
|
-
lastSentIndex = encoder.stringified.length - 1;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
return processingChain;
|
|
148
|
-
}, (reason) => {
|
|
149
|
-
processingChain = processingChain.then(async () => {
|
|
150
|
-
if (!reason || typeof reason !== "object" || !(reason instanceof Error)) reason = /* @__PURE__ */ new Error("An unknown error occurred");
|
|
151
|
-
const id = await flatten.call(encoder, reason);
|
|
152
|
-
if (Array.isArray(id)) {
|
|
153
|
-
controller.enqueue(textEncoder.encode(`E${deferredId}:[["Z",${id[0]}]]\n`));
|
|
154
|
-
encoder.index++;
|
|
155
|
-
lastSentIndex++;
|
|
156
|
-
} else if (id < 0) controller.enqueue(textEncoder.encode(`E${deferredId}:${id}\n`));
|
|
157
|
-
else {
|
|
158
|
-
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
|
159
|
-
controller.enqueue(textEncoder.encode(`E${deferredId}:[${values}]\n`));
|
|
160
|
-
lastSentIndex = encoder.stringified.length - 1;
|
|
161
|
-
}
|
|
108
|
+
let cancelled = false;
|
|
109
|
+
return new ReadableStream({
|
|
110
|
+
async start(controller) {
|
|
111
|
+
const enqueue = (chunk) => {
|
|
112
|
+
if (!cancelled) controller.enqueue(chunk);
|
|
113
|
+
};
|
|
114
|
+
const id = await flatten.call(encoder, input);
|
|
115
|
+
if (Array.isArray(id)) throw new Error("This should never happen");
|
|
116
|
+
if (id < 0) enqueue(textEncoder.encode(`${id}\n`));
|
|
117
|
+
else {
|
|
118
|
+
enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]\n`));
|
|
119
|
+
lastSentIndex = encoder.stringified.length - 1;
|
|
120
|
+
}
|
|
121
|
+
const seenPromises = /* @__PURE__ */ new WeakSet();
|
|
122
|
+
let processingChain = Promise.resolve();
|
|
123
|
+
if (Object.keys(encoder.deferred).length) {
|
|
124
|
+
let raceDone;
|
|
125
|
+
const racePromise = new Promise((resolve, reject) => {
|
|
126
|
+
raceDone = resolve;
|
|
127
|
+
if (signal) {
|
|
128
|
+
const rejectPromise = () => reject(signal.reason || /* @__PURE__ */ new Error("Signal was aborted."));
|
|
129
|
+
if (signal.aborted) rejectPromise();
|
|
130
|
+
else signal.addEventListener("abort", (event) => {
|
|
131
|
+
rejectPromise();
|
|
162
132
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
while (Object.keys(encoder.deferred).length > 0) {
|
|
136
|
+
for (const [deferredId, deferred] of Object.entries(encoder.deferred)) {
|
|
137
|
+
if (seenPromises.has(deferred)) continue;
|
|
138
|
+
seenPromises.add(encoder.deferred[Number(deferredId)] = Promise.race([racePromise, deferred]).then((resolved) => {
|
|
139
|
+
processingChain = processingChain.then(async () => {
|
|
140
|
+
const id = await flatten.call(encoder, resolved);
|
|
141
|
+
if (Array.isArray(id)) {
|
|
142
|
+
enqueue(textEncoder.encode(`P${deferredId}:[["Z",${id[0]}]]\n`));
|
|
143
|
+
encoder.index++;
|
|
144
|
+
lastSentIndex++;
|
|
145
|
+
} else if (id < 0) enqueue(textEncoder.encode(`P${deferredId}:${id}\n`));
|
|
146
|
+
else {
|
|
147
|
+
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
|
148
|
+
enqueue(textEncoder.encode(`P${deferredId}:[${values}]\n`));
|
|
149
|
+
lastSentIndex = encoder.stringified.length - 1;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return processingChain;
|
|
153
|
+
}, (reason) => {
|
|
154
|
+
processingChain = processingChain.then(async () => {
|
|
155
|
+
if (!reason || typeof reason !== "object" || !(reason instanceof Error)) reason = /* @__PURE__ */ new Error("An unknown error occurred");
|
|
156
|
+
const id = await flatten.call(encoder, reason);
|
|
157
|
+
if (Array.isArray(id)) {
|
|
158
|
+
enqueue(textEncoder.encode(`E${deferredId}:[["Z",${id[0]}]]\n`));
|
|
159
|
+
encoder.index++;
|
|
160
|
+
lastSentIndex++;
|
|
161
|
+
} else if (id < 0) enqueue(textEncoder.encode(`E${deferredId}:${id}\n`));
|
|
162
|
+
else {
|
|
163
|
+
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
|
164
|
+
enqueue(textEncoder.encode(`E${deferredId}:[${values}]\n`));
|
|
165
|
+
lastSentIndex = encoder.stringified.length - 1;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return processingChain;
|
|
169
|
+
}).finally(() => {
|
|
170
|
+
delete encoder.deferred[Number(deferredId)];
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
await Promise.race(Object.values(encoder.deferred));
|
|
167
174
|
}
|
|
168
|
-
|
|
175
|
+
raceDone();
|
|
169
176
|
}
|
|
170
|
-
|
|
177
|
+
await Promise.all(Object.values(encoder.deferred));
|
|
178
|
+
await processingChain;
|
|
179
|
+
if (!cancelled) controller.close();
|
|
180
|
+
onComplete?.();
|
|
181
|
+
},
|
|
182
|
+
cancel() {
|
|
183
|
+
cancelled = true;
|
|
171
184
|
}
|
|
172
|
-
|
|
173
|
-
await processingChain;
|
|
174
|
-
controller.close();
|
|
175
|
-
onComplete?.();
|
|
176
|
-
} });
|
|
185
|
+
});
|
|
177
186
|
}
|
|
178
187
|
//#endregion
|
|
179
188
|
export { decode, encode };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.5.
|
|
2
|
+
* react-router v8.5.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -50,6 +50,7 @@ function hydrate(index) {
|
|
|
50
50
|
set(-0);
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
|
+
validateIndex(index, values.length);
|
|
53
54
|
if (hydrated[index]) {
|
|
54
55
|
set(hydrated[index]);
|
|
55
56
|
continue;
|
|
@@ -121,11 +122,21 @@ function hydrate(index) {
|
|
|
121
122
|
set(obj);
|
|
122
123
|
continue;
|
|
123
124
|
case "P":
|
|
125
|
+
validateIndex(b, values.length);
|
|
124
126
|
if (hydrated[b]) set(hydrated[index] = hydrated[b]);
|
|
125
127
|
else {
|
|
126
128
|
const d = new Deferred();
|
|
129
|
+
const promise = d.promise;
|
|
130
|
+
promise.status = "pending";
|
|
131
|
+
promise.then((value) => {
|
|
132
|
+
promise.status = "fulfilled";
|
|
133
|
+
promise.value = value;
|
|
134
|
+
}, (reason) => {
|
|
135
|
+
promise.status = "rejected";
|
|
136
|
+
promise.reason = reason;
|
|
137
|
+
});
|
|
127
138
|
deferred[b] = d;
|
|
128
|
-
set(hydrated[index] =
|
|
139
|
+
set(hydrated[index] = promise);
|
|
129
140
|
}
|
|
130
141
|
continue;
|
|
131
142
|
case "E":
|
|
@@ -135,6 +146,7 @@ function hydrate(index) {
|
|
|
135
146
|
set(error);
|
|
136
147
|
continue;
|
|
137
148
|
case "Z":
|
|
149
|
+
validateIndex(b, values.length);
|
|
138
150
|
set(hydrated[index] = hydrated[b]);
|
|
139
151
|
continue;
|
|
140
152
|
default:
|
|
@@ -185,7 +197,12 @@ function hydrate(index) {
|
|
|
185
197
|
r[0] = k;
|
|
186
198
|
}]);
|
|
187
199
|
postRun.push(() => {
|
|
188
|
-
object
|
|
200
|
+
Object.defineProperty(object, r[0], {
|
|
201
|
+
value: r[1],
|
|
202
|
+
enumerable: true,
|
|
203
|
+
configurable: true,
|
|
204
|
+
writable: true
|
|
205
|
+
});
|
|
189
206
|
});
|
|
190
207
|
}
|
|
191
208
|
set(object);
|
|
@@ -195,5 +212,8 @@ function hydrate(index) {
|
|
|
195
212
|
while (postRun.length > 0) postRun.pop()();
|
|
196
213
|
return result;
|
|
197
214
|
}
|
|
215
|
+
function validateIndex(index, length) {
|
|
216
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= length) throw new SyntaxError();
|
|
217
|
+
}
|
|
198
218
|
//#endregion
|
|
199
219
|
export { unflatten };
|
|
@@ -6,9 +6,6 @@ title: Backend For Frontend
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
While React Router can serve as your fullstack application, it also fits perfectly into the "Backend for Frontend" architecture.
|
|
13
10
|
|
|
14
11
|
The BFF strategy employs a web server with a job scoped to serving the frontend web app and connecting it to the services it needs: your database, mailer, job queues, existing backend APIs (REST, GraphQL), etc. Instead of your UI integrating directly from the browser to these services, it connects to the BFF, and the BFF connects to your services.
|
|
@@ -6,9 +6,6 @@ title: Automatic Code Splitting
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
When using React Router's framework features, your application is automatically code split to improve the performance of initial load times when users visit your application.
|
|
13
10
|
|
|
14
11
|
## Code Splitting by Route
|
|
@@ -6,9 +6,6 @@ title: Network Concurrency Management
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
When building web applications, managing network requests can be a daunting task. The challenges of ensuring up-to-date data and handling simultaneous requests often lead to complex logic in the application to deal with interruptions and race conditions. React Router simplifies this process by automating network management while mirroring and expanding upon the intuitive behavior of web browsers.
|
|
13
10
|
|
|
14
11
|
To help understand how React Router handles concurrency, it's important to remember that after `form` submissions, React Router will fetch fresh data from the `loader`s. This is called revalidation.
|
|
@@ -6,9 +6,6 @@ title: Hot Module Replacement
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Hot Module Replacement is a technique for updating modules in your app without needing to reload the page.
|
|
13
10
|
It's a great developer experience, and React Router supports it when using Vite.
|
|
14
11
|
|
|
@@ -6,9 +6,6 @@ title: Lazy Route Discovery
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Lazy Route Discovery is a performance optimization that loads route information progressively as users navigate through your application, rather than loading the complete route manifest upfront.
|
|
13
10
|
|
|
14
11
|
With Lazy Route Discovery enabled (the default), React Router sends only the routes needed for the initial server-side render in the manifest. As users navigate to new parts of your application, additional route information is fetched dynamically and added to the client-side manifest.
|
|
@@ -6,9 +6,6 @@ title: Progressive Enhancement
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
> Progressive enhancement is a strategy in web design that puts emphasis on web content first, allowing everyone to access the basic content and functionality of a web page, whilst users with additional browser features or faster Internet access receive the enhanced version instead.
|
|
13
10
|
>
|
|
14
11
|
> <cite>- [Wikipedia][wikipedia]</cite>
|
|
@@ -6,9 +6,6 @@ title: Race Conditions
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
While impossible to eliminate every possible race condition in your application, React Router automatically handles the most common race conditions found in web user interfaces.
|
|
13
10
|
|
|
14
11
|
## Browser Behavior
|
|
@@ -6,9 +6,6 @@ title: React Transitions
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data, declarative]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
[React 18][react-18] introduced the concept of "transitions" which allow you to differentiate urgent from non-urgent UI updates. To learn more about React Transitions and "concurrent rendering" Please refer to React's official documentation:
|
|
13
10
|
|
|
14
11
|
- [What is Concurrent React][concurrent]
|
|
@@ -324,7 +324,7 @@ React Router makes it easy to store sessions in your own database if needed. The
|
|
|
324
324
|
- `createData` will be called from `commitSession` on the initial session creation when no session ID exists in the cookie
|
|
325
325
|
- `readData` will be called from `getSession` when a session ID exists in the cookie
|
|
326
326
|
- `updateData` will be called from `commitSession` when a session ID already exists in the cookie
|
|
327
|
-
- `deleteData` is called from `destroySession`
|
|
327
|
+
- `deleteData` is called from `destroySession` when the session has an ID
|
|
328
328
|
|
|
329
329
|
The following example shows how you could do this using a generic database client:
|
|
330
330
|
|
|
@@ -6,9 +6,6 @@ title: State Management
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
State management in React typically involves maintaining a synchronized cache of server data on the client side. However, when using React Router as your framework, most of the traditional caching solutions become redundant because of how it inherently handles data synchronization.
|
|
13
10
|
|
|
14
11
|
## Understanding State Management in React
|
|
@@ -6,9 +6,6 @@ title: Styling
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Framework mode uses the React Router Vite plugin, so the styling story is mostly just Vite's styling story.
|
|
13
10
|
|
|
14
11
|
React Router does not have a separate CSS pipeline for Framework mode. In practice, there are three patterns that matter:
|
|
@@ -6,9 +6,6 @@ title: Type Safety
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
If you haven't done so already, check out our guide for [setting up type safety][route-module-type-safety] in a new project.
|
|
13
10
|
|
|
14
11
|
React Router generates types for each route in your app to provide type safety for the route module exports.
|
|
@@ -12,9 +12,6 @@ React Router makes certain accessibility practices the default where possible an
|
|
|
12
12
|
|
|
13
13
|
[MODES: framework, data, declarative]
|
|
14
14
|
|
|
15
|
-
<br/>
|
|
16
|
-
<br/>
|
|
17
|
-
|
|
18
15
|
The [`<Link>` component][link] renders a standard anchor tag, meaning that you get its accessibility behaviors from the browser for free!
|
|
19
16
|
|
|
20
17
|
React Router also provides the [`<NavLink/>`][navlink] which behaves the same as `<Link>`, but it also provides context for assistive technology when the link points to the current page. This is useful for building navigation menus or breadcrumbs.
|
|
@@ -23,9 +20,6 @@ React Router also provides the [`<NavLink/>`][navlink] which behaves the same as
|
|
|
23
20
|
|
|
24
21
|
[MODES: framework]
|
|
25
22
|
|
|
26
|
-
<br/>
|
|
27
|
-
<br/>
|
|
28
|
-
|
|
29
23
|
If you are rendering [`<Scripts>`][scripts] in your app, there are some important things to consider to make client-side routing more accessible for your users.
|
|
30
24
|
|
|
31
25
|
With a traditional multi-page website we don't have to think about route changes too much. Your app renders an anchor tag, and the browser handles the rest. If your users disable JavaScript, your React Router app should already work this way by default!
|
|
@@ -6,9 +6,6 @@ title: Client Data
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
You can fetch and mutate data directly in the browser using `clientLoader` and `clientAction` functions.
|
|
13
10
|
|
|
14
11
|
These functions are the primary mechanism for data handling when using [SPA mode][spa]. This guide demonstrates common use cases for leveraging client data in Server-Side Rendering (SSR).
|
|
@@ -6,9 +6,6 @@ title: Data Strategy
|
|
|
6
6
|
|
|
7
7
|
[MODES: data]
|
|
8
8
|
|
|
9
|
-
<br />
|
|
10
|
-
<br />
|
|
11
|
-
|
|
12
9
|
<docs-warning>This is a low-level API intended for advanced use-cases. This overrides React Router's internal handling of `action`/`loader` execution, and if done incorrectly will break your app code. Please use with caution and perform the appropriate testing.</docs-warning>
|
|
13
10
|
|
|
14
11
|
## Overview
|
|
@@ -6,9 +6,6 @@ title: Error Boundaries
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
To avoid rendering an empty page to users, route modules will automatically catch errors in your code and render the closest `ErrorBoundary`.
|
|
13
10
|
|
|
14
11
|
Error boundaries are not intended for rendering form validation errors or error reporting. Please see [Form Validation](./form-validation) and [Error Reporting](./error-reporting) instead.
|
|
@@ -6,9 +6,6 @@ title: Error Reporting
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework,data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
React Router catches errors in your route modules and sends them to [error boundaries](./error-boundary) to prevent blank pages when errors occur. However, `ErrorBoundary` isn't sufficient for logging and reporting errors.
|
|
13
10
|
|
|
14
11
|
## Server Errors
|
package/docs/how-to/fetchers.md
CHANGED
|
@@ -6,9 +6,6 @@ title: Using Fetchers
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Fetchers are useful for creating complex, dynamic user interfaces that require multiple, concurrent data interactions without causing a navigation.
|
|
13
10
|
|
|
14
11
|
Fetchers track their own, independent state and can be used to load data, mutate data, submit forms, and generally interact with loaders and actions.
|
|
@@ -6,9 +6,6 @@ title: File Uploads
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
_Thank you to David Adams for [writing an original guide](https://programmingarehard.com/2024/09/06/remix-file-uploads-updated.html/) on which this doc is based. You can refer to it for even more examples._
|
|
13
10
|
|
|
14
11
|
## Basic File Upload
|
|
@@ -6,9 +6,6 @@ title: Form Validation
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
This guide walks through a simple signup form implementation. You will likely want to pair these concepts with third-party validation libraries and error components, but this guide only focuses on the moving pieces for React Router.
|
|
13
10
|
|
|
14
11
|
## 1. Setting Up
|