You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: overhaul TanStack Start guide for Vite default and Rsbuild
Rewrite the framework guide in the-voice register: Turbo lead, Vite as
the default CLI path, Rsbuild Callout with manual install, Callouts
instead of ::: directives, schema as its own H2, and named
arkenvRsbuildPlugin import. Mention both plugins on the frameworks index card.
Copy file name to clipboardExpand all lines: apps/www/content/docs/frameworks/index.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Choose your framework to get started:
17
17
18
18
<Cardhref="/docs/frameworks/vite"title="Vite"description="@arkenv/vite-plugin transform mode and VITE_ keys." />
19
19
20
-
<Cardhref="/docs/frameworks/tanstack-start"title="TanStack Start"description="@arkenv/vite-plugin with tanstackStart() and createServerFn." />
20
+
<Cardhref="/docs/frameworks/tanstack-start"title="TanStack Start"description="@arkenv/vite-plugin / @arkenv/rsbuild-plugin with tanstackStart() and createServerFn." />
21
21
22
22
<Cardhref="/docs/frameworks/bun"title="Bun fullstack dev server"description="@arkenv/bun-plugin for Bun bundler and fullstack apps." />
By default, the add-on scaffolds with **ArkType** (`@arkenv/core`) and includes the interactive demo route at `/demo/arkenv`.
35
-
36
-
Configuration options supported by the add-on:
37
-
38
-
-**Validator Engine**:
39
-
-**ArkType** (default) — installs `@arkenv/core` and `arktype`
40
-
-**Zod** — installs `@arkenv/standard` and `zod`
41
-
-**Valibot** — installs `@arkenv/standard` and `valibot`
42
-
-**Interactive Demo Route**:
43
-
-**Include `/demo/arkenv`** (default) — scaffolds an interactive secret leak test showcasing server-only isolation in the browser
44
-
-**Skip demo route** — scaffolds only the schema definition and plugin configuration (automatically skipped when creating a project with `--no-examples` or the `blank` preset)
27
+
The add-on installs the validator runtime, registers
28
+
`arkenvVitePlugin()` in `vite.config.ts`, writes `src/env.ts`, and
29
+
pre-populates declared keys in `.env.example`.
45
30
46
-
The add-on automatically:
31
+
### Existing projects
47
32
48
-
- Installs the required validator runtime and dev dependencies
49
-
- Configures `arkenvVitePlugin()` in `vite.config.ts`
50
-
- Generates `src/env.ts` with your selected validator engine
51
-
- Pre-populates declared keys in `.env.example`
33
+
If you already have a TanStack Start app on Vite, add ArkEnv with either
34
+
the TanStack CLI add-on or the ArkEnv CLI:
52
35
53
-
<Callouttype="info"title="Adding to an existing TanStack project">
54
-
If you already have a TanStack application, add ArkEnv directly with the TanStack CLI:
@@ -149,20 +130,22 @@ Install `@vitejs/plugin-react` if it is not already a dependency. If you
149
130
aren't using ArkType, import the ArkEnv plugin from
150
131
`@arkenv/vite-plugin/standard`.
151
132
152
-
:::warning[React Refresh plugin required for client hydration]
153
-
TanStack Start React dev mode requires the React Refresh runtime (`/@react-refresh`). You must include `@vitejs/plugin-react` (or `@vitejs/plugin-react-swc`) in your Vite `plugins` array and place it **after**`tanstackStart()`.
154
-
155
-
If the React plugin is missing, Vite fails to load the client entry (`/@react-refresh could not be resolved`). The page will still render via SSR, but client-side hydration fails, leaving interactive handlers (like `onClick` listeners) unattached.
156
-
:::
133
+
<Callouttype="warn"title="React Refresh after tanstackStart()">
134
+
Place `@vitejs/plugin-react` (or `@vitejs/plugin-react-swc`) **after**
135
+
`tanstackStart()`. Without it, Vite cannot resolve `/@react-refresh`,
136
+
SSR still renders, and client hydration fails so handlers never attach.
137
+
</Callout>
157
138
158
139
### Rsbuild
159
140
160
-
TanStack Start also supports [Rsbuild](https://rsbuild.dev) via `@tanstack/react-start/plugin/rsbuild`. Register `arkenvRsbuildPlugin()` in your `rsbuild.config.ts`:
141
+
TanStack Start also supports [Rsbuild](https://rsbuild.dev) via
142
+
`@tanstack/react-start/plugin/rsbuild`. Register
143
+
`arkenvRsbuildPlugin()` in your `rsbuild.config.ts`:
@@ -211,22 +202,22 @@ Everything else stays on the server:
211
202
</Tab>
212
203
</Tabs>
213
204
214
-
:::tip[Pass the schema as an object literal]
215
-
Pass the object literal into `arkenv({ ... })`, or wrap a shared shape with
216
-
`type(...)` from `@arkenv/core`. An untyped intermediate object can break
217
-
overload inference.
218
-
:::
205
+
<Callouttype="info"title="Pass the schema as an object literal">
206
+
Pass the object literal into `arkenv({ ... })`, or wrap a shared shape
207
+
with `type(...)` from `@arkenv/core`. An untyped intermediate object
208
+
can break overload inference.
209
+
</Callout>
219
210
220
211
## Server functions and client access
221
212
222
-
Read the validated `env` object from your schema module in routes and server
223
-
functions.
213
+
Read the validated `env` object from your schema module in routes and
214
+
server functions.
224
215
225
216
### Server keys in createServerFn
226
217
227
-
Server-only keys work inside `createServerFn` handlers. The handler runs on the
228
-
server, where `env.ts` executes the real validation runtime against your
229
-
process environment:
218
+
Server-only keys work inside `createServerFn` handlers. The handler runs
219
+
on the server, where `env.ts` executes the real validation runtime
220
+
against your process environment:
230
221
231
222
<Tabsitems={["Vite", "Rsbuild"]}>
232
223
<Tabvalue="Vite">
@@ -290,14 +281,15 @@ process environment:
290
281
291
282
### Client keys in components
292
283
293
-
Client components read public keys (`VITE_*` on Vite, `PUBLIC_*` on Rsbuild)
294
-
from the same import. The plugin rewrites the client module so these values
295
-
are inlined as coerced literals.
284
+
Client components read public keys (`VITE_*` on Vite, `PUBLIC_*` on
285
+
Rsbuild) from the same import. The plugin rewrites the client module so
286
+
these values are inlined as coerced literals.
296
287
297
-
:::warning[Do not read `import.meta.env` directly]
298
-
Reading `import.meta.env` skips ArkEnv. Import `{ env }` so public keys stay
299
-
typed and coerced and server secrets stay out of the client bundle.
300
-
:::
288
+
<Callouttype="warn"title="Do not read `import.meta.env` directly">
289
+
Reading `import.meta.env` skips ArkEnv. Import `{ env }` so public keys
290
+
stay typed and coerced and server secrets stay out of the client
291
+
bundle.
292
+
</Callout>
301
293
302
294
Reading a server-only key in the browser throws instead of leaking:
303
295
@@ -320,29 +312,34 @@ Reading a server-only key in the browser throws instead of leaking:
320
312
## SSR and the client boundary
321
313
322
314
TanStack Start builds two module graphs: the SSR graph for the server
323
-
functions and routes you render on the server, and the client graph for what
324
-
ships to the browser.
325
-
326
-
-**Server graph:**`env.ts` executes the real `@arkenv/core` runtime at boot
327
-
and validates your process environment before requests are served. `createServerFn`
328
-
handlers run on this graph, so they read real, validated values.
329
-
-**Client graph:**`@arkenv/vite-plugin` or `@arkenv/rsbuild-plugin` transforms `env.ts` during the client
330
-
build. It inlines public values and replaces private server keys with
331
-
throwing getters, so the validator engine never ships to the browser.
332
-
333
-
Like Vite and Rsbuild, TanStack Start loads `.env*` files in development. In production, the
334
-
environment comes from the process that starts your server, so containers must
335
-
inject variables before boot.
315
+
functions and routes you render on the server, and the client graph for
316
+
what ships to the browser.
317
+
318
+
-**Server graph:**`env.ts` executes the real `@arkenv/core` runtime at
319
+
boot and validates your process environment before requests are
320
+
served. `createServerFn` handlers run on this graph, so they read
321
+
real, validated values.
322
+
-**Client graph:**`@arkenv/vite-plugin` or `@arkenv/rsbuild-plugin`
323
+
transforms `env.ts` during the client build. It inlines public values
324
+
and replaces private server keys with throwing getters, so the
325
+
validator engine never ships to the browser.
326
+
327
+
Like Vite and Rsbuild, TanStack Start loads `.env*` files in
328
+
development. In production, the environment comes from the process that
329
+
starts your server, so containers must inject variables before boot.
336
330
337
331
## Examples
338
332
339
333
Run a complete setup end to end:
340
334
341
-
-[`with-tanstack-start`](https://github.com/yamcodes/arkenv/tree/v1/examples/with-tanstack-start): TanStack Start with Vite and `@arkenv/vite-plugin`.
342
-
-[`with-tanstack-start-rsbuild`](https://github.com/yamcodes/arkenv/tree/v1/examples/with-tanstack-start-rsbuild): TanStack Start with Rsbuild and `@arkenv/rsbuild-plugin`.
0 commit comments