@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.
Files changed (60) hide show
  1. package/dist/recipes.js +37 -20
  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 -250
  7. package/guides/bap-vs-inertia.md +67 -25
  8. package/guides/blueprints.md +307 -174
  9. package/guides/bun.md +42 -25
  10. package/guides/caching.md +46 -49
  11. package/guides/coming-from-inertia.md +5 -5
  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 -538
  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 +272 -150
  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 -538
  59. package/guides/laravel.md +0 -786
  60. 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
- Pages that do not need the request can be rendered once, at build time, and
6
- served from disk — no render per request, no round trip to a database.
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
- ## The build decides by rendering
8
+ ```bash
9
+ bun run build
10
+ # ○ /
11
+ # ○ /about
12
+ # ◔ /account
13
+ #
14
+ # 2 stored, 1 shell
15
+ ```
9
16
 
10
- Nothing declares whether a route is stored. The build renders each one with a
11
- budget and watches what happens:
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
- | Outcome | What the probe saw |
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 budget expired, but the static parts had painted. The shell is stored; the rest is rendered per request. |
17
- | A redirect | The route only redirects, so the redirect itself is stored — status and location. |
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
- The budget is 2 seconds, and `RSC_PPR_TIMEOUT_MS` changes it. A page whose data
21
- resolves inside it is stored whole — including one that called `fetch()`, as
22
- long as the answer arrived.
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
- Waiting does not hold up the build. A page that has rendered what it can and is
25
- only waiting steps aside for the next one, so hundreds of shells cost about one
26
- budget between them, not one each.
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
- There is no way to opt out, and that is the point: a route the build cannot
29
- store has its boundary in the wrong place. Put the part that waits inside
30
- `<Suspense>`, or add a `loading.tsx` beside the page, and it becomes a shell.
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
- <Aside type="caution" title="Stored means stored">
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
- ## Listing the URLs of a parameterised route
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 decision, not a
99
- failure — `/posts/[slug]` in the example app declares no params precisely so
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
- `vite build` does it, at the end, once every bundle exists — prerendering is
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, in the page, with [`connection()`](/guides/connection):
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. This is the same model Next has with cache components, where
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
- Per route, keyed by its URL — `/` becomes `index`, `/docs/install` becomes
164
- `docs/install`:
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
- | File | For |
167
- | --- | --- |
168
- | `{key}.html` | A full page load. |
169
- | `{key}.flight` | An SPA navigation that replaces the whole document. |
170
- | `{key}.seg1.flight`, `{key}.seg2.flight`, … | An SPA navigation that keeps that many layouts. |
171
- | `{key}.meta.json` | The client chunks and build version the payload belongs to. |
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
- The generated server does this for you: the build freezes pages into
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, which includes whatever the clock
196
- said at build time. So this renders once, during the build, and serves that
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. Not "a few seconds stale" — the moment your CI ran.
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 says so rather than leaving you to notice:
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
- <Aside type="caution" title="Suspense alone does not fix this">
220
- Wrapping it in a boundary changes nothing: prerendering renders straight
221
- through a component that never awaits, so the value is captured exactly as
222
- before — same `○`, same warning. A boundary becomes a hole only when
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 comes from is what decides it, not whether the component is a
235
- client one:
167
+ Where the value is read decides what happens:
236
168
 
237
- | the value is | result |
169
+ | The value is | Result |
238
170
  | --- | --- |
239
- | read in a server component | frozen at build time, and the build warns |
240
- | read in a client component's body | produced twice, and the two disagree |
241
- | computed on the server, passed as a prop | travels in the payload, so both renders read the same string |
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
- The third row is the ordinary answer for anything the server can decide. It
245
- does hydrate the client component, and there is no mismatch, because the value
246
- arrived rather than being recomputed. It is still frozen with the page, which
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 genuinely per-visitor and needs no server — a clock,
252
- `localStorage`, a map, an editor — say so, and React will skip the component on
253
- the server:
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
- That fallback is what visitors see in the first paint, and the real thing
282
- replaces it once the browser renders. There is no mismatch to have, because
283
- only one side ever ran.
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 `reason` is optional and only ever read on the server, where it shows up in
295
- the renderer's bailout callback. Give it one anyway — it is the sentence the
296
- next person needs. Pass a function if building it is expensive.
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
- <Aside type="note" title="This replaced a workaround">
299
- The old answer was an empty first render plus a `useEffect`, which worked by
300
- making both renders agree on nothing. `browser()` lands the same outcome with
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
- This package ships no `ClientOnly` of its own, and now never will — the
305
- boundary was always React's to draw.
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'` and the build writes a directory a static host
311
- can serve with no origin at all:
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
- It refuses unless every route came out static. A shell on a static host is a
319
- page that loads and then stays empty forever, because there is nothing running
320
- to fill it in. `RSC_EXPORT_FORCE=1` writes the site anyway and reports what it
321
- left out, which is how you move an app towards being exportable.
322
-
323
- A route that only redirects is written as a meta refresh, which is the one
324
- redirect every static host performs without being configured.
325
-
326
- Everything a server would have answered as a file comes along: the browser
327
- bundle, your `public/` folder, the icons and share image beside the root
328
- layout, the web manifest and the service worker. So do stored `route.ts`
329
- answers - `robots.txt`, `sitemap.xml`, a JSON feed - written as the files they
330
- are. A static host types a file by its extension, so only an answer at a url
331
- with one can keep its content type: `/api/health` would be served without its
332
- `application/json`, and the build lists it as left out rather than exporting
333
- it wrong. Give such a route an extension (`/api/health.json`), or serve it
334
- from a host that runs.
335
-
336
- ## Customising the document
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
- <Aside type="tip" title="Fonts and global CSS belong in the root layout">
355
- The root layout renders once and survives every SPA navigation, so its
356
- `<link>` tags load a single time. The same tags in a nested layout or a page
357
- are re-injected on every navigation.
358
- </Aside>
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
- Per-page titles and meta tags come from the page, not the layout — see
361
- [Page metadata](/guides/metadata).
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.