@rsc-kit/mcp 0.30.45 → 0.30.47
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 +11 -5
- package/dist/recipes.js.map +1 -1
- package/guides/caching.md +2 -1
- package/guides/coming-from-next.md +4 -3
- package/guides/deployment.md +3 -3
- package/guides/edge-caching.md +18 -7
- package/guides/go.md +15 -0
- package/guides/index.json +7 -2
- package/guides/isr.md +172 -0
- package/guides/laravel.md +16 -0
- package/guides/public-forms.md +124 -7
- package/guides/your-own-backend.md +5 -4
- package/package.json +2 -2
package/guides/caching.md
CHANGED
|
@@ -86,7 +86,8 @@ export async function savePage(values: PageValues) {
|
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
`changed()` is the same call that refreshes open tabs for
|
|
89
|
-
[live data](/guides/live-data)
|
|
89
|
+
[live data](/guides/live-data), and a page kept with [ISR](/guides/isr) that read
|
|
90
|
+
this answer renders again too. Nothing is purged. Each kept answer's key
|
|
90
91
|
includes its tags' versions, so a change makes a new key, and the old entry is
|
|
91
92
|
never read again. `tags` can also be a function of the arguments, for a tag per
|
|
92
93
|
record:
|
|
@@ -90,9 +90,10 @@ which, and why:
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
`await connection()` is the one explicit mark, for a page that must render per
|
|
93
|
-
visitor and does not happen to read anything.
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
visitor and does not happen to read anything. A frozen page changes when you
|
|
94
|
+
build, and a dynamic one on every request. [ISR](/guides/isr) is the middle, and
|
|
95
|
+
it works as you expect: `export const revalidate = 60`, with `changed(tag)` in
|
|
96
|
+
the place of `revalidateTag`.
|
|
96
97
|
|
|
97
98
|
### Middleware is per directory, not one file at the edge
|
|
98
99
|
|
package/guides/deployment.md
CHANGED
|
@@ -303,8 +303,8 @@ rsc-kit implements the [edge contract](/reference/edge-contract): one marker
|
|
|
303
303
|
and two endpoints that an edge uses the same way for every framework that
|
|
304
304
|
implements it. next-bun-compile implements it too. The edge serves a static
|
|
305
305
|
page whole and a PPR page's shell straight from its cache, and has the origin
|
|
306
|
-
render only a shell's holes, onto the same response. [
|
|
307
|
-
|
|
306
|
+
render only a shell's holes, onto the same response. [Edge
|
|
307
|
+
caching](/guides/edge-caching) covers what that buys. What rsc-kit puts in it:
|
|
308
308
|
|
|
309
309
|
- **`.output/edge.json`** is written by every server build, with empty lists
|
|
310
310
|
when there is nothing to list. An export writes none.
|
|
@@ -437,7 +437,7 @@ A route that declares middleware is never cached publicly: it is sent as
|
|
|
437
437
|
`private, no-store`, because middleware runs per visitor. If something in front
|
|
438
438
|
of your app also owns the response — an auth proxy re-issuing a session on
|
|
439
439
|
pass-through — give the paths it covers a `middleware.ts` so this host knows
|
|
440
|
-
they are covered. See [
|
|
440
|
+
they are covered. See [edge caching](/guides/edge-caching).
|
|
441
441
|
|
|
442
442
|
## Rebuild on deploy
|
|
443
443
|
|
package/guides/edge-caching.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Edge caching
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Serving prerendered pages, PPR shells and kept pages from a CDN, the headers they go out with, and purging by tag.
|
|
4
4
|
|
|
5
5
|
A prerendered page is a file. So is a PPR shell. Both can sit on a CDN and be
|
|
6
6
|
served without touching your origin.
|
|
@@ -61,7 +61,7 @@ new deploy does not leave old shells being served against a new payload.
|
|
|
61
61
|
|
|
62
62
|
A page whose data changes after the build is rendered for each request, and
|
|
63
63
|
sent `private`. When the same answer may go to everyone for a while, say how
|
|
64
|
-
long:
|
|
64
|
+
long. [ISR](/guides/isr) is the how-to; this is what goes over the wire:
|
|
65
65
|
|
|
66
66
|
```tsx
|
|
67
67
|
// app/posts/[slug]/page.tsx
|
|
@@ -73,11 +73,16 @@ read nothing that belongs to one visitor, it goes out as:
|
|
|
73
73
|
|
|
74
74
|
```
|
|
75
75
|
Cache-Control: public, max-age=0, s-maxage=60, stale-while-revalidate=86400, stale-if-error=86400
|
|
76
|
+
CDN-Cache-Control: max-age=60, stale-while-revalidate=86400, stale-if-error=86400
|
|
76
77
|
ETag: "…"
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
A CDN keeps it for 60 seconds and refreshes it in the background after that;
|
|
80
|
-
a browser never keeps it.
|
|
81
|
+
a browser never keeps it. rsc-kit sends `CDN-Cache-Control` (RFC 9213), so a
|
|
82
|
+
CDN that reads it can cache pages: Cloudflare does, and Homeport's edge caches
|
|
83
|
+
on nothing else and strips it before the answer leaves, so you will not see it
|
|
84
|
+
in a browser there. The two headers always say the same thing, and only a
|
|
85
|
+
public answer has either. While your origin is down, erroring or mid-deploy, a
|
|
81
86
|
CDN that reads `stale-if-error` serves the copy it has for up to a day rather
|
|
82
87
|
than the error. A cache revalidating a copy that has not changed is
|
|
83
88
|
answered `304`. A 404 - including the not-found.tsx a navigation shows - is
|
|
@@ -157,17 +162,23 @@ installPurge(async ({ tags }) => {
|
|
|
157
162
|
```
|
|
158
163
|
|
|
159
164
|
Every CDN's purge API is its own, so this is one hook rather than a list of
|
|
160
|
-
vendors. A purge that fails is logged
|
|
161
|
-
|
|
165
|
+
vendors. A purge that fails is logged and never fails the change: the CDN
|
|
166
|
+
still drops its copy at its `max-age` in `CDN-Cache-Control`. `purge({ tags, paths, all })` sends
|
|
162
167
|
one yourself, from a deploy step or a webhook.
|
|
163
168
|
|
|
164
169
|
On Homeport there is nothing to install. With `HOMEPORT_PURGE_URL` set, the
|
|
165
170
|
hook is `homeportPurge()` unless you installed another. With a Laravel or Go
|
|
166
|
-
backend, the change is made there - `Rsc::changed()`, `
|
|
171
|
+
backend, the change is made there - `Rsc::changed()`, `reg.Changed()` - and
|
|
167
172
|
never passes through the engine, so the backend posts the purge itself; both
|
|
168
173
|
do when `HOMEPORT_PURGE_URL` is set. A tag with a comma or a space cannot go in the header, and
|
|
169
174
|
is left out with a warning.
|
|
170
175
|
|
|
176
|
+
Homeport's edge is stricter about what it keeps than the page's headers alone
|
|
177
|
+
say. A page with more than 128 tags, or a tag over 1024 bytes, is served but
|
|
178
|
+
not kept there, and so is one that sends `Vary: Cookie` or `Vary: Authorization`
|
|
179
|
+
or names more than 16 headers in `Vary`, which a `revalidate` page only does if
|
|
180
|
+
your own code adds them.
|
|
181
|
+
|
|
171
182
|
**A revalidate page calls its backend as nobody.** Its host calls carry no
|
|
172
183
|
cookie and no `Authorization`, and a cookie the backend sets is dropped -
|
|
173
184
|
`auth()->user()` is null there, as it is for every visitor a shared copy is
|
package/guides/go.md
CHANGED
|
@@ -389,6 +389,21 @@ it signs the names a page hands the tab, and is not the host-call secret.
|
|
|
389
389
|
Generating and rotating both: [Secrets](/hosts/deployment#secrets). [Sections](/guides/live-data)
|
|
390
390
|
has the whole picture.
|
|
391
391
|
|
|
392
|
+
## Pages kept between requests
|
|
393
|
+
|
|
394
|
+
`export const revalidate = 60` keeps a page and refreshes it behind the visitor,
|
|
395
|
+
and `reg.Changed(ctx, "posts")` renders it again at once on every instance, when
|
|
396
|
+
it read that tag through `cache()`. A kept page calls Go as nobody: no `Cookie`,
|
|
397
|
+
no `Authorization`. With `HOMEPORT_PURGE_URL` set, `Changed` purges the CDN as
|
|
398
|
+
well; `reg.SetPurger` replaces it. Call it after your transaction commits.
|
|
399
|
+
[ISR](/guides/isr) has the whole of it.
|
|
400
|
+
|
|
401
|
+
## Public forms
|
|
402
|
+
|
|
403
|
+
A contact form or a sign-up is `defineForm` in TypeScript, and `handle` calls a
|
|
404
|
+
function registered here. `rsckit.InvalidField` shows under that field.
|
|
405
|
+
[Public forms](/guides/public-forms#go) has the code.
|
|
406
|
+
|
|
392
407
|
## Production
|
|
393
408
|
|
|
394
409
|
`bun run build` and `bun run start` with the same two variables in the
|
package/guides/index.json
CHANGED
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
"slug": "edge-caching",
|
|
74
|
-
"title": "
|
|
75
|
-
"description": "
|
|
74
|
+
"title": "Edge caching",
|
|
75
|
+
"description": "Serving prerendered pages, PPR shells and kept pages from a CDN, the headers they go out with, and purging by tag."
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
"slug": "emails",
|
|
@@ -134,6 +134,11 @@
|
|
|
134
134
|
"title": "Introduction",
|
|
135
135
|
"description": "React Server Components as a Vite plugin, deployed wherever you like."
|
|
136
136
|
},
|
|
137
|
+
{
|
|
138
|
+
"slug": "isr",
|
|
139
|
+
"title": "ISR",
|
|
140
|
+
"description": "A page rendered once and served to everyone, refreshed on a timer or the moment its data changes. On one server, several pods or a Worker, with Laravel, Go or no backend."
|
|
141
|
+
},
|
|
137
142
|
{
|
|
138
143
|
"slug": "laravel",
|
|
139
144
|
"title": "Laravel",
|
package/guides/isr.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# ISR
|
|
2
|
+
|
|
3
|
+
> A page rendered once and served to everyone, refreshed on a timer or the moment its data changes. On one server, several pods or a Worker, with Laravel, Go or no backend.
|
|
4
|
+
|
|
5
|
+
ISR is one line. A page that exports `revalidate` is rendered once and served
|
|
6
|
+
to everyone from a kept copy, then replaced in the background. It needs no CDN:
|
|
7
|
+
the host keeps the copy itself, on every platform, and with a Laravel or Go
|
|
8
|
+
backend the page is the same.
|
|
9
|
+
|
|
10
|
+
```tsx title="src/app/posts/[slug]/page.tsx"
|
|
11
|
+
export const revalidate = 60
|
|
12
|
+
|
|
13
|
+
export default async function Post({ params }: { params: Promise<{ slug: string }> }) {
|
|
14
|
+
const { slug } = await params
|
|
15
|
+
const post = await findPost(slug)
|
|
16
|
+
|
|
17
|
+
return <article>{post.title}</article>
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The value is a number literal in seconds, since the build reads it. A layout can
|
|
22
|
+
export it too: the smallest on the way down to the page wins, and `0` anywhere
|
|
23
|
+
turns it off. With Laravel the page lives under `resources/js/app`.
|
|
24
|
+
|
|
25
|
+
| Request | What happens |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| The first | The page renders, and the copy is kept. A burst of visitors renders it once. |
|
|
28
|
+
| Within `revalidate` | The kept copy is served, with no render. |
|
|
29
|
+
| Past `revalidate` | The kept copy is still served at once, and one render replaces it behind the visitor. This lasts up to a day; after that, the page renders while the visitor waits. |
|
|
30
|
+
| After `changed(tag)` | The page renders, on every instance, and is never served stale. |
|
|
31
|
+
|
|
32
|
+
A 404 is kept for a minute at most, so a scanner walking random urls cannot
|
|
33
|
+
hold your pages out.
|
|
34
|
+
|
|
35
|
+
## See it working
|
|
36
|
+
|
|
37
|
+
Pages are never kept in development, so build and start the app first. Ask for
|
|
38
|
+
a page twice:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
curl -sI http://localhost:3000/posts/hello | grep -iE 'x-rsc-kit|^age|cache-status'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The second answer has `X-RSC-Kit: cached` and an `Age`.
|
|
45
|
+
|
|
46
|
+
If it has `Cache-Status: rsc-kit; fwd=bypass; detail=cookies` instead, the page
|
|
47
|
+
was sent private, and `detail` says why. The server log says it once per page,
|
|
48
|
+
naming what read the visitor:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
[rsc-kit] /posts/[slug] exports revalidate, and was sent private: cookies() in Header
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Refresh it the moment the data changes
|
|
55
|
+
|
|
56
|
+
A timer alone means a change can take `revalidate` seconds to show. To show it
|
|
57
|
+
at once, read the data through [`cache()`](/guides/caching#across-requests) with
|
|
58
|
+
tags, and say when those tags change. A page remembers the tags it read.
|
|
59
|
+
|
|
60
|
+
```ts title="src/data/posts.ts"
|
|
61
|
+
import { cache } from '@rsc-kit/core/cache'
|
|
62
|
+
|
|
63
|
+
export const findPost = cache(
|
|
64
|
+
async (slug: string) => db.posts.findBySlug(slug),
|
|
65
|
+
{ key: 'posts.find', revalidate: 3600, tags: (slug) => ['posts', `post:${slug}`] },
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```ts title="src/app/posts/actions.ts"
|
|
70
|
+
'use server'
|
|
71
|
+
import { changed } from '@rsc-kit/core/changed'
|
|
72
|
+
|
|
73
|
+
export async function savePost(slug: string, values: PostValues) {
|
|
74
|
+
await db.posts.save(slug, values)
|
|
75
|
+
await changed(`post:${slug}`)
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### With Laravel
|
|
80
|
+
|
|
81
|
+
The read is an `rpc()` inside `cache()`, and PHP says what changed, from
|
|
82
|
+
anywhere: an action, a job, a webhook or an observer.
|
|
83
|
+
|
|
84
|
+
```ts title="resources/js/data/posts.ts"
|
|
85
|
+
import { cache } from '@rsc-kit/core/cache'
|
|
86
|
+
|
|
87
|
+
export const findPost = cache(
|
|
88
|
+
(slug: string) => rpc('Posts.find', slug),
|
|
89
|
+
{ key: 'posts.find', revalidate: 3600, tags: (slug) => ['posts', `post:${slug}`] },
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```php title="app/Rsc/Posts.php"
|
|
94
|
+
namespace App\Rsc;
|
|
95
|
+
|
|
96
|
+
use App\Models\Post;
|
|
97
|
+
use RscKit\Rsc;
|
|
98
|
+
|
|
99
|
+
class Posts
|
|
100
|
+
{
|
|
101
|
+
public function find(string $slug): Post
|
|
102
|
+
{
|
|
103
|
+
return Post::where('slug', $slug)->firstOrFail();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```php
|
|
109
|
+
// after the write
|
|
110
|
+
$post->save();
|
|
111
|
+
|
|
112
|
+
Rsc::changed("post:{$post->slug}");
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### With Go
|
|
116
|
+
|
|
117
|
+
The same read, and `Changed` on the registry:
|
|
118
|
+
|
|
119
|
+
```go
|
|
120
|
+
reg.Handle("Posts.find", func(ctx context.Context, slug string) (Post, error) {
|
|
121
|
+
return posts.Find(ctx, slug)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// after the write, from a handler, a job or a webhook
|
|
125
|
+
reg.Changed(ctx, "post:"+slug)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Call it after your transaction commits, so nobody renders the old data under
|
|
129
|
+
the new version.
|
|
130
|
+
|
|
131
|
+
## What keeps a page from being kept
|
|
132
|
+
|
|
133
|
+
The page is judged after it renders, and sent private when:
|
|
134
|
+
|
|
135
|
+
- It read the visitor: `cookies()`, `headers()`, `request()` or `connection()`,
|
|
136
|
+
anywhere in the render, a Suspense'd child included.
|
|
137
|
+
- Its answer set a cookie, or carries a CSP nonce.
|
|
138
|
+
- Its `middleware.ts` declares Laravel or Go route middleware, which runs
|
|
139
|
+
against the visitor's session.
|
|
140
|
+
- It answered anything but a 200 or a 404, or its render failed.
|
|
141
|
+
|
|
142
|
+
**A kept page calls its backend as nobody.** Its `rpc()` calls carry no cookie
|
|
143
|
+
and no `Authorization`, and a cookie the backend sets is dropped. In Laravel,
|
|
144
|
+
`auth()->user()` is null there. That is the rule rather than a limit: the copy
|
|
145
|
+
goes to every visitor. A page that shows who is signed in is not one to keep.
|
|
146
|
+
|
|
147
|
+
A form in a kept page still works: a same-origin post needs no token. See
|
|
148
|
+
[public forms](/guides/public-forms).
|
|
149
|
+
|
|
150
|
+
## On several instances
|
|
151
|
+
|
|
152
|
+
Nothing changes in the page. Each instance keeps its own copy in memory, 64 MB
|
|
153
|
+
at most, and `changed()` reaches them all, because a kept page checks its tags'
|
|
154
|
+
versions on each lookup.
|
|
155
|
+
|
|
156
|
+
- **With Laravel or Go,** the backend holds the versions, so there is nothing to
|
|
157
|
+
set up beyond [a shared store for Go](/hosts/go#saying-data-changed).
|
|
158
|
+
- **With no backend,** install a shared
|
|
159
|
+
[version source](/guides/live-data), as `refreshOn` already needs.
|
|
160
|
+
- **On a Worker or Vercel,** memory does not last, so give the page cache a
|
|
161
|
+
store with `installCacheStore()`. The host warns without one.
|
|
162
|
+
|
|
163
|
+
[Where a kept page lives](/guides/edge-caching#kept-by-the-engine-too) has the
|
|
164
|
+
table for each platform. Turn the page cache off with `pageCache: false` in the
|
|
165
|
+
host's options.
|
|
166
|
+
|
|
167
|
+
## With a CDN in front
|
|
168
|
+
|
|
169
|
+
The same page is ready for one. It goes out with `Cache-Control`,
|
|
170
|
+
`CDN-Cache-Control` and the `Cache-Tag` of every `cache()` answer it used, and
|
|
171
|
+
`changed()` can purge the CDN too. [Edge caching](/guides/edge-caching) covers
|
|
172
|
+
the headers and the purge hook.
|
package/guides/laravel.md
CHANGED
|
@@ -418,6 +418,22 @@ the channel is public, and names may be one visitor's - so Laravel still
|
|
|
418
418
|
answers which names moved, and the renderer never touches the database. It is
|
|
419
419
|
sent after the transaction commits.
|
|
420
420
|
|
|
421
|
+
## Pages kept between requests
|
|
422
|
+
|
|
423
|
+
`export const revalidate = 60` keeps a page and refreshes it behind the visitor,
|
|
424
|
+
and `Rsc::changed('posts')` renders it again at once on every instance, when it
|
|
425
|
+
read that tag through `cache()`. A kept page calls PHP as nobody, so
|
|
426
|
+
`auth()->user()` is null there. With `HOMEPORT_PURGE_URL` set, `Rsc::changed()`
|
|
427
|
+
purges the CDN as well, after the transaction commits and the response has gone.
|
|
428
|
+
[ISR](/guides/isr) has the whole of it.
|
|
429
|
+
|
|
430
|
+
## Public forms
|
|
431
|
+
|
|
432
|
+
A contact form or a sign-up is `defineForm` in TypeScript, and `handle` calls a
|
|
433
|
+
class under `app/Rsc` whose `FormRequest` validates it. What the rules refuse
|
|
434
|
+
shows under each field. [Public forms](/guides/public-forms#laravel) has the
|
|
435
|
+
code.
|
|
436
|
+
|
|
421
437
|
## Route middleware
|
|
422
438
|
|
|
423
439
|
The renderer owns the route table, but Laravel still decides whether a route
|
package/guides/public-forms.md
CHANGED
|
@@ -74,15 +74,126 @@ handle: async ({ email }) => {
|
|
|
74
74
|
|
|
75
75
|
## A Laravel or Go backend
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
The form stays in TypeScript, because the schema is what draws it and what the
|
|
78
|
+
browser checks. `handle` hands the values to your backend with `rpc()`, and the
|
|
79
|
+
backend validates and saves them. Only the `handle` line changes:
|
|
78
80
|
|
|
79
|
-
```ts
|
|
80
|
-
|
|
81
|
+
```ts title="resources/js/forms/contact.ts"
|
|
82
|
+
import * as z from 'zod'
|
|
83
|
+
import { defineForm } from '@rsc-kit/press/forms'
|
|
84
|
+
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
85
|
+
|
|
86
|
+
export const contact = defineForm({
|
|
87
|
+
name: 'contact',
|
|
88
|
+
form: z.object({
|
|
89
|
+
name: z.string().min(2),
|
|
90
|
+
email: z.email(),
|
|
91
|
+
message: z.string().min(10).max(2000),
|
|
92
|
+
}),
|
|
93
|
+
fields: { message: { type: 'textarea' } },
|
|
94
|
+
theme: shadcn,
|
|
95
|
+
submit: 'Send message',
|
|
96
|
+
done: 'Thanks - we will be in touch.',
|
|
97
|
+
handle: (values) => rpc('Contact.send', values),
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The values arrive as one object, keyed by field. What the backend refuses comes
|
|
102
|
+
back under the field of the same name, with what was typed kept, and there is
|
|
103
|
+
nothing to catch. The schema's checks run first, so a submission it refuses
|
|
104
|
+
never reaches the backend.
|
|
105
|
+
|
|
106
|
+
### Laravel
|
|
107
|
+
|
|
108
|
+
A `FormRequest` type-hinted on the method is built from the values and validated
|
|
109
|
+
before the method runs, as on a route. Its failure is the 422 the form reads.
|
|
110
|
+
|
|
111
|
+
```php title="app/Http/Requests/SendContact.php"
|
|
112
|
+
namespace App\Http\Requests;
|
|
113
|
+
|
|
114
|
+
use Illuminate\Foundation\Http\FormRequest;
|
|
115
|
+
|
|
116
|
+
class SendContact extends FormRequest
|
|
117
|
+
{
|
|
118
|
+
public function authorize(): bool
|
|
119
|
+
{
|
|
120
|
+
return true; // anyone may send it; make:request writes false
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public function rules(): array
|
|
124
|
+
{
|
|
125
|
+
return [
|
|
126
|
+
'name' => ['required', 'string', 'min:2'],
|
|
127
|
+
'email' => ['required', 'email', 'unique:subscribers,email'],
|
|
128
|
+
'message' => ['required', 'string', 'min:10', 'max:2000'],
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```php title="app/Rsc/Contact.php"
|
|
135
|
+
namespace App\Rsc;
|
|
136
|
+
|
|
137
|
+
use App\Http\Requests\SendContact;
|
|
138
|
+
use App\Models\Message;
|
|
139
|
+
|
|
140
|
+
class Contact
|
|
141
|
+
{
|
|
142
|
+
public function send(SendContact $request): void
|
|
143
|
+
{
|
|
144
|
+
Message::create($request->validated());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The method takes the request alone. Without a `FormRequest`, take `array $values`
|
|
150
|
+
and call `Validator::make($values, [...])->validate()`, or throw
|
|
151
|
+
`ValidationException::withMessages(['email' => 'That address is blocked.'])`.
|
|
152
|
+
Either lands the same way.
|
|
153
|
+
|
|
154
|
+
Keep the class under `app/Rsc`, and `rpc('Contact.send', ...)` is typed from it
|
|
155
|
+
at the next build.
|
|
156
|
+
|
|
157
|
+
### Go
|
|
158
|
+
|
|
159
|
+
Register a function that takes the values as a struct. Its `json` tags are the
|
|
160
|
+
form's field names, and `rsckit.InvalidField` or `rsckit.Invalid` is the 422.
|
|
161
|
+
|
|
162
|
+
```go
|
|
163
|
+
type ContactInput struct {
|
|
164
|
+
Name string `json:"name"`
|
|
165
|
+
Email string `json:"email"`
|
|
166
|
+
Message string `json:"message"`
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
reg.Handle("Contact.send", func(ctx context.Context, in ContactInput) error {
|
|
170
|
+
if blocked(in.Email) {
|
|
171
|
+
return rsckit.InvalidField("email", "That address is blocked.")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return messages.Insert(ctx, in)
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
For several fields at once:
|
|
179
|
+
|
|
180
|
+
```go
|
|
181
|
+
return rsckit.Invalid(map[string][]string{
|
|
182
|
+
"email": {"That address is blocked."},
|
|
183
|
+
"message": {"That looks like spam."},
|
|
184
|
+
})
|
|
81
185
|
```
|
|
82
186
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
187
|
+
`reg.WriteManifest("rsc-host.json")` types `rpc('Contact.send', ...)` for the
|
|
188
|
+
app, as with any function.
|
|
189
|
+
|
|
190
|
+
### On a kept page
|
|
191
|
+
|
|
192
|
+
A public form can sit in an [ISR](/guides/isr) page. The page is kept for
|
|
193
|
+
everyone, and the post is the visitor's own: it needs no token, because the
|
|
194
|
+
engine and Laravel 13 accept a same-origin post by its `Sec-Fetch-Site` header.
|
|
195
|
+
The `rpc()` in `handle` runs in that post, so it carries the visitor's cookie,
|
|
196
|
+
unlike the calls the kept page made while rendering.
|
|
86
197
|
|
|
87
198
|
## Once it is sent
|
|
88
199
|
|
|
@@ -97,7 +208,13 @@ hidden from screen readers and not autofilled. A bot filling in every input
|
|
|
97
208
|
fills that one too, and the submission is answered as though it worked and
|
|
98
209
|
dropped - `handle` never sees it, and the bot learns nothing. It is a filter
|
|
99
210
|
for the crudest spam, not a CAPTCHA; a form worth attacking wants rate
|
|
100
|
-
limiting
|
|
211
|
+
limiting as well.
|
|
212
|
+
|
|
213
|
+
Put that in front of the app, at the CDN or the proxy, where the visitor's
|
|
214
|
+
address is known. A backend sees the renderer's address on an `rpc()`, not the
|
|
215
|
+
visitor's, so `throttle:5,1` on a Laravel method puts every logged-out visitor
|
|
216
|
+
in one bucket. To limit in the backend, key on something the submission carries,
|
|
217
|
+
such as the email address.
|
|
101
218
|
|
|
102
219
|
The trap is named `homepage`, so a form cannot have a field of that name.
|
|
103
220
|
|
|
@@ -293,10 +293,11 @@ answered if you can - post
|
|
|
293
293
|
{ "tags": ["team:1:repos"] }
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
to that url, `Content-Type: application/json`, at most 100 tags a call
|
|
297
|
-
needs no token.
|
|
298
|
-
|
|
299
|
-
copy at `
|
|
296
|
+
to that url, `Content-Type: application/json`, at most 100 tags a call, each
|
|
297
|
+
at most 1024 bytes. It needs no token. Only a `202` means it was accepted. A
|
|
298
|
+
429 may be tried once more after its `Retry-After`; anything else is logged
|
|
299
|
+
and never fails the change, since the CDN drops its copy at its `max-age` in `CDN-Cache-Control` anyway.
|
|
300
|
+
Without the variable, do nothing.
|
|
300
301
|
|
|
301
302
|
## Server actions
|
|
302
303
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/mcp",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.47",
|
|
4
4
|
"description": "An MCP server over what an rsc-kit build decided: the routes, why each one is static or not, and what it costs the browser.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
37
|
-
"create-rsc-kit": "^0.30.
|
|
37
|
+
"create-rsc-kit": "^0.30.47",
|
|
38
38
|
"zod": "^3.25"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|