Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 74 additions & 7 deletions docs/start/framework/react/hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ npm run start
Make sure that your `react` and `react-dom` packages are set to version 19.0.0 or higher in your `package.json` file. If not, run the following command to upgrade the packages:

```sh
npm install react@rc react-dom@rc
bun install react@19 react-dom@19
```

Ensure your `vite.config.ts` file is correct.
Ensure your `vite.config.ts` file is correct:

```ts
// vite.config.ts
Expand All @@ -230,14 +230,81 @@ export default defineConfig({
})
```

Then you can run the following command to build and start your application:
#### Production Server with Bun

To run TanStack Start applications in production with Bun, you need a custom server implementation.

We've created an optimized production server that provides intelligent static asset loading with configurable memory management.

**Features:**

- **Hybrid loading strategy**: Small files (<5MB by default) are preloaded into memory, large files are served on-demand
- **Configurable file filtering**: Use include/exclude patterns to control which files are preloaded
- **Production-ready caching headers**: Automatic optimization for static assets
- **Memory-efficient**: Smart memory management prevents excessive RAM usage

**Quick Setup:**

1. Copy the [`server.ts`](../../../../examples/react/start-bun/server.ts) file from the example in this repository to your project root

2. Build your application:
Comment on lines +248 to +250
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid linking to repo files via deep relative paths; use a stable GitHub URL

Deep relative paths outside docs/ often break on the docs site build. Link to the example file on GitHub.

Apply:

-1. Copy the [`server.ts`](../../../../examples/react/start-bun/server.ts) file from the example in this repository to your project root
+1. Copy the `server.ts` file from the example in this repository to your project root:
+   https://github.com/TanStack/router/blob/main/examples/react/start-bun/server.ts

As per coding guidelines

🤖 Prompt for AI Agents
In docs/start/framework/react/hosting.md around lines 248 to 250, replace the
deep relative link to ../../../../examples/react/start-bun/server.ts with a
stable GitHub URL to the example file (use the repository's canonical branch,
e.g.
https://github.com/<org>/<repo>/blob/main/examples/react/start-bun/server.ts or
the raw URL if appropriate for embedding); update the text so it references that
absolute GitHub link and verify the link points to the correct branch and path
so docs builds won't break due to relative path traversal outside docs/.


```sh
bun run build
```

3. Start the server:

```sh
bun run server.ts
```

**Configuration:**

The server can be configured using environment variables:

```sh
bun run build
# Basic usage
bun run server.ts

# Custom port
PORT=8080 bun run server.ts

# Optimize for minimal memory usage (1MB preload limit)
STATIC_PRELOAD_MAX_BYTES=1048576 bun run server.ts

# Preload only critical assets
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
bun run server.ts

# Debug mode with verbose logging
STATIC_PRELOAD_VERBOSE=true bun run server.ts
```

You're now ready to deploy your application to a Bun server. You can start your application by running:
**Environment Variables:**

```sh
bun run .output/server/index.mjs
- `PORT`: Server port (default: 3000)
- `STATIC_PRELOAD_MAX_BYTES`: Maximum file size to preload in bytes (default: 5242880 = 5MB)
- `STATIC_PRELOAD_INCLUDE`: Comma-separated glob patterns for files to include
- `STATIC_PRELOAD_EXCLUDE`: Comma-separated glob patterns for files to exclude
- `STATIC_PRELOAD_VERBOSE`: Enable detailed logging (set to "true")

**Example Output:**

```txt
📦 Loading static assets from ./dist/client...
Max preload size: 5.00 MB

📁 Preloaded into memory:
/assets/index-a1b2c3d4.js 45.23 kB │ gzip: 15.83 kB
/assets/index-e5f6g7h8.css 12.45 kB │ gzip: 4.36 kB

💾 Served on-demand:
/assets/vendor-i9j0k1l2.js 245.67 kB │ gzip: 86.98 kB

✅ Preloaded 2 files (57.68 KB) into memory
🚀 Server running at http://localhost:3000
```

For a complete working example, check out the [TanStack Start + Bun example](../../../../examples/react/start-bun) in this repository.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/basic-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"combinate": "^1.1.11",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/basic-react-query-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/basic-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/basic-scroll-restoration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/basic-virtual-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/generator-cli-only/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/js-only-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-router/sentry-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/react-start/basic-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1"
"vite": "^7.1.7"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/basic-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"postcss": "^8.5.1",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4",
"wrangler": "^4.40.2"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/basic-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1"
"vite": "^7.1.7"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/basic-rsc/package.disabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1"
"vite": "^7.1.7"
},
"devDependencies": {
"@types/react": "^19.0.8",
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/basic-tsr-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@tanstack/react-start": "workspace:^",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vite": "^7.1.1"
"vite": "^7.1.7"
},
"devDependencies": {
"@tanstack/router-e2e-utils": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"srvx": "^0.8.6",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4",
"zod": "^3.24.2"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/clerk-basic/package.disabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1"
"vite": "^7.1.7"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/custom-basepath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"tailwindcss": "^3.4.17",
"tsx": "^4.20.3",
"typescript": "^5.7.2",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4"
}
}
2 changes: 1 addition & 1 deletion e2e/react-start/scroll-restoration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1",
"vite": "^7.1.7",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/selective-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@tanstack/react-start": "workspace:^",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4",
"zod": "^3.24.2"
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/serialization-adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@tanstack/react-start": "workspace:^",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4",
"zod": "^3.24.2"
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/server-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1",
"vite": "^7.1.7",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/server-routes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1",
"vite": "^7.1.7",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/spa-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"postcss": "^8.5.1",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4"
}
}
2 changes: 1 addition & 1 deletion e2e/react-start/virtual-routes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.1",
"vite": "^7.1.7",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-start/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"srvx": "^0.8.6",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"vite": "^7.1.1",
"vite": "^7.1.7",
"vite-plugin-solid": "^2.11.8"
}
}
2 changes: 1 addition & 1 deletion e2e/solid-router/basic-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@tanstack/router-e2e-utils": "workspace:^",
"vite-plugin-solid": "^2.11.8",
"combinate": "^1.1.11",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"vite-plugin-solid": "^2.11.8",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/solid-router/basic-solid-query-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"vite-plugin-solid": "^2.11.8",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/solid-router/basic-solid-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"vite-plugin-solid": "^2.11.8",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
2 changes: 1 addition & 1 deletion e2e/solid-router/basic-virtual-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"vite-plugin-solid": "^2.11.8",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"vite-plugin-solid": "^2.11.8",
"vite": "^7.1.1"
"vite": "^7.1.7"
}
}
Loading
Loading