@rsc-kit/mcp 0.41.0 → 0.42.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.
Files changed (60) hide show
  1. package/dist/recipes.js +18 -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 +270 -216
  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,8 +2,8 @@
2
2
 
3
3
  > Refreshing one region of a page without re-rendering the rest.
4
4
 
5
- A page often has one part that changes and a lot that does not. A section names
6
- that part, so an action can refresh it on its own.
5
+ A section is a part of a page that an action can refresh on its own. Name a file
6
+ `<name>.section.tsx`:
7
7
 
8
8
  ```tsx title="src/app/orders/orders.section.tsx"
9
9
  import { section } from '@rsc-kit/core/section'
@@ -23,16 +23,20 @@ const Orders = section('orders', OrdersList)
23
23
  export default Orders
24
24
  ```
25
25
 
26
- The name passed to `section()` is the file's: `orders.section.tsx` is the
27
- section `orders`, and `revalidate('orders')` is how an action refreshes it. The
28
- renderer finds a section by its file and the browser by the name it was given,
29
- so a section whose two names differ would refresh nothing; the build refuses
26
+ Then `revalidate('orders')` in an action renders that part again, and nothing
27
+ else.
28
+
29
+ ## Defining a section
30
+
31
+ The name passed to `section()` must match the file: `orders.section.tsx` is the
32
+ section `orders`. The renderer finds a section by its file and the browser by
33
+ its name, so a section whose two names differ would refresh nothing: the build refuses
30
34
  one, and says which file to rename.
31
35
 
32
- Give the section a name before exporting it, as above, rather than writing
33
- `export default section(...)`. An editor offers an import by the name a default
34
- export has, and a call has none: it falls back to one made up from the file name,
35
- `OrdersSection`, so typing `<Orders` finds nothing to import.
36
+ Assign the section to a variable before exporting it, as above, rather than
37
+ writing `export default section(...)`. An editor names an import after the
38
+ default export, and a call has no name: it falls back to one made from the file
39
+ name, `OrdersSection`, so typing `<Orders` finds nothing to import.
36
40
 
37
41
  Render it like any other component:
38
42
 
@@ -51,7 +55,7 @@ export default function OrdersPage() {
51
55
 
52
56
  ## Refreshing it
53
57
 
54
- An action names what it changed, and only that region is rendered again:
58
+ An action names what it changed, and only that section is rendered again:
55
59
 
56
60
  ```tsx
57
61
  'use server'
@@ -65,27 +69,26 @@ export async function placeOrder(form: FormData) {
65
69
  }
66
70
  ```
67
71
 
68
- The rest of the page is untouched — not re-rendered and not re-fetched. Whatever
69
- state lives outside the section, including a half-filled form beside it, stays
70
- exactly as it was.
72
+ The rest of the page is not rendered or fetched again, so state outside the
73
+ section, such as a half-filled form beside it, stays as it was.
74
+
75
+ With a backend, the backend names it: Go's `rsckit.Revalidate(ctx, "orders")`
76
+ or Laravel's `Rsc::revalidate('orders')`.
77
+
78
+ ### When the calling page has no such section
71
79
 
72
- ### From an action called on another page
80
+ An action says what it changed, not which page called it. When the page that
81
+ called it has no `orders` section, its own or one beside its layouts, there is
82
+ nothing on screen to refresh: the name is skipped and the action still answers.
73
83
 
74
- An action says what it changed, not which page called it. A backend's
75
- action cannot know at all: Go's `rsckit.Revalidate(ctx, "orders")` and
76
- Laravel's `Rsc::revalidate('orders')` name the data. When the page that
77
- called the action has no `orders` section - its own or one beside its layouts -
78
- there is nothing on screen to refresh, and the name is skipped; the action still answers. A name no page
79
- in the app has is a mistake, and the action fails, naming the sections and
80
- slots the calling page does have.
84
+ A name that no page in the app has is a mistake. The action fails, naming the
85
+ sections and slots the calling page does have.
81
86
 
82
- ## In a layout
87
+ ## A section in a layout
83
88
 
84
- A layout stays mounted while you move between the pages under it. So the part of
85
- a screen that is the same on every tab - a title, a status, the tab bar - belongs
86
- there, where it does not go away and come back when a tab is clicked. When that
87
- part shows data that changes, make it a section, and any page under the layout
88
- can refresh it by name:
89
+ A layout stays mounted while you move between the pages under it. Put what every
90
+ tab shares there, such as a title, a status or the tab bar, and make it a section
91
+ when it shows data that changes:
89
92
 
90
93
  ```tsx title="src/app/[team]/[app]/layout.tsx"
91
94
  import { Suspense } from 'react'
@@ -120,53 +123,47 @@ const Header = section('header', AppHeader, {
120
123
  export default Header
121
124
  ```
122
125
 
123
- The header reads `params`, so it has its own `<Suspense>`: the layout paints with
124
- the skeleton at once and the header streams in. A layout that awaits `params`
125
- above every boundary is refused at build, on a route that lists no urls.
126
+ The header reads `params`, so it has its own `<Suspense>`: the layout paints the
127
+ skeleton at once and the header streams in. A layout that awaits `params` above
128
+ every boundary is refused at build, on a route that lists no URLs.
126
129
 
127
- `revalidate('header')` from an action called on any page under the layout
128
- refreshes it, and so does `refreshOn`. A page's sections are the ones beside it
129
- and then the ones beside each of its layouts, nearest first, so:
130
+ `revalidate('header')` from an action on any page under the layout refreshes it.
131
+ A tab switch then replaces only the page, and the header is already there.
130
132
 
131
- - **The name is unique along the chain.** A page's `header` and its layout's are
132
- one name on one screen; the nearer one is the one a refresh renders.
133
+ - **Names are looked up nearest first.** A page's sections are the ones beside
134
+ it, then the ones beside each of its layouts. If a page and its layout both
135
+ have a `header`, a refresh renders the page's.
133
136
  - **A refresh renders the section with the page's props**, `params` and
134
- `searchParams`, awaitable as the page's own are, not the ones the layout
135
- passed. Pass `params` through, as above, and read what the section needs from
136
- it: a page's `params` hold every segment the layout's do.
137
- - **A refresh keeps the section on screen until it is ready.** The new
138
- content is swapped in as a transition, so a section whose refresh is still
139
- arriving keeps showing what it showed - it does not fall back to the nearest
140
- `loading.tsx` or `<Suspense>` skeleton on every save. One that is ready shows
141
- at once.
137
+ `searchParams`, not the ones the layout passed. Pass `params` through, as
138
+ above: a page's `params` hold every segment the layout's do.
139
+ - **A refresh keeps the section on screen until it is ready.** The new content
140
+ is swapped in as a transition, so the section doesn't fall back to a skeleton
141
+ on every save.
142
142
  - **A refresh lasts as long as its layout.** Moving to another page under the
143
- layout keeps what the refresh rendered; a navigation that renders the layout
144
- again - to a page under a different one - renders the section with it.
145
- - **The active tab is not a refresh.** Mark it from `usePathname()` in a client
146
- component inside the section; it follows the url on every navigation.
147
-
148
- A tab switch then replaces only the page. The header is already there.
143
+ same layout keeps it. A navigation to a page under a different layout renders
144
+ the section again.
145
+ - **Mark the active tab with `usePathname()`**, in a client component inside the
146
+ section. It follows the URL on every navigation, with no refresh.
149
147
 
150
148
  ## Refreshing on a change from outside
151
149
 
152
- An action refreshes the sections it changed. For a change made anywhere else -
153
- a webhook, a job, another visitor - a section can name what it depends on and
154
- refresh itself in every open tab: `section('repos', Repos, { refreshOn })`.
155
- That has its own guide: [Live data](/guides/live-data).
150
+ An action refreshes the sections it changed. For a change made anywhere else,
151
+ such as a webhook, a job or another visitor, a section can name the data it
152
+ shows and refresh in every open tab:
156
153
 
157
- ## The name is scoped to the module, not the app
154
+ ```tsx
155
+ section('repos', Repos, { refreshOn: ['repos'] })
156
+ ```
158
157
 
159
- Two pages may both call their section `orders`. The name is resolved through the
160
- modules the route declares - the sections beside the page and beside its
161
- layouts - not through a table every section in the app writes to.
158
+ See [Live data](/guides/live-data).
162
159
 
163
- That is a security property rather than a convenience. A name-keyed registry is
164
- populated by every section at bundle load, so a lookup by name could reach any
165
- page's region from any url — bounded only by whatever guard happened to sit on
166
- the url that was asked for.
160
+ ## How names are found
167
161
 
168
- ## What a section is not
162
+ Two pages may both call a section `orders`. A name is looked up only among the
163
+ sections beside the page and its layouts, never in a table of every section in
164
+ the app. So a refresh can only reach regions of the page that asked for it,
165
+ behind that page's own guards.
169
166
 
170
- It is not a cache boundary and not a client component. It renders on the server
171
- like everything else; what it adds is a seam the server can render *into* on its
172
- own, without producing the whole page around it.
167
+ A section is not a cache boundary and not a client component. It renders on the
168
+ server like everything else, and it can be rendered on its own, without the
169
+ page around it.
@@ -4,16 +4,35 @@
4
4
 
5
5
  A crawler asks for `/robots.txt` and `/sitemap.xml` before it reads a page,
6
6
  and a model asks for `/llms.txt`. Each comes from a file beside the root
7
- layout, named for what it answers:
7
+ layout:
8
8
 
9
- | file | answers | returns |
9
+ ```ts title="src/app/robots.ts"
10
+ import type { MetadataRoute } from '@rsc-kit/core/metadata';
11
+
12
+ export default function robots(): MetadataRoute.Robots {
13
+ return {
14
+ rules: [{ userAgent: '*', allow: '/', disallow: '/admin/' }],
15
+ sitemap: '/sitemap.xml',
16
+ };
17
+ }
18
+ ```
19
+
20
+ | File | Answers | Returns |
10
21
  | --- | --- | --- |
11
22
  | `src/app/robots.ts` | `/robots.txt` | `MetadataRoute.Robots` |
12
23
  | `src/app/sitemap.ts` | `/sitemap.xml` | `MetadataRoute.Sitemap` |
13
24
  | `src/app/llms.ts` | `/llms.txt` | `MetadataRoute.Llms` |
14
25
  | `src/app/llms-full.ts` | `/llms-full.txt` | a string |
15
26
 
16
- The same names and shapes as Next, so a port copies them across unchanged.
27
+ The names and shapes are the same as Next, so a port copies them across
28
+ unchanged.
29
+
30
+ A relative URL in any of them is made absolute with the root layout's
31
+ `metadataBase`. Without one, a relative URL is a build error that says so.
32
+
33
+ ## Writing robots.txt
34
+
35
+ List a rule per user agent:
17
36
 
18
37
  ```ts title="src/app/robots.ts"
19
38
  import type { MetadataRoute } from '@rsc-kit/core/metadata';
@@ -29,6 +48,10 @@ export default function robots(): MetadataRoute.Robots {
29
48
  }
30
49
  ```
31
50
 
51
+ ## Writing a sitemap
52
+
53
+ Return one entry per URL. Reading the database is fine:
54
+
32
55
  ```ts title="src/app/sitemap.ts"
33
56
  import type { MetadataRoute } from '@rsc-kit/core/metadata';
34
57
  import { db } from '@/lib/db';
@@ -44,57 +67,49 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
44
67
  }
45
68
  ```
46
69
 
47
- ```ts title="src/app/llms.ts"
48
- import type { MetadataRoute } from '@rsc-kit/core/metadata';
70
+ ### Letting the build write it
49
71
 
50
- export default function llms(): MetadataRoute.Llms {
51
- return {
52
- title: 'Example',
53
- summary: 'What the site is, in one sentence.',
54
- sections: [
55
- { title: 'Pages', links: [{ title: 'Pricing', url: '/pricing', description: 'Per restoration, no subscription' }] },
56
- ],
57
- };
58
- }
59
- ```
60
-
61
- A relative url in any of them is made absolute with the root layout's
62
- `metadataBase`; without one, a relative url is a build error that says so.
63
- Any of the three may return a string instead, served as written.
64
-
65
- ## A sitemap you do not write
66
-
67
- With no `sitemap.ts`, the build writes `/sitemap.xml` itself, from what it
68
- already knows: every page it stored and every url `generateStaticParams`
69
- listed, each with the build as `lastModified`. Left out: anything under a
70
- `middleware.ts` (a guard means not for everyone), a page the build could not
71
- render, and the not-found page. The build's table says so:
72
+ With no `sitemap.ts`, the build writes `/sitemap.xml` itself from what it
73
+ already knows: every page it stored, and every URL `generateStaticParams`
74
+ listed, each with the build as `lastModified`. The build's table says so:
72
75
 
73
- ```
76
+ ```text
74
77
  ○ /sitemap.xml
75
78
  written by the build: 5 urls; a sitemap.ts beside the root layout replaces it
76
79
  ```
77
80
 
78
- It needs the root layout's `metadataBase` for the host; without one the line
79
- says it was not written. A `sitemap.ts` replaces it entirely — the moment you
80
- want a page the build cannot see (a post per database row without
81
- `generateStaticParams`) or a `changeFrequency`, write one.
81
+ It leaves out:
82
+
83
+ - anything under a `middleware.ts`, since a guard means not for everyone;
84
+ - a page the build could not render;
85
+ - the not-found page.
86
+
87
+ It needs the root layout's `metadataBase` for the host. Without one, the line
88
+ says it was not written.
89
+
90
+ A `sitemap.ts` replaces it entirely. Write one as soon as you want a page the
91
+ build can't see, such as a post per database row without
92
+ `generateStaticParams`, or a `changeFrequency`.
82
93
 
83
- ## How fresh
94
+ ### Keeping it fresh
84
95
 
85
- Three choices, and the function decides — the same rule every route follows:
96
+ The function decides, by the same rule as every route:
86
97
 
87
- | you write | served | fresh |
98
+ | You write | Served | Fresh |
88
99
  | --- | --- | --- |
89
100
  | nothing | the build's own sitemap, stored | every deploy |
90
101
  | a `sitemap.ts` that reads the database | stored at build | every deploy |
91
102
  | a `sitemap.ts` that awaits `connection()` | rendered per request | every crawl |
92
103
 
104
+ To answer every crawl from the database, await `connection()` first:
105
+
93
106
  ```ts title="src/app/sitemap.ts"
107
+ import type { MetadataRoute } from '@rsc-kit/core/metadata';
94
108
  import { connection } from '@rsc-kit/core/request';
109
+ import { db } from '@/lib/db';
95
110
 
96
111
  export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
97
- await connection(); // per request — the same mark a page uses
112
+ await connection(); // per request, the same mark a page uses
98
113
 
99
114
  const posts = await db.post.findMany({ select: { slug: true, updatedAt: true } });
100
115
 
@@ -102,45 +117,92 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
102
117
  }
103
118
  ```
104
119
 
105
- Without the `connection()` line the same function runs once at build and the
106
- answer is stored; the build's table shows `○` for a stored one and `ƒ` for
107
- one that runs per request. Reading the database at build is fine — it is the
108
- request that makes a route dynamic, not the data.
120
+ Without the `connection()` line, the same function runs once at build and the
121
+ answer is stored. The build's table shows `○` for a stored one and `ƒ` for one
122
+ that runs per request. It is the request that makes a route dynamic, not the
123
+ data.
109
124
 
110
- ## How they are served
125
+ ## Writing llms.txt
111
126
 
112
- Each file becomes an api route, and that decides the rest. A `sitemap.ts`
113
- that reads nothing per request — the database counts as nothing, the request
114
- does not — is answered once at build and stored, like any frozen route, and
115
- served from the file after. One that reads `cookies()` or awaits
116
- `connection()` stays dynamic and runs per request. The build's table lists
117
- them with the other routes and says which.
127
+ Give the site a title, a summary and sections of links:
118
128
 
119
- They run no middleware, on purpose: a guard on the root layout's directory
120
- would otherwise answer a crawler's request for `robots.txt` with a 401.
129
+ ```ts title="src/app/llms.ts"
130
+ import type { MetadataRoute } from '@rsc-kit/core/metadata';
121
131
 
122
- The urls are typed like every other route, so `route('/sitemap.xml')` is a
123
- link the build checks.
132
+ export default function llms(): MetadataRoute.Llms {
133
+ return {
134
+ title: 'Example',
135
+ summary: 'What the site is, in one sentence.',
136
+ sections: [
137
+ {
138
+ title: 'Pages',
139
+ links: [{ title: 'Pricing', url: '/pricing', description: 'Per restoration, no subscription' }],
140
+ },
141
+ ],
142
+ };
143
+ }
144
+ ```
145
+
146
+ `llms-full.ts` returns the whole text as a string:
124
147
 
125
- ## Files as written
148
+ ```ts title="src/app/llms-full.ts"
149
+ import { allDocs } from '@/lib/docs';
150
+
151
+ export default async function llmsFull(): Promise<string> {
152
+ const docs = await allDocs();
153
+
154
+ return docs.map((doc) => `# ${doc.title}\n\n${doc.body}`).join('\n\n');
155
+ }
156
+ ```
157
+
158
+ `robots.ts`, `sitemap.ts` and `llms.ts` may return a string too, served as
159
+ written.
160
+
161
+ ## Serving a file as written
126
162
 
127
163
  A hand-written file beside the root layout is served at the root as it is:
128
164
  `robots.txt`, `sitemap.xml` (or `sitemap-posts.xml`), `llms.txt`,
129
- `llms-full.txt`, and the others a site is asked for there — `humans.txt`,
130
- `security.txt`, `ads.txt`. In development they are read from `app/`; a build
131
- copies them beside the client output. A file and a function for the same url
132
- is a build error naming both.
133
-
134
- A file of the same name in `public/` wins over both: whatever serves
135
- `public/` — Herd, nginx in front of Laravel, the server's static handler —
136
- answers before the app is reached. Laravel's skeleton ships a
165
+ `llms-full.txt`, and the others a site is asked for there, such as
166
+ `humans.txt`, `security.txt` and `ads.txt`:
167
+
168
+ ```text
169
+ src/app/
170
+ layout.tsx
171
+ humans.txt /humans.txt
172
+ security.txt /security.txt
173
+ ```
174
+
175
+ In development they are read from `app/`, and a build copies them beside the
176
+ client output. A file and a function for the same URL is a build error naming
177
+ both.
178
+
179
+ A file of the same name in `public/` wins over both. Whatever serves `public/`
180
+ (Herd, nginx in front of Laravel, the server's static handler) answers before
181
+ the app is reached. Laravel's skeleton ships a
137
182
  `public/robots.txt`, so a `robots.ts` beside the root layout is never seen
138
183
  until it is deleted. Dev start and the build warn, naming both files.
139
184
 
185
+ ## Linking to them
186
+
187
+ The URLs are typed like every other route, so `route('/sitemap.xml')` is a
188
+ link the build checks.
189
+
140
190
  ## Coming from Next
141
191
 
142
- `app/robots.ts` and `app/sitemap.ts` carry across unchanged. `app/llms.txt`
143
- in Next is usually a `route.ts`; here it is `llms.ts` with a shape, or a file
144
- as written. Next's `generateSitemaps()` for a sitemap split across files is
145
- not here: a `sitemap-posts.xml` written by hand, or a `route.ts` under
146
- `app/sitemap/`, covers it.
192
+ `app/robots.ts` and `app/sitemap.ts` carry across unchanged. In Next,
193
+ `app/llms.txt` is usually a `route.ts`. Here it is `llms.ts` with a shape, or
194
+ a file as written. Next's `generateSitemaps()`, for a sitemap split across
195
+ files, isn't here: a `sitemap-posts.xml` written by hand, or a `route.ts`
196
+ under `app/sitemap/`, covers it.
197
+
198
+ ## How they are served
199
+
200
+ Each file becomes an API route, and that decides the rest. One that reads
201
+ nothing per request is answered once at build, stored like any frozen route,
202
+ and served from the file after. The database counts as nothing here; the
203
+ request doesn't. One that reads `cookies()` or awaits `connection()` stays
204
+ dynamic and runs per request. The build's table lists them with the other
205
+ routes and says which.
206
+
207
+ They run no middleware, on purpose. A guard on the root layout's folder would
208
+ otherwise answer a crawler's request for `robots.txt` with a 401.