@rsc-kit/mcp 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recipes.js +46 -18
- package/dist/recipes.js.map +1 -1
- package/guides/admin.md +3 -3
- package/guides/backend-answered-pages.md +5 -3
- package/guides/blueprints.md +10 -8
- package/guides/coming-from-inertia.md +3 -3
- package/guides/forms.md +77 -8
- package/guides/go.md +12 -11
- package/guides/laravel.md +7 -6
- package/guides/testing.md +3 -3
- package/guides/where-it-runs.md +4 -0
- package/guides/your-own-backend.md +49 -6
- package/package.json +2 -2
package/dist/recipes.js
CHANGED
|
@@ -98,6 +98,22 @@ A field is checked when it is LEFT, not as it is typed (the form listens for
|
|
|
98
98
|
focusout, so uncontrolled fields are covered), and on submit. So error() has
|
|
99
99
|
nothing for a field nobody reached - there is no "touched" to check first.
|
|
100
100
|
|
|
101
|
+
CHECKED BY THE SERVER BEFORE SUBMIT: when a field is left having CHANGED, the
|
|
102
|
+
form also asks the action - marked as a check, so its guards and validation run
|
|
103
|
+
and its body does NOT. Automatic; nothing to opt into, and NO hook to add. It
|
|
104
|
+
asks only an action that can stop before its body: createActionClient() with
|
|
105
|
+
.input(schema), or a backend function listed in rsc-host.json "validates"
|
|
106
|
+
(Laravel: one whose first parameter is a FormRequest - Precognition's rules,
|
|
107
|
+
filtered to the field). A plain "use server" function is never called to check.
|
|
108
|
+
For a wizard step or any other moment, the render prop / useForm() has:
|
|
109
|
+
validate('email', 'name') ask now about these (none = every field); resolves
|
|
110
|
+
true when they pass. '*' is one segment: 'items.*.sku'.
|
|
111
|
+
validating true while a check is out
|
|
112
|
+
valid('email') a check passed and the field is unchanged since
|
|
113
|
+
A wizard keeps every step's fields in the form (hidden, not unmounted) and does
|
|
114
|
+
\`onClick={async () => (await validate('email')) && setStep(2)}\`. Checking as
|
|
115
|
+
it is typed is validate() in onChange - debounce it yourself.
|
|
116
|
+
|
|
101
117
|
Values are uncontrolled, so an initial one is React's own \`defaultValue\`. A
|
|
102
118
|
refused submit keeps what was typed, because the DOM kept it.
|
|
103
119
|
|
|
@@ -113,7 +129,7 @@ Names that describe a shape build it: \`address.city\` nests, and
|
|
|
113
129
|
\`items[0].name\` (or \`items[0][name]\`) makes an array of objects. That is
|
|
114
130
|
the shape the schema was written against, and error() takes the same path.
|
|
115
131
|
|
|
116
|
-
Binding a field - a rich editor, a
|
|
132
|
+
Binding a field - a rich editor, a select, a value read as it is typed:
|
|
117
133
|
|
|
118
134
|
\`\`\`tsx
|
|
119
135
|
<Form action={save} defaultValues={{ body: '' }}>
|
|
@@ -198,8 +214,10 @@ and point components.json at it.
|
|
|
198
214
|
|
|
199
215
|
**shadcn/ui works as-is.** Input, Textarea, Button and Label are styled native
|
|
200
216
|
elements, so \`name\` does what it always does. Select, Checkbox, Switch and
|
|
201
|
-
RadioGroup
|
|
202
|
-
|
|
217
|
+
RadioGroup render a hidden native control whenever given a \`name\`, on Base
|
|
218
|
+
UI and on Radix alike - omit it and they are invisible to the form. A Base UI
|
|
219
|
+
Select changes that control without an event; <Form> watches its controls, so
|
|
220
|
+
dirty and valid() still see the pick.
|
|
203
221
|
|
|
204
222
|
Do NOT use shadcn's own Form/FormField/FormControl with this. Those wrap
|
|
205
223
|
react-hook-form, a different system for the same job. One or the other.
|
|
@@ -1286,12 +1304,12 @@ data / validationErrors / serverError / redirected is set), so reading any
|
|
|
1286
1304
|
field of it is safe. Do NOT wrap actions in a hook to catch
|
|
1287
1305
|
ServerRedirectError; nothing throws.
|
|
1288
1306
|
|
|
1289
|
-
A generated backend stub (Go/Laravel actions in server-actions
|
|
1307
|
+
A generated backend stub (Go/Laravel actions in src/server-actions/<class>.ts) is
|
|
1290
1308
|
typed Promise<T | Redirected>, not an ActionResult: the redirect answer is
|
|
1291
1309
|
{ redirected } in place of T. Narrow with isRedirected from
|
|
1292
1310
|
'@rsc-kit/core/errors' before reading it, and also before any "success" that
|
|
1293
1311
|
follows an await of a void stub:
|
|
1294
|
-
const secret = await
|
|
1312
|
+
const secret = await databases.reveal(id)
|
|
1295
1313
|
if (isRedirected(secret)) return
|
|
1296
1314
|
Reading secret.Password first is a type error on purpose. A <Form> or
|
|
1297
1315
|
useAction already skips onSuccess on a redirect.
|
|
@@ -1452,8 +1470,8 @@ WHAT EACH PIECE BECOMES
|
|
|
1452
1470
|
router.visit / router.get -> visit(url) from @rsc-kit/core/router
|
|
1453
1471
|
router.reload({ only }) -> Rsc::revalidate('orders') in the action re-renders that section with the answer
|
|
1454
1472
|
router.post, useForm().post('/orders') -> a server action: php artisan make:rsc-action Orders --method=create --auth
|
|
1455
|
-
--revalidate=orders, then <Form action={
|
|
1456
|
-
(import
|
|
1473
|
+
--revalidate=orders, then <Form action={orders.create}> from @rsc-kit/core/form
|
|
1474
|
+
(import * as orders from './server-actions/orders', the module the build writes)
|
|
1457
1475
|
useForm errors/processing -> <Form>'s errors (a FormRequest's ValidationException lands on the fields)
|
|
1458
1476
|
and pending
|
|
1459
1477
|
->middleware(['auth','verified']) -> export const middleware = ['auth', 'verified'] in middleware.ts beside the page
|
|
@@ -1842,8 +1860,10 @@ A new app: bun create rsc-kit --backend=<url>, or rsc-kit init in an empty
|
|
|
1842
1860
|
directory, which starts one there.
|
|
1843
1861
|
|
|
1844
1862
|
The backend writes rsc-host.json at the project root (beside vite.config.ts):
|
|
1845
|
-
{ "actions": {
|
|
1846
|
-
actions become "use server"
|
|
1863
|
+
{ "actions": { module: { export: "Function.name" } }, "functions": ["Function.name", ...] }.
|
|
1864
|
+
actions become "use server" modules, one per class: { "orders": { "create":
|
|
1865
|
+
"Orders.create" } } is src/server-actions/orders.ts exporting create, and an
|
|
1866
|
+
__invoke (or a Go function with no method) is the module's default export;
|
|
1847
1867
|
functions type rpc()'s first argument, so a misspelt name fails tsc. rpc is a
|
|
1848
1868
|
GLOBAL the build declares in .rsc-kit/rsc-env.d.ts - never import it. Have
|
|
1849
1869
|
Vite write the manifest so it cannot go stale:
|
|
@@ -1992,8 +2012,11 @@ Server actions are classes in app/Rsc/Actions, found by reflection in PHP;
|
|
|
1992
2012
|
functions } - and vite.config.ts runs it as dev and every build start:
|
|
1993
2013
|
rscKit({ hostManifest: { command: ['php', 'artisan', 'rsc:host-manifest'] } }).
|
|
1994
2014
|
functions types rpc()'s first argument, so a misspelt name fails tsc. The
|
|
1995
|
-
build writes
|
|
1996
|
-
|
|
2015
|
+
build writes a "use server" module per class from actions - import * as
|
|
2016
|
+
orders from './server-actions/orders' in a client component, then
|
|
2017
|
+
orders.cancel(id); a nested class, Billing/Invoices, is server-actions/billing/invoices.
|
|
2018
|
+
An invokable class is the module's default: import sendInvite from
|
|
2019
|
+
'./server-actions/send-invite'. server-actions/ is the build's: never edit it. Rsc::revalidate('orders')
|
|
1997
2020
|
in the action returns the re-rendered region with the answer.
|
|
1998
2021
|
|
|
1999
2022
|
Per url: if the React tree has it, React renders it, otherwise Laravel does
|
|
@@ -2234,6 +2257,11 @@ server, build, prerender - under NODE, and an app importing 'bun' or
|
|
|
2234
2257
|
on a Bun app: dev "bun --bun vite", build "bun --bun vite build". createTestApp
|
|
2235
2258
|
runs the project's build script on the runtime the tests use.
|
|
2236
2259
|
|
|
2260
|
+
Nitro is pinned EXACTLY in package.json: "nitro": "3.0.261103-rc" - never ^3.0.0,
|
|
2261
|
+
which npm resolves to an older plain 3.0.0 that 404s every route. That version is
|
|
2262
|
+
also the OLDEST rsc-kit runs on: an older one (3.0.0 included) stops the build
|
|
2263
|
+
with "nitro X is older than 3.0.261103-rc"; fix the pin and install again.
|
|
2264
|
+
|
|
2237
2265
|
Native dependencies (sharp, bcrypt, better-sqlite3, @prisma/client, puppeteer,
|
|
2238
2266
|
...) are external to the server bundles by default; Nitro traces them into
|
|
2239
2267
|
.output/server/node_modules with their binaries. Add one:
|
|
@@ -2999,7 +3027,7 @@ THE BACKEND'S ACTIONS AS THE FORM: when a FormRequest or a Go struct already
|
|
|
2999
3027
|
says what a record takes, write NO schema. Give the generated actions instead
|
|
3000
3028
|
of form, and the source only list/find/delete:
|
|
3001
3029
|
source: { list, find, delete },
|
|
3002
|
-
actions: { create:
|
|
3030
|
+
actions: { create: products.store, update: products.update }, // import * as products from '../server-actions/products'
|
|
3003
3031
|
fields: { category_id: { relation: 'categories' } }, // the backend's names, typechecked
|
|
3004
3032
|
form and actions are one or the other, never both. The create form is drawn
|
|
3005
3033
|
from create's input, the edit form from update's. create(values); update(values,
|
|
@@ -3154,24 +3182,24 @@ create and update) saves the panel's records too, so source is only
|
|
|
3154
3182
|
{ list, find, delete }; one that does not needs a whole source. Say fields and
|
|
3155
3183
|
actions on the blueprint, never again on the resource (that throws).
|
|
3156
3184
|
|
|
3157
|
-
A BACKEND, WITH NO SCHEMA: defineBlueprint({ name, actions: { create:
|
|
3158
|
-
with
|
|
3185
|
+
A BACKEND, WITH NO SCHEMA: defineBlueprint({ name, actions: { create: send }, theme }),
|
|
3186
|
+
with import { send } from '../server-actions/contact' - the
|
|
3159
3187
|
action itself, never its name as a string (a string throws). No form, no
|
|
3160
3188
|
handle, no zod. actions is { create, update }, either or both: create's input
|
|
3161
3189
|
draws the create form, update's the edit form, and update is called
|
|
3162
3190
|
(values, key) - update(UpdateProfile $request, string $user) in Laravel,
|
|
3163
3191
|
reading the key with $this->route('user'); func(ctx, in ProfileInput,
|
|
3164
|
-
id string) in Go. bunx rsc-kit make:form
|
|
3192
|
+
id string) in Go. bunx rsc-kit make:form Contact.send writes forms/contact.ts.
|
|
3165
3193
|
The action is a Laravel class in app/Rsc/Actions (Contact::send is
|
|
3166
|
-
|
|
3167
|
-
reg.HandleAction("
|
|
3194
|
+
send in server-actions/contact; a class in app/Rsc is rpc only and has no action) or Go's
|
|
3195
|
+
reg.HandleAction("Contact.send", fn). Fields and browser checks
|
|
3168
3196
|
come from what it takes (rsc-host.json): a Laravel FormRequest's rules(), or a
|
|
3169
3197
|
Go struct, whose validate tags are read as hints and never run, so the Go
|
|
3170
3198
|
function must still check. It takes one object; a file needs form and handle.
|
|
3171
3199
|
A 422 from Laravel (a FormRequest type-hinted on the method, whose authorize()
|
|
3172
3200
|
returns true) or Go (rsckit.InvalidField) lands under the same fields,
|
|
3173
3201
|
uncaught. To check in TypeScript first, keep a schema and
|
|
3174
|
-
handle: (values) =>
|
|
3202
|
+
handle: (values) => send(values).
|
|
3175
3203
|
|
|
3176
3204
|
THE BOT TRAP: every form carries a hidden field named homepage. Filled in, the
|
|
3177
3205
|
submission is answered as a success and dropped - handle() never runs. So a
|