@rsc-kit/mcp 0.30.38 → 0.30.42
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 +343 -1
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +109 -0
- package/guides/admin.md +401 -0
- package/guides/api-routes.md +21 -0
- package/guides/caching.md +85 -3
- package/guides/coming-from-inertia.md +1 -1
- package/guides/coming-from-next.md +1 -0
- package/guides/edge-caching.md +57 -0
- package/guides/index.json +21 -1
- package/guides/laravel.md +8 -0
- package/guides/pages.md +177 -0
- package/guides/public-forms.md +113 -0
- package/guides/redirects.md +21 -1
- package/guides/server-actions.md +47 -0
- package/guides/your-own-backend.md +17 -0
- package/package.json +2 -2
package/guides/edge-caching.md
CHANGED
|
@@ -57,6 +57,63 @@ static.
|
|
|
57
57
|
Deployments are handled for you: cached responses carry a build version, so a
|
|
58
58
|
new deploy does not leave old shells being served against a new payload.
|
|
59
59
|
|
|
60
|
+
## Keeping a page that is rendered per request
|
|
61
|
+
|
|
62
|
+
A page whose data changes after the build is rendered for each request, and
|
|
63
|
+
sent `private`. When the same answer may go to everyone for a while, say how
|
|
64
|
+
long:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
// app/posts/[slug]/page.tsx
|
|
68
|
+
export const revalidate = 60 // seconds a shared cache may keep it
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The page is then rendered whole before it is sent, and judged. When the render
|
|
72
|
+
read nothing that belongs to one visitor, it goes out as:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
Cache-Control: public, max-age=0, s-maxage=60, stale-while-revalidate=86400
|
|
76
|
+
ETag: "…"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
A CDN keeps it for 60 seconds and refreshes it in the background after that;
|
|
80
|
+
a browser never keeps it. A cache revalidating a copy that has not changed is
|
|
81
|
+
answered `304`. A 404 - including the not-found.tsx a navigation shows - is
|
|
82
|
+
kept for at most a minute, so a scanner walking random urls cannot hold your
|
|
83
|
+
pages out. A layout can export it too: the smallest value on the way down to
|
|
84
|
+
the page wins, and `0` anywhere means the page is rendered per request as
|
|
85
|
+
before. It must be a number literal the build can read.
|
|
86
|
+
|
|
87
|
+
**A revalidate page calls its backend as nobody.** Its host calls carry no
|
|
88
|
+
cookie and no `Authorization`, and a cookie the backend sets is dropped -
|
|
89
|
+
`auth()->user()` is null there, as it is for every visitor a shared copy is
|
|
90
|
+
served to. A page that needs to know who is asking is not one to keep.
|
|
91
|
+
|
|
92
|
+
A form needs no token for this. The engine's actions, and Laravel 13's
|
|
93
|
+
forgery check, accept a same-origin post by its `Sec-Fetch-Site` header, so a
|
|
94
|
+
form in a kept page posts as the visitor. A backend that still checks a token
|
|
95
|
+
tied to the session should be asked for it by a component that awaits
|
|
96
|
+
`connection()`, inside `<Suspense>`. In a static page that part is a hole
|
|
97
|
+
filled per request with the visitor's own session; in a revalidate page it is
|
|
98
|
+
a read of the visitor, so the page is sent private.
|
|
99
|
+
|
|
100
|
+
Any of these sends the page as before, `private, no-store`, with a
|
|
101
|
+
`Cache-Status` header naming the reason and one line in the log per page and
|
|
102
|
+
reason:
|
|
103
|
+
|
|
104
|
+
| `Cache-Status: rsc-kit; fwd=bypass; detail=` | Why |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| `cookies`, `headers`, `request`, `connection` | the render read the visitor - in the page, a layout, a Suspense'd child, metadata or `middleware.ts`; the log names the component |
|
|
107
|
+
| `host-middleware` | the route has host middleware, which runs against the visitor's session |
|
|
108
|
+
| `set-cookie` | the answer set a cookie |
|
|
109
|
+
| `nonce` | the answer carries a CSP nonce, which a shared copy would give everyone |
|
|
110
|
+
| `status` | only a 200 or a 404 is kept, never a redirect or a 5xx |
|
|
111
|
+
| `failed-render` | React reported a failure inside the payload |
|
|
112
|
+
| `payload-url` | a navigation's payload was asked for without its `?_rsc=` key, or a document with one; the router always adds it |
|
|
113
|
+
|
|
114
|
+
The page is not prerendered: `revalidate` says its data changes, so a frozen
|
|
115
|
+
copy would be wrong from the first change.
|
|
116
|
+
|
|
60
117
|
## Finishing a shell at the edge
|
|
61
118
|
|
|
62
119
|
A shell has holes in it, and something has to fill them. That happens at your
|
package/guides/index.json
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"slug": "admin",
|
|
4
|
+
"title": "Admin panels",
|
|
5
|
+
"description": "An admin panel over any data - a database, an ORM, a REST API, a Laravel or Go backend - with server or client tables, tenants and plugins."
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"slug": "admin-plugins",
|
|
9
|
+
"title": "Admin plugins",
|
|
10
|
+
"description": "Writing an @rsc-kit/press plugin, publishing it as a package, and selling it."
|
|
11
|
+
},
|
|
2
12
|
{
|
|
3
13
|
"slug": "api-routes",
|
|
4
14
|
"title": "API routes",
|
|
@@ -27,7 +37,7 @@
|
|
|
27
37
|
{
|
|
28
38
|
"slug": "caching",
|
|
29
39
|
"title": "Asking once per request",
|
|
30
|
-
"description": "cache() — one lookup, however many places need it."
|
|
40
|
+
"description": "cache() — one lookup, however many places need it, and with a key and a lifetime, however many requests."
|
|
31
41
|
},
|
|
32
42
|
{
|
|
33
43
|
"slug": "coming-from-inertia",
|
|
@@ -164,11 +174,21 @@
|
|
|
164
174
|
"title": "OpenAPI",
|
|
165
175
|
"description": "A document derived from your route.ts files, and Scalar's page over it."
|
|
166
176
|
},
|
|
177
|
+
{
|
|
178
|
+
"slug": "pages",
|
|
179
|
+
"title": "Pages from blocks",
|
|
180
|
+
"description": "Landing pages, an about page, a pricing page - built in the admin panel from the app's own blocks, live on the next visit."
|
|
181
|
+
},
|
|
167
182
|
{
|
|
168
183
|
"slug": "ppr",
|
|
169
184
|
"title": "Partial prerendering",
|
|
170
185
|
"description": "Storing what every visitor sees the same, and rendering the rest per request."
|
|
171
186
|
},
|
|
187
|
+
{
|
|
188
|
+
"slug": "public-forms",
|
|
189
|
+
"title": "Public forms",
|
|
190
|
+
"description": "A contact form, a sign-up, a survey - drawn from a Standard Schema, checked in the browser and on the server, sent to any backend."
|
|
191
|
+
},
|
|
172
192
|
{
|
|
173
193
|
"slug": "pwa",
|
|
174
194
|
"title": "Progressive web apps",
|
package/guides/laravel.md
CHANGED
|
@@ -350,6 +350,14 @@ region with it rather than the browser being told to ask again — the same
|
|
|
350
350
|
thing `revalidate()` does from a JavaScript action, described in
|
|
351
351
|
[Sections](/guides/sections).
|
|
352
352
|
|
|
353
|
+
`Rsc::flash('Invoice sent.')` leaves a message for the page the visitor lands
|
|
354
|
+
on next - after a redirect, or in place - and `useFlash()` from
|
|
355
|
+
`@rsc-kit/core/useFlash` shows it once, the same message `flash()` leaves from
|
|
356
|
+
a JavaScript action ([A message for the next page](/guides/server-actions#a-message-for-the-next-page)).
|
|
357
|
+
A second argument is the kind: `'error'`, `'info'` or `'warning'`. It works
|
|
358
|
+
from a controller too, on its own response. The cookie is read by the browser,
|
|
359
|
+
so the package leaves it unencrypted: nothing secret goes in a flash.
|
|
360
|
+
|
|
353
361
|
## Saying data changed
|
|
354
362
|
|
|
355
363
|
`Rsc::revalidate()` is for the action that made the change. A webhook, a
|
package/guides/pages.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Pages from blocks
|
|
2
|
+
|
|
3
|
+
> Landing pages, an about page, a pricing page - built in the admin panel from the app's own blocks, live on the next visit.
|
|
4
|
+
|
|
5
|
+
`@rsc-kit/press/pages` lets an editor build pages in the [admin panel](/guides/admin/)
|
|
6
|
+
from blocks the app defines - a hero, a feature grid, a call to action, a
|
|
7
|
+
[public form](/guides/public-forms/) - and serves them from one catch-all
|
|
8
|
+
route. The blocks are the app's code and look like the rest of the site; what
|
|
9
|
+
is on a page, and in what order, is the editor's.
|
|
10
|
+
|
|
11
|
+
## Blocks
|
|
12
|
+
|
|
13
|
+
A block is a schema for what an editor fills in and a component that draws
|
|
14
|
+
it:
|
|
15
|
+
|
|
16
|
+
```tsx title="src/site/blocks.tsx"
|
|
17
|
+
import * as z from 'zod'
|
|
18
|
+
import { defineBlock } from '@rsc-kit/press'
|
|
19
|
+
|
|
20
|
+
export const hero = defineBlock({
|
|
21
|
+
name: 'hero',
|
|
22
|
+
form: z.object({
|
|
23
|
+
heading: z.string().min(3).max(80),
|
|
24
|
+
lead: z.string().max(300).optional(),
|
|
25
|
+
}),
|
|
26
|
+
fields: { lead: { type: 'textarea' } },
|
|
27
|
+
render: ({ data }) => (
|
|
28
|
+
<section>
|
|
29
|
+
<h1>{data.heading}</h1>
|
|
30
|
+
{data.lead && <p>{data.lead}</p>}
|
|
31
|
+
</section>
|
|
32
|
+
),
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`form` is any Standard Schema, and `fields` overrides what it cannot say, as a
|
|
37
|
+
[resource's form](/guides/admin/#the-form-is-any-standard-schema) does. `render`
|
|
38
|
+
is a server component and may be async: a block that lists the latest posts
|
|
39
|
+
reads them itself. A block can place a public form - `render: () => <contact.Form />` -
|
|
40
|
+
so the editor decides where it goes and the code decides what it does.
|
|
41
|
+
|
|
42
|
+
## The pages
|
|
43
|
+
|
|
44
|
+
```ts title="src/site/pages.ts"
|
|
45
|
+
import { FileText } from 'lucide-react'
|
|
46
|
+
import type { DataSource } from '@rsc-kit/press'
|
|
47
|
+
import { definePages, type PageRow, type PageValues } from '@rsc-kit/press/pages'
|
|
48
|
+
import { features, hero, text } from './blocks'
|
|
49
|
+
|
|
50
|
+
export const site = definePages({
|
|
51
|
+
blocks: [hero, features, text],
|
|
52
|
+
source: pagesSource,
|
|
53
|
+
icon: FileText,
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Three files serve them:
|
|
58
|
+
|
|
59
|
+
```tsx title="src/app/[...path]/page.tsx"
|
|
60
|
+
import { site } from '@/site/pages'
|
|
61
|
+
|
|
62
|
+
export const generateMetadata = site.generateMetadata
|
|
63
|
+
|
|
64
|
+
export default function SitePage({ params }: { params: Promise<{ path: string }> }) {
|
|
65
|
+
return (
|
|
66
|
+
<main>
|
|
67
|
+
<site.Page params={params} />
|
|
68
|
+
</main>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ts title="src/app/[...path]/middleware.ts"
|
|
74
|
+
import { site } from '@/site/pages'
|
|
75
|
+
|
|
76
|
+
export default site.middleware
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```ts title="src/admin/panel.ts"
|
|
80
|
+
resources: [site.resource, products, customers],
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The catch-all is the weakest route there is, so every page and route the app
|
|
84
|
+
has wins over it; it answers only the addresses nothing else does. A page's
|
|
85
|
+
slug is its address - `about`, `pricing/teams` - and the one named `home` is
|
|
86
|
+
served at `/` when the app has no `app/page.tsx` of its own (`home` changes
|
|
87
|
+
which).
|
|
88
|
+
|
|
89
|
+
The middleware asks whether there is a published page at the address before
|
|
90
|
+
anything is sent, so a draft or a typo is a real **404**. Without it the
|
|
91
|
+
route's shell has already gone out with a 200 by the time the page finds
|
|
92
|
+
nothing - see [Errors](/guides/errors/#when-the-page-has-to-decide).
|
|
93
|
+
|
|
94
|
+
## Live on the next visit
|
|
95
|
+
|
|
96
|
+
A save in the panel is live on the next visit, and nothing is rebuilt. A page
|
|
97
|
+
is looked up once and then kept, so most visits do not ask the source at all:
|
|
98
|
+
for 60 seconds, or until any page is saved. The page is kept with
|
|
99
|
+
[`cache()`](/guides/caching/#across-requests), in memory unless the app installs
|
|
100
|
+
a shared store. `revalidate` sets the lifetime, and `false` asks on every
|
|
101
|
+
request:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
export const site = definePages({ blocks, source, revalidate: 300 })
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A change made around the panel, straight in the database, shows when the kept
|
|
108
|
+
copy expires, or at once after `changed('press:pages')`. The build stores the route's
|
|
109
|
+
frame as one shell for every address, and the page streams into it. A page
|
|
110
|
+
also has a title and a description, which become its `<title>` and meta
|
|
111
|
+
description; a draft is a page with Published off, reachable only in the
|
|
112
|
+
panel.
|
|
113
|
+
|
|
114
|
+
## Where pages are kept
|
|
115
|
+
|
|
116
|
+
`source` is a [data source](/guides/admin/#any-data-source) of rows shaped
|
|
117
|
+
`{ id, title, slug, description?, published, blocks }`, where `blocks` is a
|
|
118
|
+
list of `{ type, data }` - a JSON column in a database. Its `list()` is also
|
|
119
|
+
how a page is found by its address: it is asked for `filters: { slug }`, and
|
|
120
|
+
must answer with the page at that slug. `memorySource` does; a Laravel or Go
|
|
121
|
+
backend behind `rpc()` filters on the column.
|
|
122
|
+
|
|
123
|
+
`memorySource` keeps the pages in the process's memory: an edit is gone
|
|
124
|
+
when the server restarts, and two servers each have their own copy. It is
|
|
125
|
+
for a demo, or for pages that only ever come from rows in code. Pages an
|
|
126
|
+
editor saves belong where the app keeps its other data. On a Laravel or Go
|
|
127
|
+
backend that is a `pages` table with a JSON `blocks` column, behind `rpc()`:
|
|
128
|
+
|
|
129
|
+
```ts title="src/site/pages.ts"
|
|
130
|
+
const pagesSource: DataSource<PageRow, PageValues> = {
|
|
131
|
+
list: (query) => rpc('Pages.list', query),
|
|
132
|
+
find: (id) => rpc('Pages.find', Number(id)),
|
|
133
|
+
create: (values) => rpc('Pages.create', values),
|
|
134
|
+
update: (id, values) => rpc('Pages.update', Number(id), values),
|
|
135
|
+
delete: (id) => rpc('Pages.delete', Number(id)),
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```php title="app/Rsc/Pages.php"
|
|
140
|
+
public function list(array $query): array
|
|
141
|
+
{
|
|
142
|
+
$pages = Page::query()
|
|
143
|
+
->when($query['filters']['slug'] ?? null, fn ($q, $slug) => $q->where('slug', $slug))
|
|
144
|
+
->paginate($query['perPage'] ?? 15, page: $query['page'] ?? 1);
|
|
145
|
+
|
|
146
|
+
return ['rows' => $pages->items(), 'total' => $pages->total()];
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Cast `blocks` to an array on the model, and `published` to a boolean. An app
|
|
151
|
+
with no backend writes the same five functions over its own database -
|
|
152
|
+
Drizzle, Prisma, `bun:sqlite`.
|
|
153
|
+
|
|
154
|
+
Each block's data is checked by its own schema on every save, and a refusal
|
|
155
|
+
shows under that block's field. An address belongs to one page: saving a
|
|
156
|
+
second page at `/about` is refused under its slug.
|
|
157
|
+
|
|
158
|
+
## Blocks in any resource
|
|
159
|
+
|
|
160
|
+
The block editor is a field type, so any resource can have one - a product's
|
|
161
|
+
long description, a post's body:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
form: z.object({ name: z.string(), body: z.array(z.any()) }),
|
|
165
|
+
fields: { body: { blocks: [text, gallery, quote] } },
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Draw what was saved with `Blocks`:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { Blocks } from '@rsc-kit/press'
|
|
172
|
+
|
|
173
|
+
<Blocks blocks={[text, gallery, quote]} value={post.body} />
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
A block whose kind the code no longer defines is left out of the page rather
|
|
177
|
+
than failing it, and the editor says that saving will remove it.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Public forms
|
|
2
|
+
|
|
3
|
+
> A contact form, a sign-up, a survey - drawn from a Standard Schema, checked in the browser and on the server, sent to any backend.
|
|
4
|
+
|
|
5
|
+
`@rsc-kit/press/forms` turns a Standard Schema into a form anyone may fill in.
|
|
6
|
+
It is the panel's form without the panel: the same fields read from the same
|
|
7
|
+
schema, the same browser checks, the same refusals under the same fields - and
|
|
8
|
+
a [theme](/guides/admin/#themes) to draw it. The `shadcn` theme draws both.
|
|
9
|
+
|
|
10
|
+
```ts title="src/forms/contact.ts"
|
|
11
|
+
import * as z from 'zod'
|
|
12
|
+
import { defineForm } from '@rsc-kit/press/forms'
|
|
13
|
+
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
14
|
+
|
|
15
|
+
export const contact = defineForm({
|
|
16
|
+
name: 'contact',
|
|
17
|
+
form: z.object({
|
|
18
|
+
name: z.string().min(2),
|
|
19
|
+
email: z.email(),
|
|
20
|
+
message: z.string().min(10).max(2000),
|
|
21
|
+
}),
|
|
22
|
+
fields: { message: { type: 'textarea' } },
|
|
23
|
+
theme: shadcn,
|
|
24
|
+
submit: 'Send message',
|
|
25
|
+
done: 'Thanks - we will be in touch.',
|
|
26
|
+
handle: async (values) => {
|
|
27
|
+
await db.insert(messages).values(values)
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Place it in any page:
|
|
33
|
+
|
|
34
|
+
```tsx title="src/app/contact/page.tsx"
|
|
35
|
+
import { contact } from '@/forms/contact'
|
|
36
|
+
|
|
37
|
+
export default function ContactPage() {
|
|
38
|
+
return (
|
|
39
|
+
<main>
|
|
40
|
+
<h1>Contact us</h1>
|
|
41
|
+
<contact.Form />
|
|
42
|
+
</main>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The form reads nothing from the request, so the page around it is stored by
|
|
48
|
+
the build like any other static page. Only sending it runs on the server.
|
|
49
|
+
|
|
50
|
+
Install is the panel's: `bun add @rsc-kit/press`, and the
|
|
51
|
+
`@import "@rsc-kit/press/shadcn.css"` line in the app's stylesheet, as in
|
|
52
|
+
[Admin panels](/guides/admin/#install).
|
|
53
|
+
|
|
54
|
+
## What is checked, and where
|
|
55
|
+
|
|
56
|
+
The schema's constraints become the browser's - `required`, `minlength`,
|
|
57
|
+
`maxlength`, `type="email"`, a `pattern` - so a visitor hears about a missing
|
|
58
|
+
field before anything is sent, under the field, in their own language. The
|
|
59
|
+
schema then checks every submission on the server, which is the check that
|
|
60
|
+
counts: anyone can post without a browser. What it refuses comes back under
|
|
61
|
+
each field, with what was typed kept.
|
|
62
|
+
|
|
63
|
+
`handle` gets the values only once they have passed. A refusal it decides -
|
|
64
|
+
an address already signed up - goes under its field the same way:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { fieldErrors } from '@rsc-kit/core/action'
|
|
68
|
+
|
|
69
|
+
handle: async ({ email }) => {
|
|
70
|
+
if (await subscribed(email)) fieldErrors({ email: 'That address is already on the list.' })
|
|
71
|
+
await subscribe(email)
|
|
72
|
+
},
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## A Laravel or Go backend
|
|
76
|
+
|
|
77
|
+
`handle` is a server function, so it can hand the values on with `rpc()`:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
handle: (values) => rpc('Contact.send', values),
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The backend validates again. A 422 from it - a Laravel `FormRequest`, a Go
|
|
84
|
+
handler's field errors - shows under the same fields as the schema's, with
|
|
85
|
+
nothing to catch.
|
|
86
|
+
|
|
87
|
+
## Once it is sent
|
|
88
|
+
|
|
89
|
+
`done` is what the visitor reads in place of the form; without one it says
|
|
90
|
+
the message was sent. `redirect` sends them somewhere instead - a thank-you
|
|
91
|
+
page, the account they just made - and a form has one or the other, not both.
|
|
92
|
+
|
|
93
|
+
## Bots
|
|
94
|
+
|
|
95
|
+
Every form carries a field people never see: off screen, out of the tab order,
|
|
96
|
+
hidden from screen readers and not autofilled. A bot filling in every input
|
|
97
|
+
fills that one too, and the submission is answered as though it worked and
|
|
98
|
+
dropped - `handle` never sees it, and the bot learns nothing. It is a filter
|
|
99
|
+
for the crudest spam, not a CAPTCHA; a form worth attacking wants rate
|
|
100
|
+
limiting in front of it as well.
|
|
101
|
+
|
|
102
|
+
The trap is named `homepage`, so a form cannot have a field of that name.
|
|
103
|
+
|
|
104
|
+
## Drawing it yourself
|
|
105
|
+
|
|
106
|
+
The theme's part is one component, `PublicForm`, typed `FormsTheme` from
|
|
107
|
+
`@rsc-kit/press/forms`. It is given the bound `action`, the `fields`, the
|
|
108
|
+
`submit` words, `done`, and the `honeypot` field's name to render hidden.
|
|
109
|
+
Replace it as you would a panel page:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
theme: { ...shadcn, PublicForm: MyForm },
|
|
113
|
+
```
|
package/guides/redirects.md
CHANGED
|
@@ -172,7 +172,27 @@ An action is not a render, so there is no shell to be on either side of. Throw
|
|
|
172
172
|
from the action — a plain `"use server"` function or one built from
|
|
173
173
|
`createActionClient()` — and the client follows it as a navigation: the
|
|
174
174
|
layouts stay mounted and the history entry the form was on is replaced, so
|
|
175
|
-
Back does not return to the submitted form.
|
|
175
|
+
Back does not return to the submitted form.
|
|
176
|
+
|
|
177
|
+
The layouts are not rendered again, as on any navigation: most redirects —
|
|
178
|
+
save, then the list — change nothing a layout reads. One that does says so,
|
|
179
|
+
the way any action does. `revalidate('all')` before the `redirect()` asks for
|
|
180
|
+
the destination whole, layouts included; a named section counts too, since it
|
|
181
|
+
can live in a layout. A team switch whose name is in the sidebar:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
'use server'
|
|
185
|
+
|
|
186
|
+
export async function switchTeam(id: string) {
|
|
187
|
+
await setCurrentTeam(id)
|
|
188
|
+
revalidate('all')
|
|
189
|
+
redirect('/dashboard')
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Without it the page is the new team's and the sidebar still names the old one
|
|
194
|
+
until a reload. The same holds for a backend action: `Rsc::revalidate('all')`
|
|
195
|
+
before the redirect. A `<Form>` shows nothing for it;
|
|
176
196
|
signing in and arriving is the success.
|
|
177
197
|
|
|
178
198
|
To the caller, the action **resolves** — with `{ redirected: '/where' }` —
|
package/guides/server-actions.md
CHANGED
|
@@ -537,6 +537,53 @@ one can be wired in without this package having an opinion about which. See
|
|
|
537
537
|
[Writing to the response](/guides/authorization#writing-to-the-response) for
|
|
538
538
|
where else it works, and where it does not.
|
|
539
539
|
|
|
540
|
+
## A message for the next page
|
|
541
|
+
|
|
542
|
+
An action's return value goes back to the form that submitted it. When the
|
|
543
|
+
action redirects, that form is gone, so "Saved." on the list it lands on is a
|
|
544
|
+
one-time message instead:
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
'use server';
|
|
548
|
+
|
|
549
|
+
import { flash } from '@rsc-kit/core/flash';
|
|
550
|
+
import { redirect } from '@rsc-kit/core/redirect';
|
|
551
|
+
|
|
552
|
+
export async function saveProduct(formData: FormData) {
|
|
553
|
+
await products.save(formData);
|
|
554
|
+
await flash('Product saved.');
|
|
555
|
+
|
|
556
|
+
redirect('/products');
|
|
557
|
+
}
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
```tsx title="src/app/toasts.tsx"
|
|
561
|
+
'use client';
|
|
562
|
+
|
|
563
|
+
import { useFlash } from '@rsc-kit/core/useFlash';
|
|
564
|
+
import { toast } from 'sonner';
|
|
565
|
+
|
|
566
|
+
export function Toasts() {
|
|
567
|
+
useFlash(({ message, kind }) => (kind === 'error' ? toast.error : toast.success)(message));
|
|
568
|
+
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Render `<Toasts />` once, in the root layout. `kind` is `'success'` (the
|
|
574
|
+
default), `'error'`, `'info'` or `'warning'`; two calls are two messages.
|
|
575
|
+
|
|
576
|
+
`flash()` sets a cookie, so call it where a cookie can still be set: an action,
|
|
577
|
+
middleware or a `route.ts`, not a page. The browser takes it, not the server:
|
|
578
|
+
`useFlash` looks when it mounts, after every navigation and, where the browser
|
|
579
|
+
supports CookieStore, whenever a response sets it, so an action that stays on
|
|
580
|
+
the page shows its message too. Each message is handed over once, then cleared.
|
|
581
|
+
A page never reads it, so a stored or edge-cached page stays cacheable. Unread,
|
|
582
|
+
it lapses after a minute.
|
|
583
|
+
|
|
584
|
+
The cookie is readable by script, so it holds a message and never data. Render
|
|
585
|
+
the message as text.
|
|
586
|
+
|
|
540
587
|
## Work the visitor should not wait for
|
|
541
588
|
|
|
542
589
|
An audit row, a welcome email, a cache warm: the action's answer should not
|
|
@@ -314,6 +314,22 @@ it cannot go stale: a stale one names a method since renamed, and nothing
|
|
|
314
314
|
fails until the browser calls it. Laravel's `rsc:host-manifest` is this
|
|
315
315
|
step; a Go registry's `WriteManifest` writes the same file.
|
|
316
316
|
|
|
317
|
+
### A message for the next page
|
|
318
|
+
|
|
319
|
+
`useFlash()` on the page shows what an action leaves for the next one. Your
|
|
320
|
+
side leaves one by setting a cookie on the reply, the way a login does: named
|
|
321
|
+
`rsc-flash`, its value a URI-encoded JSON list of `{ "message", "kind" }` -
|
|
322
|
+
`kind` one of `success`, `error`, `info`, `warning` - with `Path=/`, a short
|
|
323
|
+
`Max-Age` and `SameSite=Lax`.
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
Set-Cookie: rsc-flash=%5B%7B%22message%22%3A%22Saved.%22%2C%22kind%22%3A%22success%22%7D%5D; Path=/; Max-Age=60; SameSite=Lax
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
The browser reads it, so it is never `HttpOnly` and never encrypted - Laravel's
|
|
330
|
+
`Rsc::flash()` exempts it from `EncryptCookies`. A message the visitor's cookie
|
|
331
|
+
still carries goes first: append to the list, do not replace it.
|
|
332
|
+
|
|
317
333
|
## Urls you own
|
|
318
334
|
|
|
319
335
|
The renderer forwards any url the route tree does not own — `/login`, a
|
|
@@ -382,6 +398,7 @@ ordinary API, the way an app would write them:
|
|
|
382
398
|
| `Conformance.authorization` | return the forwarded `Authorization` header |
|
|
383
399
|
| `Conformance.cookie` | return the forwarded `Cookie` header |
|
|
384
400
|
| `Conformance.login` | set a cookie named `conformance_login` on the response, and return `"ok"` |
|
|
401
|
+
| `Conformance.flash` | leave the one-time message `"Saved."` (`"success"`) for the next page, after any the visitor's `rsc-flash` cookie still carries, and return `"ok"` |
|
|
385
402
|
| `Conformance.change` | say `conformance:changed` changed, as your webhook would, and return `"ok"` |
|
|
386
403
|
|
|
387
404
|
And three guards: `conformance-allow`, which passes, `conformance-deny`, which
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/mcp",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.42",
|
|
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.42",
|
|
38
38
|
"zod": "^3.25"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|