@rsc-kit/mcp 0.41.0 → 0.42.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.
Files changed (60) hide show
  1. package/dist/recipes.js +12 -2
  2. package/dist/recipes.js.map +1 -1
  3. package/guides/admin-plugins.md +206 -6
  4. package/guides/api-routes.md +159 -215
  5. package/guides/authorization.md +103 -114
  6. package/guides/backend-answered-pages.md +301 -252
  7. package/guides/bap-vs-inertia.md +67 -25
  8. package/guides/blueprints.md +300 -169
  9. package/guides/bun.md +42 -25
  10. package/guides/caching.md +46 -49
  11. package/guides/coming-from-inertia.md +2 -2
  12. package/guides/commands.md +251 -200
  13. package/guides/connection.md +50 -54
  14. package/guides/content-security-policy.md +133 -84
  15. package/guides/domains.md +190 -149
  16. package/guides/edge-caching.md +242 -268
  17. package/guides/emails.md +96 -45
  18. package/guides/errors.md +116 -137
  19. package/guides/feature-flags.md +100 -30
  20. package/guides/file-uploads.md +101 -26
  21. package/guides/fonts.md +139 -110
  22. package/guides/forms.md +520 -542
  23. package/guides/images.md +87 -28
  24. package/guides/index.json +13 -33
  25. package/guides/instrumentation.md +134 -95
  26. package/guides/isr.md +3 -3
  27. package/guides/live-data-in-production.md +695 -0
  28. package/guides/live-data.md +170 -839
  29. package/guides/mcp.md +83 -59
  30. package/guides/metadata.md +124 -179
  31. package/guides/navigation.md +118 -147
  32. package/guides/no-javascript.md +49 -57
  33. package/guides/offline.md +118 -153
  34. package/guides/openapi.md +100 -35
  35. package/guides/pages.md +160 -50
  36. package/guides/ppr.md +178 -256
  37. package/guides/pwa.md +251 -218
  38. package/guides/queries.md +171 -300
  39. package/guides/react-compiler.md +90 -50
  40. package/guides/redirects.md +141 -177
  41. package/guides/response-headers.md +76 -74
  42. package/guides/route-interception.md +112 -111
  43. package/guides/routing.md +216 -322
  44. package/guides/sections.md +63 -66
  45. package/guides/seo-files.md +127 -65
  46. package/guides/server-actions.md +285 -357
  47. package/guides/static-generation.md +131 -199
  48. package/guides/testing.md +269 -147
  49. package/guides/third-party-scripts.md +94 -47
  50. package/guides/typed-routes.md +115 -113
  51. package/guides/url-validation.md +113 -61
  52. package/guides/validation.md +53 -62
  53. package/guides/view-transitions.md +159 -132
  54. package/guides/where-it-runs.md +226 -162
  55. package/package.json +2 -2
  56. package/guides/admin.md +0 -520
  57. package/guides/deployment.md +0 -598
  58. package/guides/go.md +0 -539
  59. package/guides/laravel.md +0 -787
  60. package/guides/your-own-backend.md +0 -602
@@ -2,33 +2,58 @@
2
2
 
3
3
  > Analytics, tag managers and widgets — and why there is no Script component.
4
4
 
5
- Write the tag. React 19 does the rest, and it does the parts Next's `<Script>`
6
- component existed for.
7
-
8
- ## An external script
5
+ Write a `<script>` tag. React 19 puts it in the `<head>` and sends it once, so
6
+ there is no `Script` component to import:
9
7
 
10
8
  ```tsx title="src/app/layout.tsx"
11
- export default function RootLayout({ children }) {
9
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
12
10
  return (
13
- <html>
11
+ <html lang="en">
14
12
  <body>
15
13
  {children}
16
- <script async src="https://www.clarity.ms/tag/abc123" />
14
+ <script async src="https://plausible.io/js/script.js" data-domain="example.com" />
17
15
  </body>
18
16
  </html>
19
17
  )
20
18
  }
21
19
  ```
22
20
 
23
- Rendered from a server component, React **hoists** it into `<head>` and
24
- **deduplicates** it — render the same `src` in three components and one tag
25
- goes out. `async` means it never blocks the page. That is `afterInteractive`,
26
- without an import.
21
+ ## Adding an external script
22
+
23
+ Render the tag with `async` from a server component:
24
+
25
+ ```tsx
26
+ <script async src="https://www.clarity.ms/tag/abc123" />
27
+ ```
28
+
29
+ React **hoists** it into `<head>` and **deduplicates** it. Render the same
30
+ `src` in three components and one tag goes out. `async` means it never blocks
31
+ the page.
27
32
 
28
- ## An inline snippet
33
+ Put site-wide scripts in the root layout. The root layout renders once and is
34
+ kept across navigations, so the script runs once. In a page, a client-side
35
+ navigation renders the tag again, and whether the browser runs a script
36
+ inserted that way isn't something to rely on.
37
+
38
+ ## Adding an inline snippet
39
+
40
+ Most analytics ship a few lines that stub a global and load the real script.
41
+ Google Analytics:
42
+
43
+ ```tsx title="src/app/layout.tsx"
44
+ <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX" />
45
+ <script
46
+ id="gtag-init"
47
+ dangerouslySetInnerHTML={{
48
+ __html: `window.dataLayer = window.dataLayer || [];
49
+ function gtag(){dataLayer.push(arguments);}
50
+ gtag('js', new Date());
51
+ gtag('config', 'G-XXXXXXX');`,
52
+ }}
53
+ />
54
+ ```
29
55
 
30
- Most analytics ship one — a few lines that stub a global and load the real
31
- thing:
56
+ Microsoft Clarity:
32
57
 
33
58
  ```tsx title="src/app/layout.tsx"
34
59
  <script
@@ -42,36 +67,15 @@ thing:
42
67
  />
43
68
  ```
44
69
 
45
- It renders where you wrote it and runs during parse, **before hydration**. For
46
- a snippet whose job is to start recording as early as possible, that is the
47
- earlier of the two moments and the one its authors intended. Next's
48
- `Script` with `strategy="afterInteractive"` would have made it later.
49
-
50
- :::note[Put it in the root layout]
51
- The root layout renders once and is kept across navigations, so the snippet
52
- runs once. In a *page*, a client-side navigation to it re-renders the tag, and
53
- whether the browser runs a script inserted that way is not something to rely on
54
- either way. Site-wide scripts go in the layout; that is where they belong
55
- anyway.
56
- :::
57
-
58
- ## Porting from Next
59
-
60
- | Next's `Script strategy` | here |
61
- | --- | --- |
62
- | `beforeInteractive` | `<script src>` without `async` — the browser blocks on it, which is what that strategy meant |
63
- | `afterInteractive` | `<script async src>`, or the inline snippet above |
64
- | `lazyOnload` | the effect below, inside `requestIdleCallback` |
65
- | `worker` | not supported — that was Partytown, a separate project |
66
-
67
- The `id` prop carries across unchanged. `onLoad` and `onReady` are the one
68
- thing that needs a component, because they need to run in the browser:
70
+ An inline snippet renders where you wrote it and runs during parse,
71
+ **before hydration**. For a snippet whose job is to start recording as early
72
+ as possible, that is what its authors intended. Next's `Script` with
73
+ `strategy="afterInteractive"` would have run it later.
69
74
 
70
- ## When a script has to run after hydration
75
+ ## Running a script after hydration
71
76
 
72
- Rare, and specific: a script that touches DOM React rendered, and would find it
73
- missing if it ran during parse. A ten-line client component covers it, and it is
74
- yours rather than ours because there is nothing to abstract:
77
+ Some scripts touch DOM that React rendered, and find it missing if they run
78
+ during parse. Load those from a small client component of your own:
75
79
 
76
80
  ```tsx title="src/components/AfterHydration.tsx"
77
81
  'use client'
@@ -95,11 +99,54 @@ export function AfterHydration({ src, onLoad }: { src: string; onLoad?: () => vo
95
99
  }
96
100
  ```
97
101
 
98
- Wrap the body in `requestIdleCallback` and it is `lazyOnload`.
102
+ ```tsx title="src/app/support/page.tsx"
103
+ <AfterHydration src="https://widget.example.com/chat.js" />
104
+ ```
105
+
106
+ This is also where `onLoad` and `onReady` go: they run in the browser, so they
107
+ need a component.
108
+
109
+ ## Loading a script when the page is idle
110
+
111
+ Wrap the effect's body in `requestIdleCallback`:
112
+
113
+ ```tsx
114
+ useEffect(() => {
115
+ const id = requestIdleCallback(() => {
116
+ const tag = document.createElement('script')
117
+
118
+ tag.src = src
119
+ tag.async = true
120
+ document.head.append(tag)
121
+ })
122
+
123
+ return () => cancelIdleCallback(id)
124
+ }, [src])
125
+ ```
126
+
127
+ That is Next's `lazyOnload`.
128
+
129
+ ## Under a Content Security Policy
130
+
131
+ A script loaded by `src` needs its origin in `script-src`. An inline snippet in
132
+ a page the build stores is hashed and runs. On a page rendered per request,
133
+ render it from a client component and give it `useNonce()`'s nonce. See
134
+ [Content Security Policy](/guides/content-security-policy#your-own-inline-code).
135
+
136
+ ## Porting from Next
137
+
138
+ | Next's `Script strategy` | Here |
139
+ | --- | --- |
140
+ | `beforeInteractive` | `<script src>` without `async`. The browser blocks on it, which is what that strategy meant. |
141
+ | `afterInteractive` | `<script async src>`, or an inline snippet |
142
+ | `lazyOnload` | [The idle effect](#loading-a-script-when-the-page-is-idle) |
143
+ | `worker` | Not supported. That was Partytown, a separate project. |
144
+
145
+ The `id` prop carries across unchanged.
99
146
 
100
147
  ## Why nothing ships for this
101
148
 
102
- A `Script` component would be a wrapper around a `script` tag whose two
103
- useful behaviours — hoisting and deduplication — React already provides. The
104
- package's own tests pin that React does, so the day it stops, this page is
105
- what changes rather than your app.
149
+ A `Script` component would wrap a `script` tag whose two useful behaviours,
150
+ hoisting and deduplication, React already provides. The package's own tests
151
+ pin that React does, so the day it stops, this page is what changes rather
152
+ than your app.
@@ -2,8 +2,8 @@
2
2
 
3
3
  > Links that fail the typecheck instead of the browser.
4
4
 
5
- Every build writes the urls it found to `.rsc-kit/rsc-routes.d.ts`.
6
- `Link`, `visit`, `prefetch` and `Form` accept only those.
5
+ Every build writes the URLs it found to `.rsc-kit/rsc-routes.d.ts`. `Link`,
6
+ `visit`, `prefetch`, `redirect` and `Form` accept only those:
7
7
 
8
8
  ```tsx
9
9
  import Link from '@rsc-kit/core/Link'
@@ -12,31 +12,32 @@ import Link from '@rsc-kit/core/Link'
12
12
  <Link href="/abuot">About</Link> // ❌ typecheck fails
13
13
  ```
14
14
 
15
- Dynamic segments work through ordinary template literals:
15
+ A link to a page you renamed or deleted stops compiling, instead of becoming a
16
+ 404 someone finds after you deploy.
17
+
18
+ ## Linking to a dynamic route
19
+
20
+ Use an ordinary template literal:
16
21
 
17
22
  ```tsx
18
23
  <Link href={`/posts/${post.slug}`}>{post.title}</Link> // ✅
19
24
  <Link href={`/postz/${post.slug}`}>{post.title}</Link> // ❌
20
25
  ```
21
26
 
22
- ## There is no `route()` helper
23
-
24
- Deliberately. A template literal is already checked the same way a builder
25
- would check it, so a builder would only wrap what the language does for free.
26
- One existed and was removed.
27
+ There is no `route()` helper. A template literal is already checked the way a
28
+ builder would check it.
27
29
 
28
- The one thing to watch is that a value you interpolate is url-safe.
29
- `` `/posts/${'a / b'}` `` type-checks and means three path segments — use
30
- `encodeURIComponent` when the value is not yours:
30
+ Encode a value that isn't yours. `` `/posts/${'a / b'}` `` type-checks, but it
31
+ means three path segments:
31
32
 
32
33
  ```tsx
33
34
  <Link href={`/posts/${encodeURIComponent(slug)}`}>…</Link>
34
35
  ```
35
36
 
36
- ## Search params, typed by the page
37
+ ## Typed search params
37
38
 
38
- A page that [exports a `searchParams` schema](/guides/url-validation) has said
39
- what its query string means. The same schema types every link to it:
39
+ A page that [exports a `searchParams` schema](/guides/url-validation) types
40
+ every link to it:
40
41
 
41
42
  ```tsx title="src/app/search/page.tsx"
42
43
  export const searchParams = z.object({
@@ -52,84 +53,49 @@ export const searchParams = z.object({
52
53
  <Link href="/search" search={{ page: '2' }}>…</Link> // does not compile: page is a number
53
54
  ```
54
55
 
55
- A key the page requires is required on the link — a `q: z.string()` with no
56
- default makes `search` itself required, so the page's error boundary is not
57
- where a missing `q` is found. A page with no schema takes any scalars, and so
58
- does an href that is not one route (`path as Route`), because there is nothing
59
- to check it against.
56
+ - **A required key is required on the link.** A `q: z.string()` with no default
57
+ makes `search` itself required, so a missing `q` is caught by the compiler,
58
+ not by the page's error boundary.
59
+ - **Values are typed by what the page sees.** `z.coerce.number()` accepts
60
+ anything, but the link takes a number. Whether a key is required comes from
61
+ the schema's input; its type comes from the output.
62
+ - **Arrays repeat the key.** `tags: ['a', 'b']` becomes `?tags=a&tags=b`, which
63
+ is what `z.array()` parses back.
64
+ - **A page with no schema takes any scalars**, and so does an href that isn't
65
+ one route (`path as Route`), because there's nothing to check it against.
60
66
 
61
- Values are typed by what the page will **see**, not what the schema accepts:
62
- `z.coerce.number()` takes anything in, and a link typed by that would take
63
- `page: 'two'`. Required-ness comes from the schema's input, the value from its
64
- output. Arrays repeat the key — `tags: ['a', 'b']` is `?tags=a&tags=b`, which
65
- is what `z.array()` parses back.
66
-
67
- For `visit()`, `prefetch()` and anything else that wants the string,
68
- `href()` runs the same check:
67
+ For `visit()`, `prefetch()` and anything else that wants a string, `href()`
68
+ runs the same check:
69
69
 
70
70
  ```ts
71
71
  import { href } from '@rsc-kit/core/routes';
72
72
 
73
73
  visit(href('/search', { q: 'shoes', page: 2 }));
74
+ redirect(href('/search', { q: 'shoes' }));
74
75
  ```
75
76
 
76
- The build writes one line per route into `rsc-routes.d.ts` that reads the
77
- page module's `searchParams` export as a type. Nothing runs; a page without
78
- the export costs nothing.
79
-
80
- ## Two limits
77
+ ## A list of links
81
78
 
82
- **A dynamic segment widens.** `/posts/[slug]` becomes `` `/posts/${string}` ``,
83
- so `/posts/a/b` type-checks even though it does not match at runtime.
84
-
85
- **A list widens to `string`** unless you say what it is:
79
+ TypeScript widens an array's `href` to `string` unless you say what it is. Use
80
+ `satisfies` with `Route`:
86
81
 
87
82
  ```tsx
83
+ import type { Route } from '@rsc-kit/core/routes'
84
+
88
85
  const nav = [
89
86
  { href: '/', label: 'Home' },
90
87
  { href: '/about', label: 'About' },
91
88
  ] satisfies { href: Route; label: string }[]
92
- ```
93
-
94
- Without `satisfies`, TypeScript infers `string` for `href` and you lose the
95
- check.
96
89
 
97
- ## The build checks
98
-
99
- `vite build` runs the project's typecheck before it bundles, and stops on an
100
- error — so a link to a route that does not exist is a failed build, not a 404
101
- found after deploying. It is the same `tsc --noEmit` the `check` script runs,
102
- on the same tsconfig, and it costs about a second. `rscKit({ typecheck: false })`
103
- turns it off; a project with no `tsconfig.json`, or no `typescript`
104
- installed, is skipped without being asked.
105
-
106
- ## After adding a route
107
-
108
- The file is written whenever Vite starts — a build, or the dev server, which
109
- also rewrites it when it sees a route added. A typecheck run with neither, by
110
- an agent or in CI, reads what the last start wrote, so a link to a route
111
- added since fails with `"/admin"` is not assignable to type `Route`.
112
- `rsc-kit-typegen` writes it without starting Vite, from the app's own
113
- `vite.config`. The scaffold's `typecheck` and `check` scripts run it first; an
114
- older project adds it the same way:
115
-
116
- ```json title="package.json"
117
- "typecheck": "rsc-kit-typegen && tsc --noEmit"
90
+ nav.map((item) => <Link key={item.href} href={item.href}>{item.label}</Link>)
118
91
  ```
119
92
 
120
- ## If you never run the generator
121
-
122
- `.rsc-kit/rsc-routes.d.ts` is written by the build. Without it — or with a
123
- tsconfig whose `include` does not cover `.rsc-kit` — nothing is registered,
124
- every url-taking prop stays exactly as permissive as a plain `string`, and
125
- nothing breaks. There is no flag to turn this on.
93
+ Without `satisfies`, `href` is a `string` and you lose the check.
126
94
 
127
- ## `redirect()` is typed
95
+ ## A URL computed at runtime
128
96
 
129
- `redirect('/login')` is checked like a `Link`, so a redirect to a page that was
130
- renamed or deleted stops compiling instead of sending someone to a 404. A
131
- destination that is computed — read from a cookie, handed over by middleware —
132
- is a string the compiler cannot check, so it takes the cast:
97
+ A destination read from a cookie or handed over by middleware is a string the
98
+ compiler can't check. Cast it, and you vouch for it:
133
99
 
134
100
  ```ts
135
101
  redirect('/login'); // ✅
@@ -137,51 +103,42 @@ redirect('/logn'); // ❌
137
103
  redirect(returnTo as Route); // computed: you vouch for it
138
104
  ```
139
105
 
140
- A page's `search` is checked on `redirect()` too, against the destination's own
141
- `searchParams` schema — see [redirects](/guides/redirects/#with-a-query-string).
106
+ A redirect's `search` is checked too, against the destination's own
107
+ `searchParams` schema. See [redirects](/guides/redirects/#with-a-query-string).
142
108
 
143
- ## Api routes
109
+ ## Fetching an API route
144
110
 
145
- A `route.ts` is a `Route` too — `<Link href="/logout">`, `visit('/agent-account')`
146
- and `redirect('/files/export.csv')` all typecheck, as they do in Next. What
147
- differs is what the browser does with one: a route answers with a `Response`,
148
- not a page, so the client treats a link to it as the anchor it is — never
149
- prefetched (a hover must not sign someone out) and a full navigation rather
150
- than a payload fetch. The build hands the client every route's pattern for
151
- that.
111
+ A `route.ts` is a `Route` as well, so `<Link href="/logout">`,
112
+ `visit('/agent-account')` and `redirect('/files/export.csv')` all typecheck.
152
113
 
153
- Every build also writes the `route.ts` files in their own narrower union,
154
- `ApiRoute`, so a `fetch` to an endpoint that no longer exists stops
155
- compiling:
114
+ For `fetch`, wrap the URL in `apiUrl`. It accepts only `route.ts` URLs, so a
115
+ fetch to an endpoint that no longer exists stops compiling:
156
116
 
157
117
  ```ts
158
118
  import { apiUrl } from '@rsc-kit/core/routes'
159
119
 
160
120
  await fetch(apiUrl(`/api/orders/${id}`))
161
121
  await fetch(apiUrl('/api/ordrs')) // does not compile
122
+ await fetch(apiUrl('/orders')) // does not compile: that's a page
162
123
  ```
163
124
 
164
125
  `apiUrl` returns what it was given. It exists because `fetch` takes any
165
- `string`, so without somewhere to put the type there is nothing to check
166
- against — the function is the place.
126
+ `string`, so without it there's nowhere to put the type. A page URL doesn't
127
+ compile, because fetching a page gets HTML where JSON was expected.
167
128
 
168
- `apiUrl('/orders')` does not compile, because fetching a page gets html where
169
- json was expected — the one mistake the narrower union is for.
129
+ This checks the URL, not what the endpoint returns. API routes are plain web
130
+ standards, with nothing of ours in them. For types end to end, a [server
131
+ action or query](/guides/queries/) is already typed across the boundary: the
132
+ return type is the function's.
170
133
 
171
- :::note[Paths, not response types]
172
- This checks the **url**. It does not infer what the endpoint returns — that
173
- would mean a typed `json()` helper of our own in place of `Response.json()`, and
174
- api routes are deliberately web standards with nothing of ours required in them.
175
-
176
- For end-to-end types without a fetch at all, a [server action or
177
- query](/guides/queries/) is already typed across the boundary: the return type
178
- is the function's, because it is the same function.
179
- :::
134
+ The browser treats a link to a `route.ts` as an ordinary anchor. It is never
135
+ prefetched, since a hover must not sign someone out, and clicking it is a full
136
+ navigation rather than a payload fetch.
180
137
 
181
138
  ## The backend's urls
182
139
 
183
140
  A prefix named in `backendPaths` is a `Route` too, so a link or a redirect to a
184
- url the backend owns compiles as written:
141
+ URL the backend owns compiles as written:
185
142
 
186
143
  ```tsx
187
144
  // vite.config.ts: rscKit({ backendPaths: ['/gitlab'] })
@@ -190,29 +147,74 @@ redirect('/gitlab/connect'); // ✅
190
147
  <Link href="/gitlabs">…</Link> // ❌ not the prefix
191
148
  ```
192
149
 
193
- A dynamic segment in one is any string there: `backendPaths: ['/login/[provider]']`
150
+ A dynamic segment in one matches any string. `backendPaths: ['/login/[provider]']`
194
151
  types `/login/google` and `/login/google/callback`, and leaves `/login` to the
195
152
  page.
196
153
 
197
- The prefix is a segment boundary, as it is for the server: `/gitlab`, anything
198
- under it, and a query or fragment, never `/gitlabs`. What is behind it is the
199
- backend's, so nothing past the prefix is checked. Like a `route.ts`, the browser
200
- loads it as a document and never prefetches it — see [leaving the
154
+ The prefix ends at a segment boundary, as it does on the server: `/gitlab`,
155
+ anything under it, and a query or fragment, never `/gitlabs`. Nothing past the
156
+ prefix is checked, because it's the backend's. Like a `route.ts`, the browser
157
+ loads it as a document and never prefetches it. See [leaving the
201
158
  app](/guides/redirects/#leaving-the-app).
202
159
 
203
- ## Regions
160
+ ## Refreshing a section by name
204
161
 
205
- `revalidate()` in an action and `refresh()` in the browser take a region by
206
- name, and the names are typed to the ones the build found: every
207
- `section('orders', …)` and every `@slot` directory, plus `'page'` and
208
- `'all'`. A typo, or a section renamed since, stops compiling instead of being
209
- refused by the renderer at runtime:
162
+ `revalidate()` in an action and `refresh()` in the browser take a region name.
163
+ The names are typed to the ones the build found: every `section('orders', …)`,
164
+ every `@slot` folder, `'page'` and `'all'`:
210
165
 
211
166
  ```ts
212
167
  revalidate('orders') // a section the build found
213
168
  revalidate('order') // does not compile
214
169
  ```
215
170
 
216
- A name computed at runtime is cast, as an href is: `revalidate(name as
217
- RevalidateTarget)`. A name that reaches the renderer unknown anyway is still
218
- refused with the names it does know.
171
+ A name computed at runtime is cast, as an href is:
172
+ `revalidate(name as RevalidateTarget)`. A name the renderer doesn't know is
173
+ still refused, with the names it does know.
174
+
175
+ ## Keeping the types current
176
+
177
+ The file is written whenever Vite starts: a build, or the dev server, which
178
+ also rewrites it when you add a route. A typecheck run without either, by an
179
+ agent or in CI, reads what the last start wrote. A link to a route added since
180
+ then fails with `"/admin"` is not assignable to type `Route`.
181
+
182
+ `rsc-kit-typegen` writes the file without starting Vite, from the app's own
183
+ `vite.config`. The scaffold's `typecheck` and `check` scripts run it first. In
184
+ an older project, add it the same way:
185
+
186
+ ```json title="package.json"
187
+ "typecheck": "rsc-kit-typegen && tsc --noEmit"
188
+ ```
189
+
190
+ ## The build checks
191
+
192
+ `vite build` runs the project's typecheck before it bundles, and stops on an
193
+ error. A link to a route that doesn't exist is a failed build. It's the same
194
+ `tsc --noEmit` the `check` script runs, on the same tsconfig, and it takes
195
+ about a second.
196
+
197
+ ```ts title="vite.config.ts"
198
+ rscKit({ typecheck: false }) // turn it off
199
+ ```
200
+
201
+ A project with no `tsconfig.json`, or without `typescript` installed, is
202
+ skipped.
203
+
204
+ ## Limits
205
+
206
+ - **A dynamic segment widens.** `/posts/[slug]` becomes `` `/posts/${string}` ``,
207
+ so `/posts/a/b` type-checks even though it doesn't match at runtime.
208
+ - **Without the generated file, nothing is checked.** If
209
+ `.rsc-kit/rsc-routes.d.ts` is missing, or your tsconfig's `include` doesn't
210
+ cover `.rsc-kit`, every URL prop accepts any `string` and nothing breaks.
211
+ There's no flag to turn the check on; the file is the switch.
212
+
213
+ ## How it works
214
+
215
+ The build writes one line per route into `rsc-routes.d.ts`. For a page with a
216
+ `searchParams` export, that line reads the export's type from the page module.
217
+ Nothing runs, and a page without the export costs nothing. The build also
218
+ writes the `route.ts` files into their own narrower union, `ApiRoute`, which is
219
+ what `apiUrl` takes, and hands the client every route's pattern so it knows
220
+ which links to treat as documents.