@rsc-kit/core 0.24.2 → 0.24.3
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/README.md +69 -62
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
React Server Components as a Vite plugin: it discovers the route tree, renders it, and serves it. Nitro builds the server around it, so there is no server file to write.
|
|
4
4
|
|
|
5
|
-
This is the library. Most people
|
|
5
|
+
This is the library. Most people start with `bun create rsc-kit@latest my-app` (a new app) or `bunx rsc-kit@latest init` (an existing project).
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
bun create rsc-kit@latest my-app
|
|
@@ -10,90 +10,97 @@ bun create rsc-kit@latest my-app
|
|
|
10
10
|
|
|
11
11
|
## Why not just use Next?
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
own
|
|
13
|
+
The routing conventions here *are* Next's — `app/`, `page`/`layout`/`loading`,
|
|
14
|
+
`@slot`, `(.)` interception, `"use client"`, server actions,
|
|
15
|
+
`generateMetadata` — so there is no translation table to learn. The difference
|
|
16
|
+
is underneath:
|
|
17
|
+
|
|
18
|
+
- **It is a Vite plugin, not a bundler.** You keep your `vite.config.ts` and
|
|
19
|
+
your plugins. Adding RSC is one entry in the plugins array.
|
|
20
|
+
- **It deploys wherever Nitro does.** [Nitro](https://nitro.build) builds the
|
|
21
|
+
server around the route tree, so the target is a preset — Bun, Node,
|
|
22
|
+
Cloudflare Workers, Vercel, Netlify, Deno.
|
|
23
|
+
- **A page ships no JavaScript until something on it needs some.** No client
|
|
24
|
+
component and no server action in its tree means stored HTML, with no React
|
|
25
|
+
in the browser ([guide](https://docs.rsc-kit.dev/guides/no-javascript)).
|
|
26
|
+
- **It can sit in front of a backend you already have.** With Laravel or Go
|
|
27
|
+
behind it, a server component calls the backend with
|
|
28
|
+
`await rpc('Orders.recent')`, typed from the backend's own signatures. See
|
|
29
|
+
[Backend-Answered Pages](https://docs.rsc-kit.dev/hosts/backend-answered-pages).
|
|
30
|
+
- **It compiles to a single binary** with `bun build --compile`, assets and
|
|
31
|
+
frozen pages inside it.
|
|
32
|
+
|
|
33
|
+
## Setup
|
|
29
34
|
|
|
30
35
|
```ts
|
|
31
|
-
|
|
36
|
+
// vite.config.ts
|
|
37
|
+
import { defineConfig } from 'vite'
|
|
38
|
+
import { nitro } from 'nitro/vite'
|
|
39
|
+
import react from '@vitejs/plugin-react'
|
|
40
|
+
import { rscKit } from '@rsc-kit/core/vite'
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
plugins: [nitro({ preset: 'bun', serveStatic: 'inline' }), rscKit(), react()],
|
|
44
|
+
})
|
|
32
45
|
```
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
70 kB gzipped back on a page with nothing to hydrate, of which react-dom alone
|
|
37
|
-
is ~54 kB. The build refuses the combination rather than shipping a button that
|
|
38
|
-
does nothing.
|
|
39
|
-
|
|
40
|
-
**And the framework itself is small, because most of what ships is React.**
|
|
41
|
-
Measured on the example app: a typical route is 85 kB gzipped, of which
|
|
42
|
-
**66 kB is React and react-dom** and this framework's own runtime is 6 kB.
|
|
43
|
-
Client components are chunked per module, so a route only downloads the ones it
|
|
44
|
-
renders — the three routes using TanStack Query are the only ones that pay for
|
|
45
|
-
it. Serving a page frozen at build time costs the server about 25 µs, because
|
|
46
|
-
it renders nothing.
|
|
47
|
+
React 19.2+ and Vite 8 are peer dependencies. The full walk-through is
|
|
48
|
+
[Installation](https://docs.rsc-kit.dev/installation).
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
With a backend, `rscKit({ hostManifest: { command, cwd, watch } })` runs the
|
|
51
|
+
backend's manifest command — `php artisan rsc:host-manifest`, or a Go program
|
|
52
|
+
calling `reg.WriteManifest` — when dev or a build starts, and again under dev
|
|
53
|
+
when something in a `watch` directory changes. It writes `rsc-host.json`
|
|
54
|
+
(`{ actions, functions, types, defs }`), from which the build generates typed
|
|
55
|
+
`rpc()` overloads and server action stubs.
|
|
50
56
|
|
|
51
57
|
## What you get
|
|
52
58
|
|
|
53
|
-
- File-based routing with layouts
|
|
54
|
-
route interception
|
|
59
|
+
- File-based routing with layouts (which receive `params`), loading
|
|
60
|
+
boundaries, parallel routes and route interception
|
|
55
61
|
- Streaming SSR with Suspense, and partial prerendering — the static shell is
|
|
56
62
|
stored, the part that needs the request is rendered per visit
|
|
57
|
-
- Server actions, with an optional builder
|
|
58
|
-
(any Standard Schema library — Zod, Valibot, ArkType) and
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
- Server actions, with an optional builder (`@rsc-kit/core/action`) for
|
|
64
|
+
validation (any Standard Schema library — Zod, Valibot, ArkType) and
|
|
65
|
+
middleware; `<Form>` with field errors and `formError`, and `useAction` for
|
|
66
|
+
calls without a form
|
|
67
|
+
- API routes in `app/**/route.ts` — a `Request` in, a `Response` out, frozen
|
|
68
|
+
at build time when they read nothing from the request
|
|
61
69
|
- Typed urls: `params`, `searchParams` and request bodies arrive parsed through
|
|
62
70
|
a schema you export beside the route
|
|
63
71
|
- Typed routes: every build writes the routes it found, so a link to a page
|
|
64
72
|
that does not exist stops compiling
|
|
65
|
-
- `middleware.ts` that runs before every render below it
|
|
73
|
+
- `middleware.ts` that runs before every render below it; `notFound()` there
|
|
74
|
+
answers 404
|
|
66
75
|
- Request and response access — `headers()`, `cookies()`, `responseHeaders()`
|
|
67
76
|
- Offline and installable: a generated service worker, a web manifest, icons
|
|
68
77
|
found by name, and a place to put your own push handlers
|
|
78
|
+
- Testing without a browser: `createTestApp({ host, backend })` from
|
|
79
|
+
`@rsc-kit/core/testing` fetches any url, with `hostReply` to fake backend
|
|
80
|
+
answers ([guide](https://docs.rsc-kit.dev/guides/testing))
|
|
69
81
|
- A build that explains itself — why each route is dynamic, what it ships, and
|
|
70
|
-
a report
|
|
71
|
-
|
|
72
|
-
## Status
|
|
73
|
-
|
|
74
|
-
**0.x. Early, and honest about it.** The API will change before 1.0, and
|
|
75
|
-
`@vitejs/plugin-rsc` — which this builds on — is itself pre-1.0.
|
|
82
|
+
a `build-report.json` that [`@rsc-kit/mcp`](https://www.npmjs.com/package/@rsc-kit/mcp)
|
|
83
|
+
answers questions from
|
|
76
84
|
|
|
77
|
-
|
|
78
|
-
it has had an adversarial security review, and it runs a real documentation
|
|
79
|
-
site in production. It has not been used by anyone but its author. Issues and
|
|
80
|
-
questions are welcome; promises are not being made yet.
|
|
85
|
+
## Commands
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
- `rsc-kit-typegen` writes the generated types without starting Vite;
|
|
88
|
+
`--check` exits non-zero when the committed `rsc-host.json` or types are
|
|
89
|
+
stale ([typed routes](https://docs.rsc-kit.dev/guides/typed-routes)).
|
|
90
|
+
- `rsc-kit-conformance` checks a backend adapter against the host-call
|
|
91
|
+
contract ([your own backend](https://docs.rsc-kit.dev/hosts/your-own-backend)):
|
|
84
92
|
|
|
85
|
-
|
|
93
|
+
```sh
|
|
94
|
+
npx -y -p @rsc-kit/core rsc-kit-conformance \
|
|
95
|
+
--endpoint http://127.0.0.1:8123/__rsc/host-call --secret test --manifest rsc-host.json
|
|
96
|
+
```
|
|
86
97
|
|
|
87
|
-
|
|
88
|
-
bun create rsc-kit@latest my-app # a new app
|
|
89
|
-
cd my-app && bun run dev
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Adding it to a project you already have:
|
|
98
|
+
## Status
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
**0.x.** The API will change before 1.0, and `@vitejs/plugin-rsc` — which
|
|
101
|
+
this builds on — is itself pre-1.0. It has had an adversarial security review
|
|
102
|
+
and runs a real documentation site in production. See
|
|
103
|
+
[SECURITY.md](./SECURITY.md) for the threat model and how to report something.
|
|
97
104
|
|
|
98
105
|
Docs: https://docs.rsc-kit.dev
|
|
99
106
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/core",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.3",
|
|
4
4
|
"description": "React Server Components as a Vite plugin. Routing, streaming, server actions, typed urls and build-time prerendering — deploy to Bun, Node, Workers, Vercel or Deno.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|