@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.
- package/dist/recipes.js +18 -2
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -252
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +300 -169
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +2 -2
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -542
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +270 -216
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +269 -147
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -539
- package/guides/laravel.md +0 -787
- package/guides/your-own-backend.md +0 -602
package/guides/bun.md
CHANGED
|
@@ -2,20 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
> What is different when the runtime is Bun — and what only looks like it is.
|
|
4
4
|
|
|
5
|
-
Bun is the default host, and most of an app never notices.
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Bun is the default host, and most of an app never notices. This page is what
|
|
6
|
+
an app *does* notice, collected from real ports: the framework's part first,
|
|
7
|
+
then the things that will look like the framework's fault and are not.
|
|
8
8
|
|
|
9
|
-
## Vite
|
|
9
|
+
## Running Vite on Bun
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
app that imports `bun`, `bun:sqlite` or a Bun-only driver then fails at the
|
|
14
|
-
first render with `Cannot find package 'bun'`, in a project that just said
|
|
15
|
-
it was a Bun app.
|
|
16
|
-
|
|
17
|
-
The scaffold's scripts run Vite on Bun's runtime, and an existing app should
|
|
18
|
-
too:
|
|
11
|
+
Start Vite with `bun --bun`, so the dev server, the build and the prerender run
|
|
12
|
+
on Bun's runtime:
|
|
19
13
|
|
|
20
14
|
```json title="package.json"
|
|
21
15
|
{
|
|
@@ -27,22 +21,29 @@ too:
|
|
|
27
21
|
}
|
|
28
22
|
```
|
|
29
23
|
|
|
24
|
+
The scaffold writes these, and an existing app should use them too. `vite` is
|
|
25
|
+
a bin with a Node shebang, so `bun run dev` alone starts Vite under **Node**. An
|
|
26
|
+
app that imports `bun`, `bun:sqlite` or a Bun-only driver then fails at the
|
|
27
|
+
first render with `Cannot find package 'bun'`, in a project that just said it
|
|
28
|
+
was a Bun app.
|
|
29
|
+
|
|
30
30
|
`createTestApp()` runs that `build` script, so a test builds on the same
|
|
31
31
|
runtime the server ships on.
|
|
32
32
|
|
|
33
33
|
## Native dependencies stay outside the bundle
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
`@prisma/client` — cannot be rolled into a server bundle: the build succeeds
|
|
37
|
-
and the server cannot load its own binary. The usual ones are left external
|
|
38
|
-
by default, and Nitro traces each into `.output/server/node_modules` with its
|
|
39
|
-
binaries, so the deployment is still one directory. For one that is not on
|
|
40
|
-
the list:
|
|
35
|
+
For a native package that is not on the default list, name it:
|
|
41
36
|
|
|
42
37
|
```ts title="vite.config.ts"
|
|
43
38
|
rscKit({ serverExternalPackages: ['@acme/native-thing'] })
|
|
44
39
|
```
|
|
45
40
|
|
|
41
|
+
A package with a native binary — `sharp`, `bcrypt`, `better-sqlite3`,
|
|
42
|
+
`@prisma/client` — cannot be rolled into a server bundle: the build succeeds
|
|
43
|
+
and the server cannot load its own binary. The usual ones are left external
|
|
44
|
+
by default, and Nitro traces each into `.output/server/node_modules` with its
|
|
45
|
+
binaries, so the deployment is still one directory.
|
|
46
|
+
|
|
46
47
|
The same applies on Node; it is only more visible on Bun because the
|
|
47
48
|
scaffold builds there.
|
|
48
49
|
|
|
@@ -50,27 +51,43 @@ A [compiled binary](/hosts/where-it-runs/#native-packages-in-a-binary)
|
|
|
50
51
|
carries these packages. It writes them to `RSC_KIT_RUNTIME_DIR` on its first
|
|
51
52
|
start, so it needs a directory it can write to.
|
|
52
53
|
|
|
53
|
-
##
|
|
54
|
+
## Building without the production secrets
|
|
55
|
+
|
|
56
|
+
A build machine without the production variables sets
|
|
57
|
+
`SKIP_ENV_VALIDATION=1`:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
SKIP_ENV_VALIDATION=1 bun run build
|
|
61
|
+
```
|
|
54
62
|
|
|
55
63
|
The build prerenders pages, which runs the app, which runs `instrumentation.ts`,
|
|
56
|
-
which imports `env.ts`.
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
which imports `env.ts`. The server that runs the build validates at startup
|
|
65
|
+
regardless.
|
|
66
|
+
|
|
67
|
+
Never put `NODE_ENV` in a `.env`. Vite honours it, and
|
|
59
68
|
`NODE_ENV=development` turns `vite build` into a build that cannot render;
|
|
60
69
|
[the build refuses it](/installation#environment-variables) and names the
|
|
61
70
|
line.
|
|
62
71
|
|
|
63
|
-
##
|
|
72
|
+
## Things that are Bun's, not the framework's
|
|
64
73
|
|
|
65
74
|
- **`bun test` reads `.env`.** Bun loads the package's `.env` into every test
|
|
66
75
|
run. A test that must not see the app's variables — or must see only the
|
|
67
76
|
ones it sets — runs with `bun test --env-file=/dev/null`.
|
|
68
77
|
- **Stripe's SDK is async-only on Bun.** `stripe.webhooks.constructEvent()`
|
|
69
78
|
throws on every call because Bun has no synchronous WebCrypto;
|
|
70
|
-
`constructEventAsync()` is the same check, awaited
|
|
79
|
+
`constructEventAsync()` is the same check, awaited:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const event = await stripe.webhooks.constructEventAsync(body, signature, secret);
|
|
83
|
+
```
|
|
71
84
|
- **`pg` puts SQLSTATE in `errno`.** Bun's Postgres driver reports the
|
|
72
85
|
five-character SQLSTATE (`23505`) where Node's `pg` reports it as `code`.
|
|
73
|
-
Match on both if the app runs on both
|
|
86
|
+
Match on both if the app runs on both:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const unique = (error.code ?? error.errno) === '23505';
|
|
90
|
+
```
|
|
74
91
|
- **Bun's `setTimeout(0)` is a real millisecond**, as Node's is. Nothing to
|
|
75
92
|
do; worth knowing when a test counts ticks.
|
|
76
93
|
|
package/guides/caching.md
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> cache() — one lookup, however many places need it, and with a key and a lifetime, however many requests.
|
|
4
4
|
|
|
5
|
-
Middleware checks who you are
|
|
6
|
-
permissions.
|
|
7
|
-
|
|
8
|
-
Wrap the lookup:
|
|
5
|
+
Middleware checks who you are, the layout shows their name, and the page reads
|
|
6
|
+
their permissions. Wrap the lookup in `cache()`, and those three calls make one:
|
|
9
7
|
|
|
10
8
|
```ts
|
|
11
9
|
import { cache } from '@rsc-kit/core/cache'
|
|
@@ -13,7 +11,9 @@ import { cache } from '@rsc-kit/core/cache'
|
|
|
13
11
|
export const currentUser = cache(async () => db.user(await sessionId()))
|
|
14
12
|
```
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
## Calling it more than once
|
|
15
|
+
|
|
16
|
+
Call it wherever you need it. The first call runs, and the rest get the same
|
|
17
17
|
answer:
|
|
18
18
|
|
|
19
19
|
```tsx
|
|
@@ -28,17 +28,17 @@ export default async function Page() {
|
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Without options, an answer lasts one request. Two requests in flight never see
|
|
32
|
+
each other's answers, and nothing survives into the next one, so one visitor
|
|
33
|
+
never sees another's data.
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
That is the whole safety story: a table that outlived its request would not be a
|
|
37
|
-
stale cache, it would be one visitor seeing another's data.
|
|
35
|
+
React's `cache()` is the same idea, but it isn't open yet when middleware runs,
|
|
36
|
+
which is where the duplicate lookups start.
|
|
38
37
|
|
|
39
38
|
## Arguments
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
Arguments are compared the way React compares them: primitives by value,
|
|
41
|
+
objects by identity.
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
44
|
const post = cache(async (id: string) => db.post(id))
|
|
@@ -49,18 +49,12 @@ post('b') // runs
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
Two objects that look the same are two different calls, so pass an id rather
|
|
52
|
-
than an object
|
|
53
|
-
|
|
54
|
-
<Aside type="note" title="Not React's cache()">
|
|
55
|
-
Same idea, wider scope. Middleware runs before any component does, which is
|
|
56
|
-
exactly where the duplicate lookups start — and React has no scope open yet.
|
|
57
|
-
</Aside>
|
|
52
|
+
than an object.
|
|
58
53
|
|
|
59
54
|
## Across requests
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
a price list
|
|
63
|
-
between requests:
|
|
56
|
+
For an answer that is the same for every visitor, such as a page built in the
|
|
57
|
+
panel, a menu or a price list, give `cache()` a key and a lifetime:
|
|
64
58
|
|
|
65
59
|
```ts
|
|
66
60
|
import { cache } from '@rsc-kit/core/cache'
|
|
@@ -71,8 +65,22 @@ export const findPage = cache(
|
|
|
71
65
|
)
|
|
72
66
|
```
|
|
73
67
|
|
|
74
|
-
Each request still asks once
|
|
75
|
-
|
|
68
|
+
Each request still asks once. Across requests, the answer for each list of
|
|
69
|
+
arguments is kept for `revalidate` seconds.
|
|
70
|
+
|
|
71
|
+
- **`key`** names the function in the store. Use the same key on every
|
|
72
|
+
instance, and a different key for every function.
|
|
73
|
+
- **Arguments and answers are JSON.** A `Date` comes back as a string, on the
|
|
74
|
+
first call as well as later ones.
|
|
75
|
+
- **It runs as nobody.** `cookies()` and `headers()` throw inside it, and a call
|
|
76
|
+
to Laravel or Go carries no session. A kept answer is handed to every visitor,
|
|
77
|
+
so it must not be about one of them.
|
|
78
|
+
- **A deploy starts empty.** Keys include the build, so a new deploy never reads
|
|
79
|
+
what an old one kept.
|
|
80
|
+
|
|
81
|
+
### Saying the data changed
|
|
82
|
+
|
|
83
|
+
When the data changes, call `changed()` with its tag,
|
|
76
84
|
and the next ask misses at once:
|
|
77
85
|
|
|
78
86
|
```ts
|
|
@@ -85,35 +93,31 @@ export async function savePage(values: PageValues) {
|
|
|
85
93
|
}
|
|
86
94
|
```
|
|
87
95
|
|
|
88
|
-
`
|
|
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
|
|
91
|
-
includes its tags' versions, so a change makes a new key, and the old entry is
|
|
92
|
-
never read again. `tags` can also be a function of the arguments, for a tag per
|
|
93
|
-
record:
|
|
96
|
+
`tags` can also be a function of the arguments, for a tag per record:
|
|
94
97
|
|
|
95
98
|
```ts
|
|
96
99
|
cache(findBySlug, { key: 'pages.find', revalidate: 3600, tags: (slug) => [`page:${slug}`] })
|
|
97
100
|
```
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
`changed()` is the same call that refreshes open tabs for
|
|
103
|
+
[live data](/guides/live-data), and a page kept with [ISR](/guides/isr) that
|
|
104
|
+
read the answer renders again too.
|
|
105
|
+
|
|
106
|
+
Nothing is purged. Each kept answer's key includes its tags' versions, so a
|
|
107
|
+
change makes a new key, and the old entry is never read again.
|
|
108
|
+
|
|
109
|
+
`changed()` reaches every instance only when the versions are shared, as set up
|
|
110
|
+
for [live data](/guides/live-data-in-production#where-the-versions-live). With
|
|
111
|
+
the default in-memory versions, another instance sees a change once its kept
|
|
112
|
+
answer expires, after at most `revalidate` seconds.
|
|
108
113
|
|
|
109
114
|
### Where answers are kept
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
instance. To share them across instances, install a store. It needs only a
|
|
116
|
+
By default answers are kept in memory: the 1,000 most recently used, one copy
|
|
117
|
+
per instance. To share them across instances, install a store. It needs only a
|
|
113
118
|
`get` and a `set`:
|
|
114
119
|
|
|
115
|
-
```ts
|
|
116
|
-
// instrumentation.ts
|
|
120
|
+
```ts title="src/instrumentation.ts"
|
|
117
121
|
import { installCacheStore } from '@rsc-kit/core/cache'
|
|
118
122
|
|
|
119
123
|
// Redis
|
|
@@ -131,10 +135,3 @@ installCacheStore(() => ({
|
|
|
131
135
|
|
|
132
136
|
A store that fails makes pages slower, not broken: the engine warns once and
|
|
133
137
|
does the lookup itself.
|
|
134
|
-
|
|
135
|
-
<Aside type="caution" title="Changes on other instances">
|
|
136
|
-
`changed()` reaches every instance only when the versions are shared, as
|
|
137
|
-
set up for [live data](/guides/live-data#where-the-versions-live). With the
|
|
138
|
-
default in-memory versions, another instance sees a change once its kept
|
|
139
|
-
answer expires, after at most `revalidate` seconds.
|
|
140
|
-
</Aside>
|
|
@@ -45,7 +45,7 @@ out of `package.json` when the last page that imports them is gone.
|
|
|
45
45
|
| Inertia | here |
|
|
46
46
|
| --- | --- |
|
|
47
47
|
| `resources/js/Pages/Orders/Index.jsx` | `resources/js/app/orders/page.tsx` — the file is the route; no `Route::get` for it |
|
|
48
|
-
| `Route::get('/orders', [OrdersController::class, 'index'])` + `Inertia::render('Orders/Index', ['orders' => …])` | nothing. The controller's body moves to `app/Rsc/Orders.php::recent()`, and the page calls `rpc('Orders.recent')` — [Calling PHP](/hosts/laravel
|
|
48
|
+
| `Route::get('/orders', [OrdersController::class, 'index'])` + `Inertia::render('Orders/Index', ['orders' => …])` | nothing. The controller's body moves to `app/Rsc/Orders.php::recent()`, and the page calls `rpc('Orders.recent')` — [Calling PHP](/hosts/laravel/calling-php) |
|
|
49
49
|
| props from the controller | `await rpc<T>('Class.method', …args)` inside the server component — as many reads as the page wants; siblings in one render are one batched request |
|
|
50
50
|
| `usePage().props.auth.user` and the rest of `HandleInertiaRequests::share()` | a read in the layout that needs it — `rpc('Shared.auth')` — passed down as props; there is no global props bag |
|
|
51
51
|
| `usePage().props.flash` | the action's own return value, for the form that submitted; for the page after a redirect, `Rsc::flash('Saved.')` (or `flash()` in a JS action) and `useFlash()`, which shows it once |
|
|
@@ -196,7 +196,7 @@ guest to `/login` — is performed by the browser. See [Authorization](/guides/a
|
|
|
196
196
|
React renders; the rest is Laravel's.
|
|
197
197
|
- **Two processes.** Vite is the renderer in development and Laravel proxies
|
|
198
198
|
to it through `public/rsc-hot`; in production the built server sits in
|
|
199
|
-
front. `php artisan serve` needs `PHP_CLI_SERVER_WORKERS` — [why](/hosts/laravel#
|
|
199
|
+
front. `php artisan serve` needs `PHP_CLI_SERVER_WORKERS` — [why](/hosts/laravel#php-artisan-serve-needs-workers).
|
|
200
200
|
- **The build says what each page costs.** `○` is frozen and served as a
|
|
201
201
|
file; `◐` streams the part that reads the session. An Inertia app rendered
|
|
202
202
|
every page per request; most of yours will not.
|