Skip to content

Commit 6875aa1

Browse files
authored
[Workers] Add prerendering guide to Tanstack start docs (#27062)
1 parent 06f22c1 commit 6875aa1

File tree

2 files changed

+94
-22
lines changed

2 files changed

+94
-22
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Static prerendering support for TanStack Start
3+
description: TanStack Start apps can now prerender routes to static HTML at build time using the Cloudflare Vite plugin.
4+
products:
5+
- workers
6+
date: 2025-12-19
7+
---
8+
9+
[TanStack Start](https://tanstack.com/start/) apps can now prerender routes to static HTML at build time with access to build time environment variables
10+
and bindings, and serve them as [static assets](/workers/static-assets/). To enable prerendering, configure the `prerender` option of the TanStack Start plugin in your Vite config:
11+
12+
```ts title="vite.config.ts"
13+
import { defineConfig } from "vite";
14+
import { cloudflare } from "@cloudflare/vite-plugin";
15+
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
16+
17+
export default defineConfig({
18+
plugins: [
19+
cloudflare({ viteEnvironment: { name: "ssr" } }),
20+
tanstackStart({
21+
prerender: {
22+
enabled: true,
23+
},
24+
}),
25+
],
26+
});
27+
```
28+
29+
This feature requires `@tanstack/react-start` v1.138.0 or later. See the [TanStack Start framework guide](/workers/framework-guides/web-apps/tanstack-start/#static-prerendering) for more details.

src/content/docs/workers/framework-guides/web-apps/tanstack-start.mdx

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,21 @@ import {
2020

2121
[TanStack Start](https://tanstack.com/start) is a full-stack framework for building web applications. It comes with features like server-side rendering, streaming, server functions, bundling, and more. In this guide, you learn to deploy a TanStack Start application to Cloudflare Workers.
2222

23-
## 1. Set up a TanStack Start project
23+
## Creating a new TanStack Start application
2424

25-
If you have an existing TanStack Start application, skip to the [Configuring an existing TanStack Start application](#configuring-an-existing-tanstack-start-application) section.
26-
27-
### Creating a new TanStack Start application
28-
29-
Use the [`create-cloudflare`](https://www.npmjs.com/package/create-cloudflare) CLI (C3) to set up a new project. C3 will create a new project directory, initiate TanStack Start's official setup tool, and provide the option to deploy instantly.
30-
31-
To use `create-cloudflare` to create a new TanStack Start project with Workers Assets, run the following command:
25+
To create a TanStack Start application, run the following command:
3226

3327
<PackageManagers
3428
type="create"
3529
pkg="cloudflare@latest"
3630
args="my-tanstack-start-app --framework=tanstack-start"
3731
/>
3832

39-
After setting up your project, change your directory by running the following command:
33+
After you have created your project, run the following command in the project directory to start a local development server. This will allow you to preview your project locally during development.
4034

41-
```sh
42-
cd my-tanstack-start-app
43-
```
35+
<PackageManagers type="run" args="dev" />
4436

45-
### Configuring an existing TanStack Start application
37+
## Configuring an existing TanStack Start application
4638

4739
If you have an existing TanStack Start application, you can configure it to run on Cloudflare Workers by following these steps:
4840

@@ -93,13 +85,7 @@ If you have an existing TanStack Start application, you can configure it to run
9385

9486
</Steps>
9587

96-
## 2. Develop locally
97-
98-
After you have created your project, run the following command in the project directory to start a local development server. This will allow you to preview your project locally during development.
99-
100-
<PackageManagers type="run" args="dev" />
101-
102-
## 3. Deploy your Project
88+
## Deploy your Project
10389

10490
You can deploy your project to a `*.workers.dev` subdomain or a [Custom Domain](/workers/configuration/routing/custom-domains/) from your own machine or from any CI/CD system, including Cloudflare's own [Workers Builds](/workers/ci-cd/builds/).
10591

@@ -116,8 +102,6 @@ This can help you making sure that your application will work as intended once i
116102

117103
:::
118104

119-
---
120-
121105
## Bindings
122106

123107
Your TanStack Start application can be fully integrated with the Cloudflare Developer Platform, in both local development and in production, by using bindings.
@@ -157,3 +141,62 @@ Will populate the `env` object with the various bindings based on your configura
157141
:::
158142

159143
<Render file="frameworks-bindings" product="workers" />
144+
145+
## Static Prerendering
146+
147+
You can prerender your application to static HTML files at build time with TanStack Start and serve them as [static assets](/workers/static-assets/).
148+
149+
```ts title="vite.config.ts"
150+
import { defineConfig } from "vite";
151+
import { cloudflare } from "@cloudflare/vite-plugin";
152+
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
153+
154+
export default defineConfig({
155+
plugins: [
156+
cloudflare({ viteEnvironment: { name: "ssr" } }),
157+
tanstackStart({
158+
prerender: {
159+
// Enable static prerendering
160+
enabled: true,
161+
// other prerender options...
162+
},
163+
}),
164+
],
165+
})
166+
```
167+
168+
No additional configuration is needed in your wrangler config file. For more prerender options, see the [TanStack Start documentation](https://tanstack.com/start/latest/docs/framework/react/guide/static-prerendering).
169+
170+
:::note
171+
172+
Requires `@tanstack/react-start` v1.138.0 or later.
173+
174+
:::
175+
176+
:::caution
177+
178+
Prerendering runs during the build step and uses your local environment variables, secrets, and bindings storage data. Ensure your build environment is configured correctly, and use [remote bindings](/workers/development-testing/#remote-bindings) to prerender with production data.
179+
180+
:::
181+
182+
### Prerendering in CI environments
183+
184+
When prerendering in CI, your Worker code may need access to environment variables or secrets that are not available in the build environment. One way to handle this is to include a `.env` file with variable references, which resolve to values provided by your CI environment:
185+
186+
```sh title=".env"
187+
API_KEY=${API_KEY}
188+
DATABASE_URL=${DATABASE_URL}
189+
```
190+
191+
In your CI environment, set `CLOUDFLARE_INCLUDE_PROCESS_ENV=true` and provide the required values as environment variables. If using [Workers Builds](/workers/ci-cd/builds/), update your [build settings](/workers/ci-cd/builds/configuration/#build-settings) accordingly.
192+
193+
:::note
194+
195+
For local development, create a `.env.local` file with actual secret values. Do not commit this file to your repository. Values in `.env.local` override the references in `.env`:
196+
197+
```sh title=".env.local"
198+
API_KEY=my-local-dev-key
199+
DATABASE_URL=postgres://localhost/mydb
200+
```
201+
202+
:::

0 commit comments

Comments
 (0)