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
package/docs/how-to/headers.md
CHANGED
|
@@ -6,9 +6,6 @@ title: HTTP Headers
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
## Reading request headers
|
|
13
10
|
|
|
14
11
|
The `request` sent to route handlers is a standard Web Fetch [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request), so you can read headers directly from the [`request.headers`](https://developer.mozilla.org/en-US/docs/Web/API/Request/headers) property:
|
|
@@ -6,9 +6,6 @@ title: Instrumentation
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Instrumentation allows you to add logging, error reporting, and performance tracing to your React Router application without modifying your actual route handlers. This enables comprehensive observability solutions for production applications on both the server and client.
|
|
13
10
|
|
|
14
11
|
## Overview
|
|
@@ -6,9 +6,6 @@ title: Middleware
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Middleware allows you to run code before and after the [`Response`][Response] generation for the matched path. This enables [common patterns][common-patterns] like authentication, logging, error handling, and data preprocessing in a reusable way.
|
|
13
10
|
|
|
14
11
|
Middleware runs in a nested chain, executing from parent routes to child routes on the way "down" to your route handlers, then from child routes back to parent routes on the way "up" after a [`Response`][Response] is generated.
|
|
@@ -474,6 +471,12 @@ Which `ErrorBoundary` is rendered will differ based on whether your middleware t
|
|
|
474
471
|
|
|
475
472
|
### Authentication
|
|
476
473
|
|
|
474
|
+
Middleware on a protected route or a common ancestor can authenticate and authorize a request before the matched loaders and actions run.
|
|
475
|
+
|
|
476
|
+
Loaders run in parallel and can be requested independently, so parent loaders are not capable of "protecting" child route loaders or actions. Each protected loader and action must perform its own checks unless appropriate server middleware enforces them before the handler runs.
|
|
477
|
+
|
|
478
|
+
<docs-warning>Attach authorization middleware to the protected route or layout instead of gating its checks with literal pathname-prefix comparisons such as `url.pathname.startsWith("/admin")`. Literal checks may miss potential URL encodings that React Router route matching would cover.</docs-warning>
|
|
479
|
+
|
|
477
480
|
```tsx filename=app/middleware/auth.ts
|
|
478
481
|
import { redirect } from "react-router";
|
|
479
482
|
import { userContext } from "~/context";
|
|
@@ -6,9 +6,6 @@ title: Revalidation Optimization
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
After a mutation or some navigations, React Router re-runs loaders so
|
|
13
10
|
the UI stays in sync with the server. That default is the right
|
|
14
11
|
starting point. When a loader is expensive, or a mutation cannot
|
package/docs/how-to/presets.md
CHANGED
|
@@ -7,9 +7,6 @@ unstable: true
|
|
|
7
7
|
|
|
8
8
|
[MODES: framework, data]
|
|
9
9
|
|
|
10
|
-
<br/>
|
|
11
|
-
<br/>
|
|
12
|
-
|
|
13
10
|
<docs-warning>React Server Components support is experimental and subject to breaking changes in
|
|
14
11
|
minor/patch releases. Please use with caution and pay **very** close attention
|
|
15
12
|
to release notes for relevant changes.</docs-warning>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
2
|
+
title: Route Discovery
|
|
3
3
|
unstable: true
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# Route Discovery
|
|
7
7
|
|
|
8
8
|
[MODES: framework]
|
|
9
9
|
|
|
@@ -21,6 +21,8 @@ export default {
|
|
|
21
21
|
|
|
22
22
|
Without this flag, React Router keeps its existing discovery implementation and the hook is unavailable. The flag supports conventional Framework Mode only.
|
|
23
23
|
|
|
24
|
+
Enabling the flag does not require a custom implementation or a call to `unstable_useRouteDiscovery`. React Router continues to discover routes automatically and uses its built-in manifest-mismatch recovery unless you provide a custom `onManifestMismatch` handler.
|
|
25
|
+
|
|
24
26
|
Keep `routeDiscovery.mode: "lazy"` (the default for SSR) and use `unstable_useRouteDiscovery` to choose when to discover destinations or load the complete route manifest.
|
|
25
27
|
|
|
26
28
|
```tsx
|
|
@@ -6,9 +6,6 @@ title: Route Module Type Safety
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
React Router generates route-specific types to power type inference for URL params, loader data, and more.
|
|
13
10
|
This guide will help you set it up if you didn't start with a template.
|
|
14
11
|
|
package/docs/how-to/security.md
CHANGED
|
@@ -6,9 +6,6 @@ title: Security
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
This is by no means a comprehensive guide, but React Router provides features to help address a few aspects under the _very large_ umbrella that is _Security_.
|
|
13
10
|
|
|
14
11
|
## `Content-Security-Policy`
|
|
@@ -6,9 +6,6 @@ title: Server Bundles
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
<docs-warning>This is an advanced feature designed for hosting provider integrations. When compiling your app into multiple server bundles, there will need to be a custom routing layer in front of your app directing requests to the correct bundle.</docs-warning>
|
|
13
10
|
|
|
14
11
|
React Router typically builds your server code into a single bundle that exports a request handler function. However, there are scenarios where you might want to split your route tree into multiple server bundles, each exposing a request handler function for a subset of routes. To provide this flexibility, [`react-router.config.ts`][react-router-config] supports a `serverBundles` option, which is a function for assigning routes to different server bundles.
|
package/docs/how-to/spa.md
CHANGED
|
@@ -6,9 +6,6 @@ title: Single Page App (SPA)
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
<docs-info>This guide focuses on how to build Single Page Apps with React Router Framework mode. If you're using React Router in declarative or data mode, you can design your own SPA architecture.</docs-info>
|
|
13
10
|
|
|
14
11
|
When using React Router as a framework, you can enable "SPA Mode" by setting `ssr:false` in your `react-router.config.ts` file. This will disable runtime server rendering and generate an `index.html` at build time that you can serve and hydrate as a SPA.
|
package/docs/how-to/status.md
CHANGED
package/docs/how-to/suspense.md
CHANGED
|
@@ -6,9 +6,6 @@ title: Streaming with Suspense
|
|
|
6
6
|
|
|
7
7
|
[MODES: framework, data]
|
|
8
8
|
|
|
9
|
-
<br/>
|
|
10
|
-
<br/>
|
|
11
|
-
|
|
12
9
|
Streaming with React Suspense allows apps to speed up initial renders by deferring non-critical data and unblocking UI rendering.
|
|
13
10
|
|
|
14
11
|
React Router supports React Suspense by returning promises from loaders and actions.
|
|
@@ -66,9 +63,28 @@ export default function MyComponent({
|
|
|
66
63
|
}
|
|
67
64
|
```
|
|
68
65
|
|
|
69
|
-
##
|
|
66
|
+
## Opt into React's `use()` API
|
|
67
|
+
|
|
68
|
+
<docs-warning>The `unstable_promise` prop is experimental and may change in minor or patch releases.</docs-warning>
|
|
69
|
+
|
|
70
|
+
Use `<Await unstable_promise>` instead of `<Await resolve>` to opt into `React.use` under the hood while keeping the Await API:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
<React.Suspense fallback={<div>Loading...</div>}>
|
|
74
|
+
<Await
|
|
75
|
+
unstable_promise={nonCriticalData}
|
|
76
|
+
errorElement={<LoadingError />}
|
|
77
|
+
>
|
|
78
|
+
{(value) => <h3>Non critical value: {value}</h3>}
|
|
79
|
+
</Await>
|
|
80
|
+
</React.Suspense>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This should largely behave the same as `<Await resolve>` while avoiding the legacy React Router promise tracking. Both support render-prop children, `useAsyncValue`, and `useAsyncError`. One notable difference with `unstable_promise` is that `errorElement` only handles promise rejections. Errors thrown while rendering children bubble to the nearest React error boundary.
|
|
84
|
+
|
|
85
|
+
## Use React directly
|
|
70
86
|
|
|
71
|
-
|
|
87
|
+
You can also read the promise directly with `React.use`. Pass it to a child component rendered inside `<React.Suspense>` so the boundary can display its fallback while the promise is pending.
|
|
72
88
|
|
|
73
89
|
```tsx
|
|
74
90
|
<React.Suspense fallback={<div>Loading...</div>}>
|
|
@@ -94,7 +110,7 @@ export const streamTimeout = 10_000;
|
|
|
94
110
|
|
|
95
111
|
## Handling early rejections (Node)
|
|
96
112
|
|
|
97
|
-
React Router waits for all loaders to settle (via `Promise.all`) before it begins streaming the response. Once streaming has started, React Router catches subsequent rejections of your streamed promises and surfaces them to your `<Await>` (or
|
|
113
|
+
React Router waits for all loaders to settle (via `Promise.all`) before it begins streaming the response. Once streaming has started, React Router catches subsequent rejections of your streamed promises and surfaces them to your `<Await>` (or `React.use`) error UI.
|
|
98
114
|
|
|
99
115
|
However, if a streamed promise rejects _before_ all of the route's loaders have settled, React Router has not yet been able to attach a handler to it. In Node, an unhandled promise rejection will crash the process unless you have a top-level handler registered.
|
|
100
116
|
|
|
@@ -80,6 +80,14 @@ export default function Product({
|
|
|
80
80
|
|
|
81
81
|
Note that the `loader` function is removed from client bundles so you can use server only APIs without worrying about them being included in the browser.
|
|
82
82
|
|
|
83
|
+
### Authentication and Authorization
|
|
84
|
+
|
|
85
|
+
React Router runs matched route loaders in parallel and loaders can be requested independently, such as during fetcher calls or navigations that do not revalidate every matched route. Therefore it is not possible for a parent loader to "protect" child route loaders or actions via authentication checks.
|
|
86
|
+
|
|
87
|
+
Unless guarded by appropriate [server middleware][auth-middleware], each protected loader and action must authenticate the request and authorize access to the data or operation before proceeding. For example, checking that a user is signed in does not establish that they have permission to access the requested project.
|
|
88
|
+
|
|
89
|
+
Middleware on a protected route or a common ancestor can enforce shared checks before the protected loaders and actions run. Any permissions not enforced by that middleware must still be checked in the individual loader or action.
|
|
90
|
+
|
|
83
91
|
## Static Data Loading
|
|
84
92
|
|
|
85
93
|
When pre-rendering, loaders are used to fetch data during the production build.
|
|
@@ -199,3 +207,4 @@ See also:
|
|
|
199
207
|
[streaming]: ../../how-to/suspense
|
|
200
208
|
[client-data]: ../../how-to/client-data
|
|
201
209
|
[fetchers]: ../../how-to/fetchers#loading-data
|
|
210
|
+
[auth-middleware]: ../../how-to/middleware#authentication
|
package/docs/upgrading/future.md
CHANGED
|
@@ -17,9 +17,6 @@ We highly recommend you make a commit after each step and ship it instead of doi
|
|
|
17
17
|
|
|
18
18
|
[MODES: framework, data, declarative]
|
|
19
19
|
|
|
20
|
-
<br/>
|
|
21
|
-
<br/>
|
|
22
|
-
|
|
23
20
|
React Router v9 will require the following minimum versions (as of now). You can prepare for the upgrade by updating them while still on v8:
|
|
24
21
|
|
|
25
22
|
- `node@24+`
|
|
@@ -50,9 +47,6 @@ We document some [unstable] flags here as a reference for folks contributing to
|
|
|
50
47
|
|
|
51
48
|
[MODES: framework]
|
|
52
49
|
|
|
53
|
-
<br/>
|
|
54
|
-
<br/>
|
|
55
|
-
|
|
56
50
|
**Background**
|
|
57
51
|
|
|
58
52
|
Now that the Web Streams API is [stable](https://nodejs.org/docs/latest-v22.x/api/webstreams.html) in Node 22+, it's viable for React Router to use React's [`renderToReadableStream`](https://react.dev/reference/react-dom/server/renderToReadableStream) in the server entry.
|
|
@@ -83,9 +77,6 @@ No code changes are required. If your app has a custom `entry.server.tsx`, this
|
|
|
83
77
|
|
|
84
78
|
[MODES: framework]
|
|
85
79
|
|
|
86
|
-
<br/>
|
|
87
|
-
<br/>
|
|
88
|
-
|
|
89
80
|
**Background**
|
|
90
81
|
|
|
91
82
|
This flag lets React Router provide Vite's dependency optimizer with the client entry file and route module files. This can improve dependency optimization in development, but the behavior is still experimental.
|
|
@@ -110,9 +101,6 @@ No code changes are required. If you run into dependency optimization issues aft
|
|
|
110
101
|
|
|
111
102
|
[MODES: data]
|
|
112
103
|
|
|
113
|
-
<br/>
|
|
114
|
-
<br/>
|
|
115
|
-
|
|
116
104
|
**Background**
|
|
117
105
|
|
|
118
106
|
This flag opts Data Routers into a new (and vastly more efficient) route matcher
|
package/docs/upgrading/v7.md
CHANGED
|
@@ -13,9 +13,6 @@ We highly recommend you make a commit after each step and ship it instead of doi
|
|
|
13
13
|
|
|
14
14
|
[MODES: framework, data, declarative]
|
|
15
15
|
|
|
16
|
-
<br/>
|
|
17
|
-
<br/>
|
|
18
|
-
|
|
19
16
|
React Router v8 requires the following minimum versions. Update them before updating React Router to v8:
|
|
20
17
|
|
|
21
18
|
- `node@22.22+`
|
|
@@ -42,9 +39,6 @@ npm install react-router@7 @react-router/{dev,node,etc.}@7
|
|
|
42
39
|
|
|
43
40
|
[MODES: framework, data]
|
|
44
41
|
|
|
45
|
-
<br/>
|
|
46
|
-
<br/>
|
|
47
|
-
|
|
48
42
|
**Background**
|
|
49
43
|
|
|
50
44
|
Middleware allows you to run code before and after the [`Response`][Response] generation for the matched path. This enables common patterns like authentication, logging, error handling, and data preprocessing in a reusable way. Please see the [docs](../how-to/middleware) for more information.
|
|
@@ -86,9 +80,6 @@ If you're using the `context` parameter in `loader` and `action` functions, you
|
|
|
86
80
|
|
|
87
81
|
[MODES: framework]
|
|
88
82
|
|
|
89
|
-
<br/>
|
|
90
|
-
<br/>
|
|
91
|
-
|
|
92
83
|
**Background**
|
|
93
84
|
|
|
94
85
|
This feature enables splitting client-side route exports (`clientLoader`, `clientAction`, `clientMiddleware`, `HydrateFallback`) into separate chunks that can be loaded independently from the route component. This allows these exports to be fetched and executed while the component code is still downloading, improving performance for client-side data loading.
|
|
@@ -115,9 +106,6 @@ No code changes are required. This is an optimization feature that works automat
|
|
|
115
106
|
|
|
116
107
|
[MODES: framework]
|
|
117
108
|
|
|
118
|
-
<br/>
|
|
119
|
-
<br/>
|
|
120
|
-
|
|
121
109
|
**Background**
|
|
122
110
|
|
|
123
111
|
This enables support for the experimental Vite Environment API, which provides a more flexible and powerful way to configure Vite environments. This is only available when using Vite 6+.
|
|
@@ -173,9 +161,6 @@ See the [`node-custom-server` template][node-custom-server-template] for a compl
|
|
|
173
161
|
|
|
174
162
|
[MODES: framework]
|
|
175
163
|
|
|
176
|
-
<br/>
|
|
177
|
-
<br/>
|
|
178
|
-
|
|
179
164
|
**Background**
|
|
180
165
|
|
|
181
166
|
By default, React Router normalizes the `request.url` passed to your `loader`, `action`, and `middleware` functions by removing React Router's internal implementation details. Specifically, it removes `.data` suffixes and internal search parameters like `?index` and `?_routes`.
|
|
@@ -185,7 +170,7 @@ This flag eliminates that normalization and passes the raw HTTP `request` instan
|
|
|
185
170
|
- Reduces server-side overhead by eliminating multiple `new Request()` calls on the critical path
|
|
186
171
|
- Allows you to distinguish document from data requests in your handlers based on the presence of a `.data` suffix (useful for [observability] purposes)
|
|
187
172
|
|
|
188
|
-
If you were previously relying on the normalization of `request.url`, you can switch to use the new sibling `url` parameter which contains a `URL` instance
|
|
173
|
+
If you were previously relying on the normalization of `request.url`, you can switch to use the new sibling `url` parameter which contains a `URL` instance with React Router's internal implementation details removed.
|
|
189
174
|
|
|
190
175
|
👉 **Enable the Flag**
|
|
191
176
|
|
|
@@ -215,8 +200,8 @@ export async function loader({
|
|
|
215
200
|
}
|
|
216
201
|
}
|
|
217
202
|
|
|
218
|
-
// ✅ After: use `url`
|
|
219
|
-
// for
|
|
203
|
+
// ✅ After: use `url` with React Router's internal details removed
|
|
204
|
+
// and `request.url` for the original request URL
|
|
220
205
|
export async function loader({
|
|
221
206
|
request,
|
|
222
207
|
url,
|
|
@@ -236,9 +221,6 @@ export async function loader({
|
|
|
236
221
|
|
|
237
222
|
[MODES: framework]
|
|
238
223
|
|
|
239
|
-
<br/>
|
|
240
|
-
<br/>
|
|
241
|
-
|
|
242
224
|
**Background**
|
|
243
225
|
|
|
244
226
|
React Router serves Framework mode data requests from `.data` URLs. Previously, data requests for routes with and without trailing slashes could map to the same `.data` URL because trailing slashes were not considered during URL generation. This flag preserves trailing slash semantics for data request URLs to avoid ambiguity when your app distinguishes between trailing-slash and non-trailing-slash URLs.
|
|
@@ -293,9 +275,6 @@ The changes in this section are not controlled by future flags, but you can upda
|
|
|
293
275
|
|
|
294
276
|
[MODES: framework]
|
|
295
277
|
|
|
296
|
-
<br/>
|
|
297
|
-
<br/>
|
|
298
|
-
|
|
299
278
|
**Background**
|
|
300
279
|
|
|
301
280
|
React Router v8 removed deprecated `data` fields in favor of `loaderData` in a few places:
|
|
@@ -352,9 +331,6 @@ export default function Component({ matches, loaderData }: ComponentProps) {
|
|
|
352
331
|
|
|
353
332
|
[MODES: framework, data, declarative]
|
|
354
333
|
|
|
355
|
-
<br/>
|
|
356
|
-
<br/>
|
|
357
|
-
|
|
358
334
|
**Background**
|
|
359
335
|
|
|
360
336
|
React Router v8 removes the `react-router-dom` re-export package. In v8, you should import DOM-specific APIs from `react-router/dom` and everything else from `react-router`.
|
|
@@ -385,9 +361,6 @@ For DOM-specific APIs, import from `react-router/dom`:
|
|
|
385
361
|
|
|
386
362
|
[MODES: framework]
|
|
387
363
|
|
|
388
|
-
<br/>
|
|
389
|
-
<br/>
|
|
390
|
-
|
|
391
364
|
**Background**
|
|
392
365
|
|
|
393
366
|
React Router v8 removes the React Router Cloudflare dev proxy. Cloudflare projects should use [`@cloudflare/vite-plugin`][cloudflare-vite-plugin] instead.
|
|
@@ -415,9 +388,6 @@ export default defineConfig({
|
|
|
415
388
|
|
|
416
389
|
[MODES: framework]
|
|
417
390
|
|
|
418
|
-
<br/>
|
|
419
|
-
<br/>
|
|
420
|
-
|
|
421
391
|
**Background**
|
|
422
392
|
|
|
423
393
|
In v7, the `@react-router/architect` adapter uses `X-Forwarded-Host` when creating the `request`, falling back to the `Host` header. In React Router v8, the adapter uses `event.requestContext.domainName` by default, falling back to the `Host` header.
|
|
@@ -450,9 +420,20 @@ npm install react-router@latest
|
|
|
450
420
|
npm install react-router@latest @react-router/{dev,node,etc.}@latest
|
|
451
421
|
```
|
|
452
422
|
|
|
423
|
+
Then remove the `future.v8_*` flags, since their behavior is now the default. In Framework Mode, React Router reports an error if they are still in `react-router.config.ts`. If you set `future.v8_splitRouteModules`, use the top-level [`splitRouteModules`][split-route-modules-config] option instead (it defaults to `true`, so you only need it for `false` or `"enforce"`):
|
|
424
|
+
|
|
425
|
+
```ts filename=react-router.config.ts
|
|
426
|
+
import type { Config } from "@react-router/dev/config";
|
|
427
|
+
|
|
428
|
+
export default {
|
|
429
|
+
splitRouteModules: "enforce",
|
|
430
|
+
} satisfies Config;
|
|
431
|
+
```
|
|
432
|
+
|
|
453
433
|
Congratulations, you're now on v8!
|
|
454
434
|
|
|
455
435
|
[api-development-strategy]: ../community/api-development-strategy
|
|
436
|
+
[split-route-modules-config]: ../api/framework-conventions/react-router.config.ts#splitroutemodules
|
|
456
437
|
[observability]: ../how-to/instrumentation
|
|
457
438
|
[Response]: https://developer.mozilla.org/en-US/docs/Web/API/Response
|
|
458
439
|
[vite-environment]: https://vite.dev/guide/api-environment
|
package/package.json
CHANGED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { HydrationState, Router } from "../router/router.js";
|
|
3
|
-
import { RouteModules } from "./ssr/routeModules.js";
|
|
4
|
-
import { ServerHandoff } from "../server-runtime/serverHandoff.js";
|
|
5
|
-
import { AssetsManifest } from "./ssr/entry.js";
|
|
6
|
-
|
|
7
|
-
//#region lib/dom/global.d.ts
|
|
8
|
-
type WindowReactRouterContext = ServerHandoff & {
|
|
9
|
-
state: HydrationState;
|
|
10
|
-
stream: ReadableStream<Uint8Array> | undefined;
|
|
11
|
-
streamController: ReadableStreamDefaultController<Uint8Array>;
|
|
12
|
-
};
|
|
13
|
-
interface ViewTransition {
|
|
14
|
-
finished: Promise<void>;
|
|
15
|
-
ready: Promise<void>;
|
|
16
|
-
updateCallbackDone: Promise<void>;
|
|
17
|
-
skipTransition(): void;
|
|
18
|
-
}
|
|
19
|
-
declare global {
|
|
20
|
-
var __staticRouterHydrationData: HydrationState | undefined;
|
|
21
|
-
var __reactRouterVersion: string;
|
|
22
|
-
interface Document {
|
|
23
|
-
startViewTransition(cb: () => Promise<void> | void): ViewTransition;
|
|
24
|
-
}
|
|
25
|
-
var __reactRouterContext: WindowReactRouterContext | undefined;
|
|
26
|
-
var __reactRouterManifest: AssetsManifest | undefined;
|
|
27
|
-
var __reactRouterRouteModules: RouteModules | undefined;
|
|
28
|
-
var __reactRouterDataRouter: Router | undefined;
|
|
29
|
-
var __reactRouterHdrActive: boolean;
|
|
30
|
-
var $RefreshRuntime$: {
|
|
31
|
-
performReactRefresh: () => void;
|
|
32
|
-
} | undefined;
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { WindowReactRouterContext };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { HydrationState, Router } from "../router/router.js";
|
|
3
|
-
import { RouteModules } from "./ssr/routeModules.js";
|
|
4
|
-
import { ServerHandoff } from "../server-runtime/serverHandoff.js";
|
|
5
|
-
import { AssetsManifest } from "./ssr/entry.js";
|
|
6
|
-
|
|
7
|
-
//#region lib/dom/global.d.ts
|
|
8
|
-
type WindowReactRouterContext = ServerHandoff & {
|
|
9
|
-
state: HydrationState;
|
|
10
|
-
stream: ReadableStream<Uint8Array> | undefined;
|
|
11
|
-
streamController: ReadableStreamDefaultController<Uint8Array>;
|
|
12
|
-
};
|
|
13
|
-
interface ViewTransition {
|
|
14
|
-
finished: Promise<void>;
|
|
15
|
-
ready: Promise<void>;
|
|
16
|
-
updateCallbackDone: Promise<void>;
|
|
17
|
-
skipTransition(): void;
|
|
18
|
-
}
|
|
19
|
-
declare global {
|
|
20
|
-
var __staticRouterHydrationData: HydrationState | undefined;
|
|
21
|
-
var __reactRouterVersion: string;
|
|
22
|
-
interface Document {
|
|
23
|
-
startViewTransition(cb: () => Promise<void> | void): ViewTransition;
|
|
24
|
-
}
|
|
25
|
-
var __reactRouterContext: WindowReactRouterContext | undefined;
|
|
26
|
-
var __reactRouterManifest: AssetsManifest | undefined;
|
|
27
|
-
var __reactRouterRouteModules: RouteModules | undefined;
|
|
28
|
-
var __reactRouterDataRouter: Router | undefined;
|
|
29
|
-
var __reactRouterHdrActive: boolean;
|
|
30
|
-
var $RefreshRuntime$: {
|
|
31
|
-
performReactRefresh: () => void;
|
|
32
|
-
} | undefined;
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { WindowReactRouterContext };
|