@rsc-kit/mcp 0.40.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 +37 -20
- 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 -250
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +307 -174
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +5 -5
- 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 -538
- 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 +272 -150
- 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 -538
- package/guides/laravel.md +0 -786
- package/guides/your-own-backend.md +0 -587
|
@@ -2,44 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
> Rendering pages ahead of time, and exporting a site of files.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
The build renders every page once and stores what it can, so a visitor gets a
|
|
6
|
+
file instead of a render. There is nothing to declare:
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
```bash
|
|
9
|
+
bun run build
|
|
10
|
+
# ○ /
|
|
11
|
+
# ○ /about
|
|
12
|
+
# ◔ /account
|
|
13
|
+
#
|
|
14
|
+
# 2 stored, 1 shell
|
|
15
|
+
```
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
`○` is a page stored whole. `◔` is a shell: the parts that painted are stored,
|
|
18
|
+
and the parts waiting for the request are rendered per request and streamed in.
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
## How the build decides
|
|
21
|
+
|
|
22
|
+
The build renders each route and watches what happens:
|
|
23
|
+
|
|
24
|
+
| Outcome | What happened |
|
|
14
25
|
| --- | --- |
|
|
15
26
|
| The whole page | It rendered to completion. Stored and served from disk. |
|
|
16
|
-
| A shell | Something was still waiting when the
|
|
17
|
-
| A redirect | The route only redirects, so the redirect itself is stored
|
|
27
|
+
| A shell | Something was still waiting when the time ran out, but the rest had painted. The shell is stored; the rest is rendered per request. |
|
|
28
|
+
| A redirect | The route only redirects, so the redirect itself is stored: status and location. |
|
|
18
29
|
| Refused | Nothing painted before the page blocked. The build fails. |
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
Each route gets 2 seconds; `RSC_PPR_TIMEOUT_MS` changes it. A page whose data
|
|
32
|
+
arrives in time is stored whole, including one that called `fetch()`. A page
|
|
33
|
+
that is only waiting steps aside for the next one, so hundreds of shells cost
|
|
34
|
+
about 2 seconds between them, not 2 seconds each.
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
A refused route has its boundary in the wrong place. Put the part that waits
|
|
37
|
+
inside `<Suspense>`, and the route becomes a shell. [Partial prerendering](/guides/ppr)
|
|
38
|
+
covers where boundaries go.
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
Whatever a stored page read during the build is in the file. If something
|
|
41
|
+
should be current on every request, it has to read the request - `params`,
|
|
42
|
+
`searchParams`, `headers()`, `cookies()` - or call
|
|
43
|
+
[`connection()`](/guides/connection), which puts it behind a boundary instead
|
|
44
|
+
of in the stored bytes.
|
|
31
45
|
|
|
32
|
-
|
|
33
|
-
Whatever a page read at build time is in the file. If it should reflect the
|
|
34
|
-
current state of the world on every request, it needs to read the request —
|
|
35
|
-
`params`, `searchParams`, `headers()`, `cookies()` — which suspends, and puts
|
|
36
|
-
it behind a boundary rather than in the stored bytes.
|
|
37
|
-
</Aside>
|
|
46
|
+
## Listing the URLs of a dynamic route
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
A route with a `[param]` cannot be frozen unless something says which values
|
|
42
|
-
exist. Export `generateStaticParams` from the page:
|
|
48
|
+
A route with a `[param]` is stored only for the values you list. Export
|
|
49
|
+
`generateStaticParams` from the page:
|
|
43
50
|
|
|
44
51
|
```tsx title="src/app/direct/[slug]/page.tsx"
|
|
45
52
|
import { Suspense } from 'react'
|
|
@@ -95,28 +102,13 @@ export function generateStaticParams() {
|
|
|
95
102
|
}
|
|
96
103
|
```
|
|
97
104
|
|
|
98
|
-
A route that lists nothing is rendered on demand. That is a
|
|
99
|
-
|
|
100
|
-
the two paths can be compared side by side.
|
|
101
|
-
|
|
102
|
-
## Running the prerender
|
|
105
|
+
A route that lists nothing is rendered on demand instead. That is a choice,
|
|
106
|
+
not a failure.
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
the app rendering itself, so it needs the thing the build just produced.
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
bun run build
|
|
109
|
-
# ○ /
|
|
110
|
-
# ○ /about
|
|
111
|
-
# ◔ /account
|
|
112
|
-
#
|
|
113
|
-
# 2 stored, 1 shell
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Opting a page out
|
|
108
|
+
## Keeping a page out of the build
|
|
117
109
|
|
|
118
110
|
There is no switch that turns prerendering off for the app. A page that must
|
|
119
|
-
not be stored says so
|
|
111
|
+
not be stored says so where the work is, with [`connection()`](/guides/connection):
|
|
120
112
|
|
|
121
113
|
```tsx
|
|
122
114
|
await connection()
|
|
@@ -125,85 +117,36 @@ const rows = await db.query('select * from orders')
|
|
|
125
117
|
```
|
|
126
118
|
|
|
127
119
|
The build skips that read, stores everything around it, and the page still
|
|
128
|
-
gets a shell.
|
|
129
|
-
the only opt-out is per page — and for the same reason: the page that
|
|
130
|
-
depends on the request is the one that knows.
|
|
131
|
-
|
|
132
|
-
Prerendering **runs your application code**, so it needs whatever that code
|
|
133
|
-
needs. A page that queries a database needs that database reachable from the
|
|
134
|
-
build — or `await connection()` before the query, which is the smaller and
|
|
135
|
-
more accurate statement. When a page cannot render at build time the build
|
|
136
|
-
refuses and names it, so nothing is silently rendered live that could have
|
|
137
|
-
been stored.
|
|
138
|
-
|
|
139
|
-
**All of it per request** is the root layout reading the request —
|
|
140
|
-
`await connection()` there — with a root `loading.tsx` to give every page a
|
|
141
|
-
shell. That is what Next's `force-dynamic` on the root layout does, and it
|
|
142
|
-
costs what it costs: every page is a stored fallback with the rest streamed,
|
|
143
|
-
and every page has the runtime. Measured in the repository's `bench/`, a
|
|
144
|
-
page that could have been stored renders five times slower this way, which
|
|
145
|
-
is why there is no switch to make it the default.
|
|
146
|
-
|
|
147
|
-
It is off in watch mode regardless — a rebuild on every keystroke that also
|
|
148
|
-
re-renders every route is not a feedback loop anyone wants.
|
|
149
|
-
|
|
150
|
-
### Doing it yourself
|
|
151
|
-
|
|
152
|
-
`prerender` is also a plain function, exported from `@rsc-kit/core/prerender`,
|
|
153
|
-
so it runs wherever your build does. `write` is a callback rather than a
|
|
154
|
-
directory, because not every place this runs has a filesystem — `writeTo` is
|
|
155
|
-
the `node:fs` implementation of it, and a platform without one passes its own.
|
|
156
|
-
|
|
157
|
-
You should not need it. The build calls it for you, with the engine bundle it
|
|
158
|
-
just produced — a path only the build knows, since Nitro builds the rsc
|
|
159
|
-
environment under `node_modules`.
|
|
160
|
-
|
|
161
|
-
## What gets written
|
|
120
|
+
gets a shell.
|
|
162
121
|
|
|
163
|
-
|
|
164
|
-
|
|
122
|
+
Prerendering **runs your application code**, so the build needs whatever that
|
|
123
|
+
code needs. A page that queries a database needs the database reachable from
|
|
124
|
+
the build, or `await connection()` before the query. A page that can't render
|
|
125
|
+
during the build is refused by name, so nothing that could have been stored is
|
|
126
|
+
quietly rendered per request instead.
|
|
165
127
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
| `{key}.ppr.html` | A shell, stored per route *pattern* rather than per URL. |
|
|
173
|
-
|
|
174
|
-
The `.seg{n}` variants are what make a prerendered route participate in partial
|
|
175
|
-
navigation. Without them every arrival at a frozen page would replace the
|
|
176
|
-
document root, unmounting the pages retained behind it — the form you were
|
|
177
|
-
filling in would not survive going back to it.
|
|
178
|
-
|
|
179
|
-
## Serving them
|
|
180
|
-
|
|
181
|
-
The host checks for a frozen file before it matches a route. `prerendered` is
|
|
182
|
-
the source it checks, and like `write` it is a callback:
|
|
128
|
+
To render every page per request, call `await connection()` in the root
|
|
129
|
+
layout and give every page a shell with a root `loading.tsx`. This is what
|
|
130
|
+
Next's `force-dynamic` on the root layout does. Every page then streams and
|
|
131
|
+
ships the runtime, and a page that could have been stored renders about five
|
|
132
|
+
times slower (measured in the repository's `bench/`). That cost is why it is
|
|
133
|
+
not the default.
|
|
183
134
|
|
|
184
|
-
|
|
185
|
-
`.output/server/rsc-static`, and the entry reads them from beside itself.
|
|
186
|
-
Nothing found, and the request falls through to a live render.
|
|
187
|
-
|
|
188
|
-
On other presets they go wherever Nitro writes the server, since that is what the
|
|
189
|
-
platform deploys: inside the function on Vercel
|
|
190
|
-
(`.vercel/output/functions/__server.func/rsc-static`) and Netlify, and among
|
|
191
|
-
the static assets on Cloudflare, read back through the assets binding.
|
|
135
|
+
Prerendering is off in watch mode.
|
|
192
136
|
|
|
193
137
|
## A value that must not be frozen
|
|
194
138
|
|
|
195
|
-
A stored page keeps whatever it rendered,
|
|
196
|
-
|
|
197
|
-
same instant to everyone until the next one:
|
|
139
|
+
A stored page keeps whatever it rendered, including what the clock said
|
|
140
|
+
during the build:
|
|
198
141
|
|
|
199
142
|
```tsx
|
|
200
143
|
export default function Page() {
|
|
201
|
-
// Frozen
|
|
144
|
+
// Frozen at the moment the build ran, for every visitor.
|
|
202
145
|
return <p>Rendered at {new Date().toISOString()}</p>;
|
|
203
146
|
}
|
|
204
147
|
```
|
|
205
148
|
|
|
206
|
-
The build
|
|
149
|
+
The build warns about it:
|
|
207
150
|
|
|
208
151
|
```
|
|
209
152
|
○ /
|
|
@@ -216,41 +159,29 @@ The build says so rather than leaving you to notice:
|
|
|
216
159
|
`new Date()`, `Date.now()`, `Math.random()` and `crypto.randomUUID()` are all
|
|
217
160
|
watched.
|
|
218
161
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
something inside it *waits* for what the build cannot finish — a read that
|
|
224
|
-
outlasts the build's budget, or a page that has said `await connection()`.
|
|
225
|
-
</Aside>
|
|
226
|
-
|
|
227
|
-
Moving it into a client component makes it worse, not better. Hydration is not
|
|
228
|
-
React attaching handlers to existing markup — it *runs* the component, because
|
|
229
|
-
that is the only way it learns what the tree should be.
|
|
230
|
-
|
|
231
|
-
So the body executes twice, once where the HTML came from and once in the
|
|
232
|
-
browser, and a clock read inside gives two different answers.
|
|
162
|
+
Wrapping it in `<Suspense>` changes nothing: the build renders straight through
|
|
163
|
+
a component that never waits, so the value is captured as before. A boundary
|
|
164
|
+
becomes a hole only when something inside it *waits* for what the build can't
|
|
165
|
+
finish - a read that outlasts the time limit, or `await connection()`.
|
|
233
166
|
|
|
234
|
-
Where the value
|
|
235
|
-
client one:
|
|
167
|
+
Where the value is read decides what happens:
|
|
236
168
|
|
|
237
|
-
|
|
|
169
|
+
| The value is | Result |
|
|
238
170
|
| --- | --- |
|
|
239
|
-
| read in a server component | frozen
|
|
240
|
-
| read in a client component's body | produced twice, and the two disagree |
|
|
241
|
-
| computed on the server, passed as a prop |
|
|
171
|
+
| read in a server component | frozen during the build, and the build warns |
|
|
172
|
+
| read in a client component's body | produced twice, on the server and in the browser, and the two disagree |
|
|
173
|
+
| computed on the server, passed as a prop | sent with the page, so both renders read the same value (and it is frozen with the page) |
|
|
242
174
|
| read only in the browser | nothing on the server to disagree with |
|
|
243
175
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
is fine for a build stamp and wrong for a clock.
|
|
176
|
+
Passing it as a prop is the usual answer for anything the server can decide:
|
|
177
|
+
right for a build stamp, wrong for a clock. For a clock, read it in the
|
|
178
|
+
browser only.
|
|
248
179
|
|
|
249
180
|
## Rendering something in the browser only
|
|
250
181
|
|
|
251
|
-
For a value that is
|
|
252
|
-
|
|
253
|
-
|
|
182
|
+
For a value that is per visitor and needs no server - a clock, `localStorage`,
|
|
183
|
+
a map, an editor - call `use(browser())`, and React skips the component on the
|
|
184
|
+
server:
|
|
254
185
|
|
|
255
186
|
```tsx
|
|
256
187
|
'use client';
|
|
@@ -267,77 +198,58 @@ function SavedDraft() {
|
|
|
267
198
|
}
|
|
268
199
|
```
|
|
269
200
|
|
|
270
|
-
The page it sits on stays frozen at build time. React stops the server render
|
|
271
|
-
at that component and puts the nearest Suspense boundary's fallback into the
|
|
272
|
-
HTML; everything around it rendered normally, so there is still a finished
|
|
273
|
-
document to store.
|
|
274
|
-
|
|
275
201
|
```tsx
|
|
276
202
|
<Suspense fallback={<p>Loading draft…</p>}>
|
|
277
203
|
<SavedDraft />
|
|
278
204
|
</Suspense>
|
|
279
205
|
```
|
|
280
206
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
Three things to know:
|
|
286
|
-
|
|
287
|
-
- **The Suspense boundary is required.** Without one, the server render fails
|
|
288
|
-
rather than degrading.
|
|
289
|
-
- **It has to be a client component.** `browser()` is about skipping the server
|
|
290
|
-
render of something that will render in the browser; a server component has
|
|
291
|
-
no browser render to fall back to.
|
|
292
|
-
- **`browser()` alone does nothing.** Pass it to `use()`. Do not throw it.
|
|
207
|
+
The page stays stored. The HTML has the boundary's fallback where the
|
|
208
|
+
component goes, and the browser renders the real thing in its place. Only one
|
|
209
|
+
side ever runs, so there is no mismatch.
|
|
293
210
|
|
|
294
|
-
The
|
|
295
|
-
|
|
296
|
-
|
|
211
|
+
- **The `<Suspense>` boundary is required.** Without one, the server render
|
|
212
|
+
fails.
|
|
213
|
+
- **It must be a client component.** A server component has no browser render
|
|
214
|
+
to fall back to.
|
|
215
|
+
- **Pass `browser()` to `use()`.** On its own it does nothing; don't throw it.
|
|
297
216
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
the fallback in the HTML instead of a blank, and says in the component why.
|
|
302
|
-
It is in `react-dom` 19.3.
|
|
217
|
+
The reason is optional and only read on the server, where React's bailout
|
|
218
|
+
callback reports it. Give one anyway: it tells the next person why. Pass a
|
|
219
|
+
function if building it is expensive.
|
|
303
220
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
</Aside>
|
|
221
|
+
`browser()` is in `react-dom` 19.3, and replaces the old empty-first-render
|
|
222
|
+
plus `useEffect` pattern. rsc-kit has no `ClientOnly` component.
|
|
307
223
|
|
|
308
224
|
## Exporting a site
|
|
309
225
|
|
|
310
|
-
Build with `output: 'export'`
|
|
311
|
-
|
|
226
|
+
Build with `output: 'export'` to write a directory any static host can serve,
|
|
227
|
+
with no server at all:
|
|
312
228
|
|
|
313
229
|
```bash
|
|
314
230
|
RSC_OUTPUT=export npm run build
|
|
315
231
|
# Exported 9 pages to dist
|
|
316
232
|
```
|
|
317
233
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
left out, which
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
There is no separate shell template. The root `layout.tsx` renders the whole
|
|
339
|
-
document, and the build injects the bootstrap script and stylesheet links into
|
|
340
|
-
it. The same layout serves streamed and frozen pages.
|
|
234
|
+
- **Every route must be stored whole.** A shell on a static host would load
|
|
235
|
+
and stay empty, since nothing runs to fill it in. The build refuses
|
|
236
|
+
otherwise. `RSC_EXPORT_FORCE=1` writes the site anyway and lists what it
|
|
237
|
+
left out, which helps you move an app towards exporting.
|
|
238
|
+
- **A route that only redirects** is written as a meta refresh, the one
|
|
239
|
+
redirect every static host follows without configuration.
|
|
240
|
+
- **Everything served as a file comes along:** the browser bundle, `public/`,
|
|
241
|
+
the icons and share image beside the root layout, the web manifest, the
|
|
242
|
+
service worker, and stored `route.ts` answers such as `robots.txt`,
|
|
243
|
+
`sitemap.xml` or a JSON feed.
|
|
244
|
+
- **A `route.ts` answer needs an extension in its URL.** A static host types a
|
|
245
|
+
file by its extension, so `/api/health` would lose its `application/json`.
|
|
246
|
+
The build lists it as left out rather than exporting it wrong. Use
|
|
247
|
+
`/api/health.json`, or serve it from a host that runs.
|
|
248
|
+
|
|
249
|
+
## The document
|
|
250
|
+
|
|
251
|
+
The root `layout.tsx` renders the whole document; there is no separate HTML
|
|
252
|
+
template. The build adds the scripts and stylesheet links to it:
|
|
341
253
|
|
|
342
254
|
```tsx title="src/app/layout.tsx"
|
|
343
255
|
import './styles.css';
|
|
@@ -351,11 +263,31 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
351
263
|
}
|
|
352
264
|
```
|
|
353
265
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
266
|
+
Load fonts and global CSS here. The root layout stays mounted across
|
|
267
|
+
navigations, so its `<link>` tags load once; the same tags in a nested layout
|
|
268
|
+
or page are added again on every navigation. Titles and meta tags come from
|
|
269
|
+
each page: see [Page metadata](/guides/metadata).
|
|
270
|
+
|
|
271
|
+
## What the build writes
|
|
272
|
+
|
|
273
|
+
Each stored route is a set of files named after its URL (`/` is `index`,
|
|
274
|
+
`/docs/install` is `docs/install`):
|
|
275
|
+
|
|
276
|
+
| File | For |
|
|
277
|
+
| --- | --- |
|
|
278
|
+
| `{key}.html` | A full page load. |
|
|
279
|
+
| `{key}.flight` | A navigation that replaces the whole document. |
|
|
280
|
+
| `{key}.seg1.flight`, `{key}.seg2.flight`, … | A navigation that keeps that many layouts, so the layouts above (and a half-filled form in them) stay mounted. |
|
|
281
|
+
| `{key}.meta.json` | The client chunks and build version the payload belongs to. |
|
|
282
|
+
| `{key}.ppr.html` | A shell, stored per route *pattern* rather than per URL. |
|
|
283
|
+
|
|
284
|
+
The server checks for a stored file before it renders, and renders when there
|
|
285
|
+
is none. The build writes them to `.output/server/rsc-static`. On other Nitro
|
|
286
|
+
presets they go wherever the server is deployed: inside the function on Vercel
|
|
287
|
+
(`.vercel/output/functions/__server.func/rsc-static`) and Netlify, and among
|
|
288
|
+
the static assets on Cloudflare, read through the assets binding.
|
|
359
289
|
|
|
360
|
-
|
|
361
|
-
|
|
290
|
+
`prerender` is also exported from `@rsc-kit/core/prerender` for running it
|
|
291
|
+
yourself. Its `write` option is a callback, since not every platform has a
|
|
292
|
+
filesystem; `writeTo` is the `node:fs` version. The build calls it for you, so
|
|
293
|
+
you shouldn't need it.
|