react-router 8.4.0 → 8.5.1
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 +94 -1
- package/dist/development/dom-export.d.ts +2 -1
- package/dist/development/dom-export.js +1 -1
- package/dist/development/index-react-server-client.js +2 -2
- package/dist/development/index-react-server.d.ts +237 -165
- package/dist/development/index-react-server.js +69 -33
- package/dist/development/index.d.ts +9 -8
- package/dist/development/index.js +5 -4
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/await.js +58 -0
- package/dist/development/lib/components.d.ts +41 -5
- package/dist/development/lib/components.js +82 -5
- package/dist/development/lib/context.d.ts +8 -3
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.d.ts +3 -0
- package/dist/development/lib/dom/dom.js +1 -1
- package/dist/development/lib/dom/lib.d.ts +34 -9
- package/dist/development/lib/dom/lib.js +17 -6
- package/dist/development/lib/dom/server.js +2 -2
- package/dist/development/lib/dom/ssr/components.js +12 -9
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/entry.d.ts +9 -2
- 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.d.ts +3 -2
- package/dist/development/lib/dom/ssr/fog-of-war.js +25 -13
- 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 +120 -0
- package/dist/development/lib/dom/ssr/route-discovery.js +415 -0
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +2 -2
- package/dist/development/lib/dom/ssr/routes.d.ts +2 -2
- package/dist/development/lib/dom/ssr/routes.js +8 -8
- package/dist/development/lib/dom/ssr/server.js +3 -1
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +28 -2
- package/dist/development/lib/dom/ssr/single-fetch.js +73 -55
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.d.ts +28 -0
- package/dist/development/lib/dom-export/hydrated-router.js +32 -12
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.d.ts +3 -6
- package/dist/development/lib/hooks.js +8 -9
- package/dist/development/lib/href.js +1 -1
- 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 +1 -1
- package/dist/development/lib/router/router.d.ts +8 -0
- package/dist/development/lib/router/router.js +213 -91
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +31 -4
- package/dist/development/lib/router/utils.js +4 -3
- package/dist/development/lib/rsc/browser.js +4 -4
- 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 +24 -12
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +3 -2
- package/dist/development/lib/rsc/server.ssr.js +1 -1
- package/dist/development/lib/server-runtime/build.d.ts +14 -0
- 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.d.ts +1 -1
- package/dist/development/lib/server-runtime/routes.js +1 -1
- package/dist/development/lib/server-runtime/server.js +24 -8
- package/dist/development/lib/server-runtime/serverHandoff.d.ts +17 -0
- 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-data.d.ts +2 -2
- 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 +1 -1
- 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.d.ts +2 -1
- package/dist/production/dom-export.js +1 -1
- package/dist/production/index-react-server-client.js +2 -2
- package/dist/production/index-react-server.d.ts +237 -165
- package/dist/production/index-react-server.js +69 -33
- package/dist/production/index.d.ts +9 -8
- package/dist/production/index.js +5 -4
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/await.js +58 -0
- package/dist/production/lib/components.d.ts +41 -5
- package/dist/production/lib/components.js +82 -5
- package/dist/production/lib/context.d.ts +8 -3
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.d.ts +3 -0
- package/dist/production/lib/dom/dom.js +1 -1
- package/dist/production/lib/dom/lib.d.ts +34 -9
- package/dist/production/lib/dom/lib.js +17 -6
- package/dist/production/lib/dom/server.js +2 -2
- package/dist/production/lib/dom/ssr/components.js +12 -9
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/entry.d.ts +9 -2
- 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.d.ts +3 -2
- package/dist/production/lib/dom/ssr/fog-of-war.js +25 -13
- 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 +120 -0
- package/dist/production/lib/dom/ssr/route-discovery.js +415 -0
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +2 -2
- package/dist/production/lib/dom/ssr/routes.d.ts +2 -2
- package/dist/production/lib/dom/ssr/routes.js +8 -8
- package/dist/production/lib/dom/ssr/server.js +3 -1
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +28 -2
- package/dist/production/lib/dom/ssr/single-fetch.js +73 -55
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.d.ts +28 -0
- package/dist/production/lib/dom-export/hydrated-router.js +32 -12
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.d.ts +3 -6
- package/dist/production/lib/hooks.js +7 -8
- package/dist/production/lib/href.js +1 -1
- 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 +1 -1
- package/dist/production/lib/router/router.d.ts +8 -0
- package/dist/production/lib/router/router.js +213 -91
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +31 -4
- package/dist/production/lib/router/utils.js +4 -3
- package/dist/production/lib/rsc/browser.js +4 -4
- 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 +24 -12
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +3 -2
- package/dist/production/lib/rsc/server.ssr.js +1 -1
- package/dist/production/lib/server-runtime/build.d.ts +14 -0
- 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.d.ts +1 -1
- package/dist/production/lib/server-runtime/routes.js +1 -1
- package/dist/production/lib/server-runtime/server.js +24 -8
- package/dist/production/lib/server-runtime/serverHandoff.d.ts +17 -0
- 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-data.d.ts +2 -2
- 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 +1 -1
- 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 +4 -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 +109 -5
- 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/custom-fetch.md +218 -0
- package/docs/how-to/data-strategy.md +23 -4
- 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 +7 -3
- package/docs/how-to/navigation-blocking.md +0 -3
- package/docs/how-to/optimize-revalidation.md +2 -5
- package/docs/how-to/pre-rendering.md +23 -4
- 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 +147 -0
- 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 +2 -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 +79 -15
- package/docs/start/framework/data-loading.md +9 -0
- package/docs/start/framework/navigating.md +5 -9
- package/docs/start/framework/rendering.md +37 -0
- package/docs/upgrading/future.md +0 -12
- package/docs/upgrading/v7.md +3 -33
- package/package.json +9 -1
|
@@ -4,16 +4,75 @@ title: View Transitions
|
|
|
4
4
|
|
|
5
5
|
# View Transitions
|
|
6
6
|
|
|
7
|
-
[MODES: framework, data]
|
|
7
|
+
[MODES: framework, data, declarative]
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
<br/>
|
|
9
|
+
Use React's [`<ViewTransition>`][react-view-transition] component to animate client-side navigations. This requires React and React DOM 19.3 or later.
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
<docs-warning>
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
React Router's `viewTransition` props/options, `useViewTransitionState` hook, and `NavLink`'s `isTransitioning` render prop and `transitioning` class are deprecated in favor of React's `<ViewTransition>` component. The existing APIs continue to work, including with older React versions.
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
</docs-warning>
|
|
16
|
+
|
|
17
|
+
## Navigation View Transitions with React
|
|
18
|
+
|
|
19
|
+
Wrap the outlet in a persistent `<ViewTransition>` boundary in a shared layout route. In Framework Mode, this can be your root route's default export; in Data and Declarative modes, use it as the component for a parent route with children:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { ViewTransition } from "react";
|
|
23
|
+
import { Link, Outlet } from "react-router";
|
|
24
|
+
|
|
25
|
+
export default function PageLayout() {
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
<nav>
|
|
29
|
+
<Link to="/">Home</Link>
|
|
30
|
+
<Link to="/about">About</Link>
|
|
31
|
+
</nav>
|
|
32
|
+
<ViewTransition>
|
|
33
|
+
<main>
|
|
34
|
+
<Outlet />
|
|
35
|
+
</main>
|
|
36
|
+
</ViewTransition>
|
|
37
|
+
</>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Navigations that update the outlet cross-fade its contents. Keep the boundary mounted across navigations; you don't need to key it by location or remount the route tree. The navigation stays outside the animated region. Other updates inside the boundary can also animate when they run in a React Transition.
|
|
43
|
+
|
|
44
|
+
React Router wraps router state updates in [`React.startTransition`][start-transition] by default, which lets React activate `<ViewTransition>` without additional configuration. React Transitions must remain enabled for navigation view transitions to work: do not set `useTransitions={false}` on your router.
|
|
45
|
+
|
|
46
|
+
This applies to navigations from `<Link>`, `<NavLink>`, and `<Form>`, as well as programmatic navigation with `useNavigate` and `useSubmit`. No additional `startTransition` wrapper is needed.
|
|
47
|
+
|
|
48
|
+
### Migrating from React Router's view transitions
|
|
49
|
+
|
|
50
|
+
- Remove `viewTransition` from `<Link>`, `<NavLink>`, and `<Form>`, and remove `viewTransition: true` from navigation/submission options. React coordinates `document.startViewTransition()` itself; enabling both implementations can interrupt animations.
|
|
51
|
+
- Replace `useViewTransitionState`, `isTransitioning`, and `.transitioning` styles with React's [View Transition classes][react-view-transition-classes]. Those router APIs only track the legacy transitions.
|
|
52
|
+
- For shared elements such as an image moving from a list to a detail route, wrap each side in `<ViewTransition name="...">` with the same unique name. See React's [shared element example][react-shared-elements].
|
|
53
|
+
- Keep React Transitions enabled. `useTransitions={false}` and synchronous updates such as `flushSync` can prevent React's animations.
|
|
54
|
+
|
|
55
|
+
React's component is not a drop-in replacement for every legacy animation. In particular, React [skips view transitions for synchronous updates from `popstate`][react-router-transitions], so browser Back/Forward navigations may not animate. Browsers without View Transitions support still navigate normally.
|
|
56
|
+
|
|
57
|
+
Respect reduced-motion preferences when adding animations:
|
|
58
|
+
|
|
59
|
+
```css
|
|
60
|
+
@media (prefers-reduced-motion: reduce) {
|
|
61
|
+
::view-transition-group(*),
|
|
62
|
+
::view-transition-old(*),
|
|
63
|
+
::view-transition-new(*) {
|
|
64
|
+
animation: none !important;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Legacy View Transitions (Deprecated)
|
|
70
|
+
|
|
71
|
+
The following examples document the deprecated APIs for existing applications. These APIs are available in Framework and Data modes.
|
|
72
|
+
|
|
73
|
+
### Basic View Transition
|
|
74
|
+
|
|
75
|
+
#### 1. Enable view transitions on navigation
|
|
17
76
|
|
|
18
77
|
The simplest way to enable view transitions is by adding the `viewTransition` prop to your `Link`, `NavLink`, or `Form` components. This automatically wraps the navigation update in `document.startViewTransition()`.
|
|
19
78
|
|
|
@@ -25,7 +84,7 @@ The simplest way to enable view transitions is by adding the `viewTransition` pr
|
|
|
25
84
|
|
|
26
85
|
Without any additional CSS, this provides a basic cross-fade animation between pages.
|
|
27
86
|
|
|
28
|
-
|
|
87
|
+
#### 2. Enable view transitions with programmatic navigation
|
|
29
88
|
|
|
30
89
|
When using programmatic navigation with the `useNavigate` hook, you can enable view transitions by passing the `viewTransition: true` option:
|
|
31
90
|
|
|
@@ -51,11 +110,11 @@ This provides the same cross-fade animation as using the `viewTransition` prop o
|
|
|
51
110
|
|
|
52
111
|
For more information on using the View Transitions API, please refer to the ["Smooth transitions with the View Transition API" guide][view-transitions-guide] from the Google Chrome team.
|
|
53
112
|
|
|
54
|
-
|
|
113
|
+
### Image Gallery Example
|
|
55
114
|
|
|
56
115
|
Let's build an image gallery that demonstrates how to trigger and use view transitions. We'll create a list of images that expand into a detail view with smooth animations.
|
|
57
116
|
|
|
58
|
-
|
|
117
|
+
#### 1. Create the image gallery route
|
|
59
118
|
|
|
60
119
|
```tsx filename=routes/image-gallery.tsx
|
|
61
120
|
import { NavLink } from "react-router";
|
|
@@ -91,7 +150,7 @@ export default function ImageGalleryRoute() {
|
|
|
91
150
|
}
|
|
92
151
|
```
|
|
93
152
|
|
|
94
|
-
|
|
153
|
+
#### 2. Add transition styles
|
|
95
154
|
|
|
96
155
|
Define view transition names and animations for elements that should transition smoothly between routes.
|
|
97
156
|
|
|
@@ -127,7 +186,7 @@ Define view transition names and animations for elements that should transition
|
|
|
127
186
|
}
|
|
128
187
|
```
|
|
129
188
|
|
|
130
|
-
|
|
189
|
+
#### 3. Create the image detail route
|
|
131
190
|
|
|
132
191
|
The detail view needs to use the same view transition names to create a seamless animation.
|
|
133
192
|
|
|
@@ -151,7 +210,7 @@ export default function ImageDetailsRoute({
|
|
|
151
210
|
}
|
|
152
211
|
```
|
|
153
212
|
|
|
154
|
-
|
|
213
|
+
#### 4. Add matching transition styles for the detail view
|
|
155
214
|
|
|
156
215
|
```css filename=app.css
|
|
157
216
|
/* Match transition names from the list view */
|
|
@@ -169,11 +228,11 @@ export default function ImageDetailsRoute({
|
|
|
169
228
|
}
|
|
170
229
|
```
|
|
171
230
|
|
|
172
|
-
|
|
231
|
+
### Advanced Usage
|
|
173
232
|
|
|
174
233
|
You can control view transitions more precisely using either render props or the `useViewTransitionState` hook.
|
|
175
234
|
|
|
176
|
-
|
|
235
|
+
#### 1. Using render props
|
|
177
236
|
|
|
178
237
|
```tsx filename=routes/image-gallery.tsx
|
|
179
238
|
<NavLink to={`/image/${idx}`} viewTransition>
|
|
@@ -201,7 +260,7 @@ You can control view transitions more precisely using either render props or the
|
|
|
201
260
|
</NavLink>
|
|
202
261
|
```
|
|
203
262
|
|
|
204
|
-
|
|
263
|
+
#### 2. Using the `useViewTransitionState` hook
|
|
205
264
|
|
|
206
265
|
```tsx filename=routes/image-gallery.tsx
|
|
207
266
|
function NavImage(props: { src: string; idx: number }) {
|
|
@@ -234,4 +293,9 @@ function NavImage(props: { src: string; idx: number }) {
|
|
|
234
293
|
```
|
|
235
294
|
|
|
236
295
|
[view-transitions-api]: https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition
|
|
296
|
+
[react-view-transition]: https://react.dev/reference/react/ViewTransition
|
|
297
|
+
[start-transition]: https://react.dev/reference/react/startTransition
|
|
298
|
+
[react-view-transition-classes]: https://react.dev/reference/react/ViewTransition#view-transition-class
|
|
299
|
+
[react-shared-elements]: https://react.dev/reference/react/ViewTransition#animating-a-shared-element
|
|
300
|
+
[react-router-transitions]: https://react.dev/reference/react/ViewTransition#building-view-transition-enabled-routers
|
|
237
301
|
[view-transitions-guide]: https://developer.chrome.com/docs/web-platform/view-transitions
|
|
@@ -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
|
|
@@ -44,10 +44,6 @@ a.active {
|
|
|
44
44
|
a.pending {
|
|
45
45
|
animate: pulse 1s infinite;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
a.transitioning {
|
|
49
|
-
/* css transition is running */
|
|
50
|
-
}
|
|
51
47
|
```
|
|
52
48
|
|
|
53
49
|
It also has callback props on `className`, `style`, and `children` with the states for inline styling or conditional rendering:
|
|
@@ -56,11 +52,10 @@ It also has callback props on `className`, `style`, and `children` with the stat
|
|
|
56
52
|
// className
|
|
57
53
|
<NavLink
|
|
58
54
|
to="/messages"
|
|
59
|
-
className={({ isActive, isPending
|
|
55
|
+
className={({ isActive, isPending }) =>
|
|
60
56
|
[
|
|
61
57
|
isPending ? "pending" : "",
|
|
62
58
|
isActive ? "active" : "",
|
|
63
|
-
isTransitioning ? "transitioning" : "",
|
|
64
59
|
].join(" ")
|
|
65
60
|
}
|
|
66
61
|
>
|
|
@@ -72,11 +67,10 @@ It also has callback props on `className`, `style`, and `children` with the stat
|
|
|
72
67
|
// style
|
|
73
68
|
<NavLink
|
|
74
69
|
to="/messages"
|
|
75
|
-
style={({ isActive, isPending
|
|
70
|
+
style={({ isActive, isPending }) => {
|
|
76
71
|
return {
|
|
77
72
|
fontWeight: isActive ? "bold" : "",
|
|
78
73
|
color: isPending ? "red" : "black",
|
|
79
|
-
viewTransitionName: isTransitioning ? "slide" : "",
|
|
80
74
|
};
|
|
81
75
|
}}
|
|
82
76
|
>
|
|
@@ -87,12 +81,14 @@ It also has callback props on `className`, `style`, and `children` with the stat
|
|
|
87
81
|
```tsx
|
|
88
82
|
// children
|
|
89
83
|
<NavLink to="/tasks">
|
|
90
|
-
{({ isActive
|
|
84
|
+
{({ isActive }) => (
|
|
91
85
|
<span className={isActive ? "active" : ""}>Tasks</span>
|
|
92
86
|
)}
|
|
93
87
|
</NavLink>
|
|
94
88
|
```
|
|
95
89
|
|
|
90
|
+
For animated navigations, see [View Transitions](../../how-to/view-transitions). The legacy `isTransitioning` render prop and `transitioning` class are deprecated in favor of React's `<ViewTransition>` component.
|
|
91
|
+
|
|
96
92
|
## Link
|
|
97
93
|
|
|
98
94
|
Use `<Link>` when the link doesn't need active styling:
|
|
@@ -54,6 +54,43 @@ export default {
|
|
|
54
54
|
|
|
55
55
|
Pre-rendering is a build-time operation that generates static HTML and client navigation data payloads for a list of URLs. This is useful for SEO and performance, especially for deployments without server rendering. When pre-rendering, route module loaders are used to fetch data at build time.
|
|
56
56
|
|
|
57
|
+
## API-only Mode (unstable)
|
|
58
|
+
|
|
59
|
+
<docs-warning>API-only Mode is experimental and may change in minor or patch releases. It is not supported in RSC Framework Mode.</docs-warning>
|
|
60
|
+
|
|
61
|
+
Set `ssr: "unstable_api-only"` to keep a runtime server for loaders, actions, and route discovery while disabling production server-side document rendering:
|
|
62
|
+
|
|
63
|
+
```ts filename=react-router.config.ts
|
|
64
|
+
import type { Config } from "@react-router/dev/config";
|
|
65
|
+
|
|
66
|
+
export default {
|
|
67
|
+
ssr: "unstable_api-only",
|
|
68
|
+
} satisfies Config;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Without prerendering, the build generates a root-only `index.html` shell using the root `HydrateFallback`, like [SPA Mode](../../how-to/spa). The browser fetches server loader data as it initializes the page. Routes can use server `loader` and `action` exports without requiring `clientLoader` or `clientAction` wrappers. Lazy route discovery remains enabled by default.
|
|
72
|
+
|
|
73
|
+
You can also [combine API-only Mode with prerendering](../../how-to/pre-rendering#pre-rendering-with-api-only-mode-unstable) to serve complete HTML for selected paths and a SPA fallback for other paths.
|
|
74
|
+
|
|
75
|
+
Deploy both `build/client` and the runtime server build. Serve assets, prerendered documents, and the SPA fallback from the client build; send `.data` and route discovery requests (`/__manifest` by default) to the React Router request handler. The production API-only handler returns `404` for document requests. `react-router-serve` handles this routing automatically.
|
|
76
|
+
|
|
77
|
+
### Using a separate API origin
|
|
78
|
+
|
|
79
|
+
By default, data and route discovery requests use the same origin as the client application. Set `unstable_apiServerOrigin` to use a separate API server:
|
|
80
|
+
|
|
81
|
+
```ts filename=react-router.config.ts
|
|
82
|
+
import type { Config } from "@react-router/dev/config";
|
|
83
|
+
|
|
84
|
+
export default {
|
|
85
|
+
ssr: "unstable_api-only",
|
|
86
|
+
unstable_apiServerOrigin: "https://api.example.com",
|
|
87
|
+
} satisfies Config;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This option applies to loader, action, and route discovery requests only in API-only Mode. Use an origin without a path, query, or hash. Configure CORS on the API server and allow the client origin via [`allowedActionOrigins`](../../api/framework-conventions/react-router.config.ts#allowedactionorigins) for cross-origin action submissions. Requests use the browser's default `same-origin` credential policy; this option does not enable sending cookies to a different origin.
|
|
91
|
+
|
|
92
|
+
To customize JavaScript-issued requests with authentication headers or cross-origin credentials, see [Custom Fetch](../../how-to/custom-fetch). Native data prefetches bypass custom fetch.
|
|
93
|
+
|
|
57
94
|
---
|
|
58
95
|
|
|
59
96
|
Next: [Data Loading](./data-loading)
|
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.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.5.1",
|
|
5
5
|
"description": "Declarative routing for React",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
@@ -104,10 +104,18 @@
|
|
|
104
104
|
"wireit": "0.14.12"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
|
+
"@types/react": ">=19.2.0",
|
|
108
|
+
"@types/react-dom": ">=19.2.0",
|
|
107
109
|
"react": ">=19.2.7",
|
|
108
110
|
"react-dom": ">=19.2.7"
|
|
109
111
|
},
|
|
110
112
|
"peerDependenciesMeta": {
|
|
113
|
+
"@types/react": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"@types/react-dom": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
111
119
|
"react-dom": {
|
|
112
120
|
"optional": true
|
|
113
121
|
}
|