@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.
Files changed (60) hide show
  1. package/dist/recipes.js +12 -2
  2. package/dist/recipes.js.map +1 -1
  3. package/guides/admin-plugins.md +206 -6
  4. package/guides/api-routes.md +159 -215
  5. package/guides/authorization.md +103 -114
  6. package/guides/backend-answered-pages.md +301 -252
  7. package/guides/bap-vs-inertia.md +67 -25
  8. package/guides/blueprints.md +300 -169
  9. package/guides/bun.md +42 -25
  10. package/guides/caching.md +46 -49
  11. package/guides/coming-from-inertia.md +2 -2
  12. package/guides/commands.md +251 -200
  13. package/guides/connection.md +50 -54
  14. package/guides/content-security-policy.md +133 -84
  15. package/guides/domains.md +190 -149
  16. package/guides/edge-caching.md +242 -268
  17. package/guides/emails.md +96 -45
  18. package/guides/errors.md +116 -137
  19. package/guides/feature-flags.md +100 -30
  20. package/guides/file-uploads.md +101 -26
  21. package/guides/fonts.md +139 -110
  22. package/guides/forms.md +520 -542
  23. package/guides/images.md +87 -28
  24. package/guides/index.json +13 -33
  25. package/guides/instrumentation.md +134 -95
  26. package/guides/isr.md +3 -3
  27. package/guides/live-data-in-production.md +695 -0
  28. package/guides/live-data.md +170 -839
  29. package/guides/mcp.md +83 -59
  30. package/guides/metadata.md +124 -179
  31. package/guides/navigation.md +118 -147
  32. package/guides/no-javascript.md +49 -57
  33. package/guides/offline.md +118 -153
  34. package/guides/openapi.md +100 -35
  35. package/guides/pages.md +160 -50
  36. package/guides/ppr.md +178 -256
  37. package/guides/pwa.md +251 -218
  38. package/guides/queries.md +171 -300
  39. package/guides/react-compiler.md +90 -50
  40. package/guides/redirects.md +141 -177
  41. package/guides/response-headers.md +76 -74
  42. package/guides/route-interception.md +112 -111
  43. package/guides/routing.md +216 -322
  44. package/guides/sections.md +63 -66
  45. package/guides/seo-files.md +127 -65
  46. package/guides/server-actions.md +285 -357
  47. package/guides/static-generation.md +131 -199
  48. package/guides/testing.md +269 -147
  49. package/guides/third-party-scripts.md +94 -47
  50. package/guides/typed-routes.md +115 -113
  51. package/guides/url-validation.md +113 -61
  52. package/guides/validation.md +53 -62
  53. package/guides/view-transitions.md +159 -132
  54. package/guides/where-it-runs.md +226 -162
  55. package/package.json +2 -2
  56. package/guides/admin.md +0 -520
  57. package/guides/deployment.md +0 -598
  58. package/guides/go.md +0 -539
  59. package/guides/laravel.md +0 -787
  60. 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 here is an instant swap: the layouts stay mounted and the
6
- page underneath changes, the way Next's router does it. Nothing fades, and
7
- nothing needs to — there is no document reload to hide. **Most apps should
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
- | the change comes from | animates |
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
- ## What works
12
+ ```tsx title="src/app/products/ProductImage.tsx"
13
+ import { ViewTransition } from 'react';
35
14
 
36
- Ordinary React. Give the changing element a `key` so React sees a replacement
37
- rather than an edit, and commit inside `startTransition`:
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
- ```tsx
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 in the working column for a reason worth stating: its result
71
- comes back as an ordinary return value, and what you do with it is `useState`.
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
- ## A shared element across pages
106
+ ### What animates
76
107
 
77
- A navigation replaces the segment inside `startTransition`, so a
78
- `<ViewTransition>` inside it animates like any other. Name the element that
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
- ```tsx
83
- <ViewTransition name={`product-${product.id}`}>
84
- <img src={product.image} alt="" />
85
- </ViewTransition>
86
- ```
87
-
88
- One element, one snapshot the size of that element: cheap on every engine.
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
- ## The page fade, if you want it
119
+ ## Fading the whole page
92
120
 
93
- What you cannot tell from outside is a navigation from the first commit
94
- after hydration — the boundary taking over the server-rendered page, which
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
- `PageTransition` is `<ViewTransition default={{ 'rsc-navigation': 'page', default: 'none' }}>`
115
- around one `<div>`, with its CSS — there is nothing to add to your
116
- stylesheet. On WebKit the class is `'none'`, decided after mount — see the
117
- caution below for why — and so it is for a visitor who asked for reduced
118
- motion. `default: 'none'` is what makes a first load or a reload never
119
- animate. The `<div>` matters (here it also carries the body's flex layout,
120
- so a `<main>` inside still fills the height): React names each top-level
121
- element under a boundary and animates every one on its own, so a page of
122
- five sections becomes five groups, each morphing from where it was to
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
- `duration={0}` is the instant swap with the transition still in place for
146
- the shared elements you name yourself (`<ViewTransition name="hero">` still
147
- morphs). `webkit="run"` is for a page you have measured — a form, a settings
148
- page — where the snapshot is one screen; the default skips WebKit for the
149
- reason below. To shape the fade further, style `::view-transition-old(.page)`
150
- and `::view-transition-new(.page)` yourself (the `transition` prop renames
151
- the class); your rules come after the component's.
152
-
153
- <Aside type="caution" title="WebKit snapshots the whole page — which is why PageTransition skips it">
154
- Safari — and every browser on iOS, Chrome included, since they all run
155
- WebKit — rasterises the outgoing snapshot at the element's full height,
156
- not the viewport's. A landing page 12,000 px tall is 44 megapixels at 3×:
157
- a port measured ~600 ms with the screen frozen on every navigation away
158
- from it, and the memory can be enough for iOS to discard the tab, which
159
- comes back as a reload nobody asked for. Chromium caps the snapshot, so a
160
- desktop or an Android phone never shows it. Other sites' transitions run
161
- fine on the same phone because they name the document root, which the
162
- spec clips to the viewport; React's `<ViewTransition>` names the element
163
- it wraps. So `PageTransition` runs the cross-fade on Chromium and Firefox
164
- and skips it where `navigator.vendor` is Apple's — decided after mount,
165
- so the first render agrees with the server's. Writing the boundary
166
- yourself, do the same, or put it on a container that is the viewport's
167
- height and scrolls inside, so the snapshot is one screen.
168
- </Aside>
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 on it ships no runtime, so a link from it is
173
- an ordinary page load - there is no router to run `<ViewTransition>`. The
174
- browser can still animate that load on its own, with one rule of CSS and no
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 animates from one document to the
186
- next - a crossfade by default, shaped with the same `::view-transition-*`
187
- selectors as above, and `view-transition-name` on an element on both pages
188
- for a shared one. Chrome, Edge and Safari 18.2+ do it; elsewhere the link is
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 same caution as the page fade applies: it never makes a navigation
192
- faster, and on WebKit a large page is expensive to snapshot. On pages that
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 navigation to a page still being held reveals it rather than refetching it,
199
- so the form you were filling in is still filled in. That applies to a link, not
200
- only the back button — having one keep your work and the other throw it away is
201
- a distinction nobody makes while using an app.
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); // never reveal — every link is a fresh request
220
+ setRevealWindow(0); // every link is a fresh request
212
221
  ```
213
222
 
214
- The back button is not bounded. It names a moment, and the page from that
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#surviving-without-one), which is a service
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 — the right tool for a value
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.