@rsc-kit/mcp 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recipes.js +12 -2
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -252
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +300 -169
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +2 -2
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -542
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +251 -218
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +269 -147
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -539
- package/guides/laravel.md +0 -787
- package/guides/your-own-backend.md +0 -602
|
@@ -2,41 +2,74 @@
|
|
|
2
2
|
|
|
3
3
|
> Navigations are an instant swap; a shared element is the transition worth having, and the page fade is the one to think twice about.
|
|
4
4
|
|
|
5
|
-
A navigation
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
stop reading here.**
|
|
9
|
-
|
|
10
|
-
React 19.3 ships [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition),
|
|
11
|
-
which animates a change by handing it to the browser's View Transition API,
|
|
12
|
-
and you can use it here for the one thing it is good at: a *shared element*
|
|
13
|
-
— a product image that morphs from the list into the detail page, a card
|
|
14
|
-
that grows into a panel. A fade over the whole page is a different thing.
|
|
15
|
-
It is cosmetic, it never makes a navigation faster, and on WebKit — Safari,
|
|
16
|
-
and every browser on iOS, Chrome included — it is expensive in a way a
|
|
17
|
-
desktop never shows; a port measured 600–900 ms with the screen frozen on
|
|
18
|
-
every navigation away from a long landing page before the transition was
|
|
19
|
-
taken out. If you want it anyway, the last section says how to have it
|
|
20
|
-
without paying that.
|
|
21
|
-
|
|
22
|
-
`<ViewTransition>` has one boundary worth knowing before you reach for it,
|
|
23
|
-
because the failure is silence: a transition that does not run looks exactly
|
|
24
|
-
like one you styled badly.
|
|
5
|
+
A navigation is an instant swap: the layouts stay mounted and the page under
|
|
6
|
+
them changes. Nothing fades, and nothing needs to. **Most apps need nothing on
|
|
7
|
+
this page.**
|
|
25
8
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| your own `useState`, inside `startTransition` | yes |
|
|
29
|
-
| a server action's result, put into state | yes |
|
|
30
|
-
| `<Form>` — errors, success, optimistic updates | yes |
|
|
31
|
-
| a streamed `<Suspense>` boundary arriving | yes, React does this on its own |
|
|
32
|
-
| navigating to another page | yes — the update carries a transition type |
|
|
9
|
+
The transition worth adding is a *shared element*: a product image that morphs
|
|
10
|
+
from the list into the detail page. Give it the same `name` on both pages:
|
|
33
11
|
|
|
34
|
-
|
|
12
|
+
```tsx title="src/app/products/ProductImage.tsx"
|
|
13
|
+
import { ViewTransition } from 'react';
|
|
35
14
|
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
export function ProductImage({ product }: { product: { id: string; image: string } }) {
|
|
16
|
+
return (
|
|
17
|
+
<ViewTransition name={`product-${product.id}`}>
|
|
18
|
+
<img src={product.image} alt="" />
|
|
19
|
+
</ViewTransition>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
38
23
|
|
|
39
|
-
|
|
24
|
+
`<ViewTransition>` is React's, from 19.3, and hands the change to the browser's
|
|
25
|
+
View Transition API. See [Requirements](#requirements).
|
|
26
|
+
|
|
27
|
+
## Morphing an element between pages
|
|
28
|
+
|
|
29
|
+
Render the same `name` on the list page and the detail page, and the browser
|
|
30
|
+
morphs the element from where it was to where it is:
|
|
31
|
+
|
|
32
|
+
```tsx title="src/app/products/page.tsx"
|
|
33
|
+
import Link from '@rsc-kit/core/Link';
|
|
34
|
+
import { ProductImage } from './ProductImage';
|
|
35
|
+
|
|
36
|
+
export default async function ProductsPage() {
|
|
37
|
+
const products = await listProducts();
|
|
38
|
+
|
|
39
|
+
return products.map((product) => (
|
|
40
|
+
<Link key={product.id} href={`/products/${product.id}`}>
|
|
41
|
+
<ProductImage product={product} />
|
|
42
|
+
{product.name}
|
|
43
|
+
</Link>
|
|
44
|
+
));
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```tsx title="src/app/products/[id]/page.tsx"
|
|
49
|
+
import { ProductImage } from '../ProductImage';
|
|
50
|
+
|
|
51
|
+
export default async function ProductPage({ params }: { params: Promise<{ id: string }> }) {
|
|
52
|
+
const product = await findProduct((await params).id);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<article>
|
|
56
|
+
<ProductImage product={product} />
|
|
57
|
+
<h1>{product.name}</h1>
|
|
58
|
+
</article>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A navigation replaces the page inside `startTransition`, so this works with no
|
|
64
|
+
other code. One element is one snapshot the size of that element, which is
|
|
65
|
+
cheap in every browser.
|
|
66
|
+
|
|
67
|
+
## Animating a change on the page
|
|
68
|
+
|
|
69
|
+
Give the changing element a `key`, so React sees a replacement rather than an
|
|
70
|
+
edit, and commit the change inside `startTransition`:
|
|
71
|
+
|
|
72
|
+
```tsx title="src/components/Total.tsx"
|
|
40
73
|
'use client';
|
|
41
74
|
|
|
42
75
|
import { useState, startTransition, ViewTransition } from 'react';
|
|
@@ -67,40 +100,31 @@ export function Total() {
|
|
|
67
100
|
}
|
|
68
101
|
```
|
|
69
102
|
|
|
70
|
-
A server action is
|
|
71
|
-
|
|
72
|
-
That makes it a transition like any other. `<Form>` is built on `useState`
|
|
73
|
-
throughout, so everything it drives animates the same way.
|
|
103
|
+
A server action's result is an ordinary return value, so putting it into state
|
|
104
|
+
is a transition like any other.
|
|
74
105
|
|
|
75
|
-
|
|
106
|
+
### What animates
|
|
76
107
|
|
|
77
|
-
A
|
|
78
|
-
|
|
79
|
-
should carry across — the same `name` on the list page and the detail page —
|
|
80
|
-
and the browser morphs it from where it was to where it is:
|
|
108
|
+
A transition that doesn't run looks exactly like one you styled badly, so check
|
|
109
|
+
the change comes from one of these:
|
|
81
110
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
This is the transition worth having.
|
|
111
|
+
| the change comes from | animates |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| your own `useState`, inside `startTransition` | yes |
|
|
114
|
+
| a server action's result, put into state | yes |
|
|
115
|
+
| `<Form>`: errors, success, optimistic updates | yes, it is built on `useState` |
|
|
116
|
+
| a streamed `<Suspense>` boundary arriving | yes, React does this on its own |
|
|
117
|
+
| navigating to another page | yes, the update carries a transition type |
|
|
90
118
|
|
|
91
|
-
##
|
|
119
|
+
## Fading the whole page
|
|
92
120
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
animated would be the page fading into itself on every load. So a
|
|
96
|
-
navigation's update carries the transition type `rsc-navigation`, and that
|
|
97
|
-
first commit does not. `PageTransition` keys the boundary on it, and skips
|
|
98
|
-
the fade where it is expensive:
|
|
121
|
+
A fade over the whole page is cosmetic and never makes a navigation faster. If
|
|
122
|
+
you want it, use `PageTransition` in the root layout:
|
|
99
123
|
|
|
100
124
|
```tsx title="src/app/layout.tsx"
|
|
101
125
|
import { PageTransition } from '@rsc-kit/core/PageTransition';
|
|
102
126
|
|
|
103
|
-
export default function RootLayout({ children }) {
|
|
127
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
104
128
|
return (
|
|
105
129
|
<html lang="en">
|
|
106
130
|
<body className="min-h-full flex flex-col">
|
|
@@ -111,68 +135,60 @@ export default function RootLayout({ children }) {
|
|
|
111
135
|
}
|
|
112
136
|
```
|
|
113
137
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
where it is now. One wrapper element is one snapshot pair — the old page
|
|
124
|
-
and the new one dissolving into each other, the way Inertia's does. A
|
|
125
|
-
navbar inside the pair cross-fades into itself, which is invisible; put the
|
|
126
|
-
boundary around `<main>` in a nested layout instead when you want the
|
|
127
|
-
navbar left out of it entirely. Write the `ViewTransition` yourself,
|
|
128
|
-
without the wrapper, when you want the per-element movement.
|
|
129
|
-
|
|
130
|
-
### Shaping the animation
|
|
131
|
-
|
|
132
|
-
The component's CSS is the part that is easy to get wrong by hand, so it
|
|
133
|
-
ships with it: a 120 ms cross-fade, and `::view-transition { pointer-events:
|
|
134
|
-
none }`, because the pseudo-element tree sits over the document while the
|
|
135
|
-
fade runs and would otherwise swallow a second tap. The browser's default
|
|
136
|
-
is 250 ms, and the group and root pairs keep it whatever you set on the
|
|
137
|
-
page pair — a "120 ms" fade written as the two-selector rule most examples
|
|
138
|
-
show ran 290 ms. Two props adjust it:
|
|
138
|
+
It is a 120 ms cross-fade on navigations only, never on a first load or a
|
|
139
|
+
reload. It is skipped on WebKit and for a visitor who asked for reduced
|
|
140
|
+
motion. Its CSS ships with it, so there is nothing to add to your stylesheet.
|
|
141
|
+
|
|
142
|
+
`className` goes on the one `<div>` it wraps the page in, so here the `<div>`
|
|
143
|
+
carries the body's flex layout. To leave the navbar out of the fade, put
|
|
144
|
+
`PageTransition` around `<main>` in a nested layout instead.
|
|
145
|
+
|
|
146
|
+
### Changing the fade
|
|
139
147
|
|
|
140
148
|
```tsx
|
|
141
149
|
<PageTransition duration={200}>{children}</PageTransition> // ms; 0 is the instant swap
|
|
142
150
|
<PageTransition webkit="run">{children}</PageTransition> // a short page that may run it on WebKit
|
|
151
|
+
<PageTransition transition="slide">{children}</PageTransition> // the class your own CSS styles
|
|
143
152
|
```
|
|
144
153
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
page
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
154
|
+
| Prop | Default | What it does |
|
|
155
|
+
| --- | --- | --- |
|
|
156
|
+
| `duration` | `120` | The fade's length in ms. `0` is the instant swap, and named shared elements still morph. |
|
|
157
|
+
| `webkit` | `"skip"` | `"run"` for a page you have measured, such as a form, where the snapshot is one screen. |
|
|
158
|
+
| `transition` | `"page"` | The view-transition class a navigation gets. |
|
|
159
|
+
| `className` | | The class of the wrapping `<div>`. |
|
|
160
|
+
|
|
161
|
+
To shape the fade further, style the class yourself. Your rules come after the
|
|
162
|
+
component's:
|
|
163
|
+
|
|
164
|
+
```css title="src/app/styles.css"
|
|
165
|
+
::view-transition-old(.page),
|
|
166
|
+
::view-transition-new(.page) {
|
|
167
|
+
animation-timing-function: ease-out;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Why WebKit is skipped
|
|
172
|
+
|
|
173
|
+
Safari, and every browser on iOS since they all run WebKit, rasterises the
|
|
174
|
+
outgoing snapshot at the element's full height, not the viewport's. A landing
|
|
175
|
+
page 12,000 px tall is 44 megapixels at 3×. A port measured about 600 ms with
|
|
176
|
+
the screen frozen on every navigation away from it, and the memory can be
|
|
177
|
+
enough for iOS to discard the tab. Chromium caps the snapshot, so a desktop or
|
|
178
|
+
an Android phone never shows it.
|
|
179
|
+
|
|
180
|
+
So `PageTransition` runs the fade on Chromium and Firefox, and skips it where
|
|
181
|
+
`navigator.vendor` is Apple's. That is decided after mount, so the first render
|
|
182
|
+
agrees with the server's.
|
|
183
|
+
|
|
184
|
+
Writing the boundary yourself, do the same, or put it on a container that is
|
|
185
|
+
the viewport's height and scrolls inside, so the snapshot is one screen.
|
|
169
186
|
|
|
170
187
|
## Pages that ship no JavaScript
|
|
171
188
|
|
|
172
|
-
A page with nothing interactive
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
JavaScript at all:
|
|
189
|
+
A page with nothing interactive ships no runtime, so a link from it is an
|
|
190
|
+
ordinary page load and there is no router to run `<ViewTransition>`. The browser
|
|
191
|
+
can still animate that load with one rule of CSS:
|
|
176
192
|
|
|
177
193
|
```css title="src/app/styles.css"
|
|
178
194
|
@media (prefers-reduced-motion: no-preference) {
|
|
@@ -182,36 +198,29 @@ JavaScript at all:
|
|
|
182
198
|
}
|
|
183
199
|
```
|
|
184
200
|
|
|
185
|
-
With it on both pages, a same-site link
|
|
186
|
-
next
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
the page load it always was.
|
|
201
|
+
With it on both pages, a same-site link cross-fades from one document to the
|
|
202
|
+
next. Shape it with the same `::view-transition-*` selectors, and give an
|
|
203
|
+
element `view-transition-name` on both pages for a shared one. Chrome, Edge
|
|
204
|
+
and Safari 18.2+ do it; elsewhere the link is the page load it always was.
|
|
190
205
|
|
|
191
|
-
The
|
|
192
|
-
|
|
193
|
-
do ship the runtime it has no effect - their navigations are the router's,
|
|
194
|
-
not page loads.
|
|
206
|
+
The WebKit cost above applies here too. On pages that ship the runtime the rule
|
|
207
|
+
has no effect, since their navigations are the router's.
|
|
195
208
|
|
|
196
209
|
## Coming back to a page you were just on
|
|
197
210
|
|
|
198
|
-
A
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
a
|
|
202
|
-
|
|
203
|
-
It is bounded, because the two halves pull against each other: what comes back
|
|
204
|
-
is the tree from when you left, so its data is from then. Thirty seconds by
|
|
205
|
-
default, which covers leaving a form to check something and coming straight
|
|
206
|
-
back. Past that a link refetches.
|
|
211
|
+
A link to a page still being held reveals it rather than refetching it, so a
|
|
212
|
+
half-filled form is still filled in. That lasts thirty seconds by default,
|
|
213
|
+
which covers leaving a form to check something and coming straight back.
|
|
214
|
+
After that a link refetches, because the held page's data is from when you
|
|
215
|
+
left. To always refetch:
|
|
207
216
|
|
|
208
217
|
```ts
|
|
209
218
|
import { setRevealWindow } from '@rsc-kit/core/navigate';
|
|
210
219
|
|
|
211
|
-
setRevealWindow(0); //
|
|
220
|
+
setRevealWindow(0); // every link is a fresh request
|
|
212
221
|
```
|
|
213
222
|
|
|
214
|
-
The back button
|
|
223
|
+
The back button isn't bounded. It names a moment, and the page from that
|
|
215
224
|
moment is the right answer however old it is.
|
|
216
225
|
|
|
217
226
|
<Aside type="caution" title="It can hide a server that is down">
|
|
@@ -221,7 +230,7 @@ moment is the right answer however old it is.
|
|
|
221
230
|
window rather than offline support, and it means a dead server can go
|
|
222
231
|
unnoticed for as long as the window lasts — [`useOffline`](/guides/offline)
|
|
223
232
|
is what surfaces it. Actually surviving with no network is
|
|
224
|
-
[`offline: true`](/guides/offline#
|
|
233
|
+
[`offline: true`](/guides/offline#working-with-no-network-at-all), which is a service
|
|
225
234
|
worker and a different thing entirely.
|
|
226
235
|
</Aside>
|
|
227
236
|
|
|
@@ -235,7 +244,25 @@ npm install react@^19.3 react-dom@^19.3
|
|
|
235
244
|
```
|
|
236
245
|
|
|
237
246
|
React also documents a [`browser`](https://react.dev/reference/react-dom/browser)
|
|
238
|
-
api for rendering a component only in the browser
|
|
239
|
-
the server cannot know. It is not in 19.3 yet; see
|
|
247
|
+
api for rendering a component only in the browser. It is not in 19.3 yet; see
|
|
240
248
|
[static generation](/guides/static-generation#a-value-that-must-not-be-frozen)
|
|
241
249
|
for what to do meanwhile.
|
|
250
|
+
|
|
251
|
+
## How the page fade works
|
|
252
|
+
|
|
253
|
+
- **Only navigations.** A navigation's update carries the transition type
|
|
254
|
+
`rsc-navigation`, and the first commit after hydration doesn't. `PageTransition`
|
|
255
|
+
is `<ViewTransition default={{ 'rsc-navigation': 'page', default: 'none' }}>`
|
|
256
|
+
around one `<div>`, so a first load or a reload never animates.
|
|
257
|
+
- **One wrapper element.** React names each top-level element under a boundary
|
|
258
|
+
and animates every one on its own, so a page of five sections would be five
|
|
259
|
+
groups morphing separately. One wrapper is one snapshot pair: the old page
|
|
260
|
+
and the new one dissolving into each other. Write the `ViewTransition`
|
|
261
|
+
yourself, without the wrapper, when you want the per-element movement.
|
|
262
|
+
- **The durations.** The browser's default is 250 ms, and the group and root
|
|
263
|
+
pairs keep it whatever you set on the page pair. A "120 ms" fade written as
|
|
264
|
+
the two-selector rule most examples show ran 290 ms, so the component sets
|
|
265
|
+
all of them.
|
|
266
|
+
- **A second tap.** The pseudo-element tree sits over the document while the
|
|
267
|
+
fade runs. The component adds `::view-transition { pointer-events: none }`, so
|
|
268
|
+
it doesn't swallow a tap.
|