Skip to content

Commit b73f4a7

Browse files
authored
Merge branch 'main' into fix-route-matching
2 parents ac8366e + 5404201 commit b73f4a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2806
-2
lines changed

docs/router/config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@
577577
"label": "View Transitions",
578578
"to": "framework/react/examples/view-transitions"
579579
},
580+
{
581+
"label": "Framer Motion",
582+
"to": "framework/react/examples/with-framer-motion"
583+
},
580584
{
581585
"label": "With tRPC",
582586
"to": "framework/react/examples/with-trpc"
@@ -629,6 +633,14 @@
629633
{
630634
"label": "Kitchen Sink + Solid Query (code-based)",
631635
"to": "framework/solid/examples/kitchen-sink-solid-query"
636+
},
637+
{
638+
"label": "View Transitions",
639+
"to": "framework/solid/examples/view-transitions"
640+
},
641+
{
642+
"label": "Framer Motion",
643+
"to": "framework/solid/examples/with-framer-motion"
632644
}
633645
]
634646
}

docs/start/framework/solid/guide/hosting.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,108 @@ export default defineConfig({
289289
})
290290
```
291291

292+
#### Production Server with Bun
293+
294+
Alternatively, you can use a custom server implementation that leverages Bun's native APIs.
295+
296+
We provide a reference implementation that demonstrates one approach to building a production-ready Bun server. This example uses Bun-native functions for optimal performance and includes features like intelligent asset preloading and memory management.
297+
298+
**This is a starting point - feel free to adapt it to your needs or simplify it for your use case.**
299+
300+
**What this example demonstrates:**
301+
302+
- Serving static assets using Bun's native file handling
303+
- Hybrid loading strategy (preload small files, serve large files on-demand)
304+
- Optional features like ETag support and Gzip compression
305+
- Production-ready caching headers
306+
307+
**Quick Setup:**
308+
309+
1. Copy the [`server.ts`](https://github.com/tanstack/router/blob/main/examples/react/start-bun/server.ts) file from the example repository to your project root (or use it as inspiration for your own implementation)
310+
311+
2. Build your application:
312+
313+
```sh
314+
bun run build
315+
```
316+
317+
3. Start the server:
318+
319+
```sh
320+
bun run server.ts
321+
```
322+
323+
**Configuration (Optional):**
324+
325+
The reference server implementation includes several optional configuration options via environment variables. You can use these as-is, modify them, or remove features you don't need:
326+
327+
```sh
328+
# Basic usage - just works out of the box
329+
bun run server.ts
330+
331+
# Common configurations
332+
PORT=8080 bun run server.ts # Custom port
333+
ASSET_PRELOAD_VERBOSE_LOGGING=true bun run server.ts # See what's happening
334+
```
335+
336+
**Available Environment Variables:**
337+
338+
| Variable | Description | Default |
339+
| -------------------------------- | -------------------------------------------------- | ----------------------------------------------------------------------------- |
340+
| `PORT` | Server port | `3000` |
341+
| `ASSET_PRELOAD_MAX_SIZE` | Maximum file size to preload into memory (bytes) | `5242880` (5MB) |
342+
| `ASSET_PRELOAD_INCLUDE_PATTERNS` | Comma-separated glob patterns for files to include | All files |
343+
| `ASSET_PRELOAD_EXCLUDE_PATTERNS` | Comma-separated glob patterns for files to exclude | None |
344+
| `ASSET_PRELOAD_VERBOSE_LOGGING` | Enable detailed logging | `false` |
345+
| `ASSET_PRELOAD_ENABLE_ETAG` | Enable ETag generation | `true` |
346+
| `ASSET_PRELOAD_ENABLE_GZIP` | Enable Gzip compression | `true` |
347+
| `ASSET_PRELOAD_GZIP_MIN_SIZE` | Minimum file size for Gzip (bytes) | `1024` (1KB) |
348+
| `ASSET_PRELOAD_GZIP_MIME_TYPES` | MIME types eligible for Gzip | `text/,application/javascript,application/json,application/xml,image/svg+xml` |
349+
350+
<details>
351+
<summary>Advanced configuration examples</summary>
352+
353+
```sh
354+
# Optimize for minimal memory usage
355+
ASSET_PRELOAD_MAX_SIZE=1048576 bun run server.ts
356+
357+
# Preload only critical assets
358+
ASSET_PRELOAD_INCLUDE_PATTERNS="*.js,*.css" \
359+
ASSET_PRELOAD_EXCLUDE_PATTERNS="*.map,vendor-*" \
360+
bun run server.ts
361+
362+
# Disable optional features
363+
ASSET_PRELOAD_ENABLE_ETAG=false \
364+
ASSET_PRELOAD_ENABLE_GZIP=false \
365+
bun run server.ts
366+
367+
# Custom Gzip configuration
368+
ASSET_PRELOAD_GZIP_MIN_SIZE=2048 \
369+
ASSET_PRELOAD_GZIP_MIME_TYPES="text/,application/javascript,application/json" \
370+
bun run server.ts
371+
```
372+
373+
</details>
374+
375+
**Example Output:**
376+
377+
```txt
378+
📦 Loading static assets from ./dist/client...
379+
Max preload size: 5.00 MB
380+
381+
📁 Preloaded into memory:
382+
/assets/index-a1b2c3d4.js 45.23 kB │ gzip: 15.83 kB
383+
/assets/index-e5f6g7h8.css 12.45 kB │ gzip: 4.36 kB
384+
385+
💾 Served on-demand:
386+
/assets/vendor-i9j0k1l2.js 245.67 kB │ gzip: 86.98 kB
387+
388+
✅ Preloaded 2 files (57.68 KB) into memory
389+
🚀 Server running at http://localhost:3000
390+
```
391+
392+
For a complete working example, check out the [TanStack Start + Bun example](https://github.com/TanStack/router/tree/main/examples/react/start-bun) in this repository.
393+
292394
### Appwrite Sites
293395

294396
When deploying to [Appwrite Sites](https://appwrite.io/products/sites), you'll need to complete a few steps:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local
6+
count.txt
7+
.env
8+
.nitro
9+
.tanstack
10+
.output
11+
.vinxi
12+
todos.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package-lock.json
2+
pnpm-lock.yaml
3+
yarn.lock
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"files.watcherExclude": {
3+
"**/routeTree.gen.ts": true
4+
},
5+
"search.exclude": {
6+
"**/routeTree.gen.ts": true
7+
},
8+
"files.readonlyInclude": {
9+
"**/routeTree.gen.ts": true
10+
}
11+
}

examples/solid/start-bun/README.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# TanStack Start + Bun Production Server
2+
3+
An optimized production server for TanStack Start applications using Bun, implementing intelligent static asset loading with configurable memory management.
4+
5+
## 🚀 Features
6+
7+
- **Hybrid Loading Strategy**: Small files are preloaded into memory, large files are served on-demand
8+
- **Configurable File Filtering**: Include/Exclude patterns for precise control
9+
- **Memory-efficient Response Generation**: Optimized for high performance
10+
- **Production-ready Caching Headers**: Automatic Cache-Control headers for optimal performance
11+
- **Detailed Logging**: Vite-like output for better overview
12+
13+
## 📦 Installation
14+
15+
This project was created with TanStack Start:
16+
17+
```bash
18+
bunx create-start-app@latest
19+
```
20+
21+
Install dependencies:
22+
23+
```bash
24+
bun install
25+
```
26+
27+
## 🏃‍♂️ Development
28+
29+
For development:
30+
31+
```bash
32+
bun run dev
33+
```
34+
35+
## 🔨 Production Build
36+
37+
Build the application for production:
38+
39+
```bash
40+
bun run build
41+
```
42+
43+
## 🚀 Production Server with server.ts
44+
45+
### Quick Start - Use in Your Project
46+
47+
You can easily use this production server in your own TanStack Start project:
48+
49+
1. **Copy the `server.ts` file** into your project root
50+
2. **Build your project** with `bun run build`
51+
3. **Start the server** directly with:
52+
```bash
53+
bun run server.ts
54+
```
55+
56+
Or add it to your `package.json` scripts:
57+
58+
```json
59+
{
60+
"scripts": {
61+
"start": "bun run server.ts"
62+
}
63+
}
64+
```
65+
66+
Then run with:
67+
68+
```bash
69+
bun run start
70+
```
71+
72+
### Server Features
73+
74+
The `server.ts` implements a high-performance production server with the following features:
75+
76+
#### 1. Intelligent Asset Loading
77+
78+
The server automatically decides which files to preload into memory and which to serve on-demand:
79+
80+
- **In-Memory Loading**: Small files (default < 5MB) are loaded into memory at startup
81+
- **On-Demand Loading**: Large files are loaded from disk only when requested
82+
- **Optimized Performance**: Frequently used assets are served from memory
83+
84+
#### 2. Configuration via Environment Variables
85+
86+
```bash
87+
# Server Port (default: 3000)
88+
PORT=3000
89+
90+
# Maximum file size for in-memory loading (in bytes, default: 5MB)
91+
STATIC_PRELOAD_MAX_BYTES=5242880
92+
93+
# Include patterns (comma-separated, only these files will be preloaded)
94+
STATIC_PRELOAD_INCLUDE="*.js,*.css,*.woff2"
95+
96+
# Exclude patterns (comma-separated, these files will be excluded)
97+
STATIC_PRELOAD_EXCLUDE="*.map,*.txt"
98+
99+
# Enable detailed logging
100+
STATIC_PRELOAD_VERBOSE=true
101+
```
102+
103+
### Example Configurations
104+
105+
#### Minimal Memory Footprint
106+
107+
```bash
108+
# Preload only critical assets
109+
STATIC_PRELOAD_MAX_BYTES=1048576 \
110+
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
111+
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
112+
bun run start
113+
```
114+
115+
#### Maximum Performance
116+
117+
```bash
118+
# Preload all small assets
119+
STATIC_PRELOAD_MAX_BYTES=10485760 \
120+
bun run start
121+
```
122+
123+
#### Debug Mode
124+
125+
```bash
126+
# With detailed logging
127+
STATIC_PRELOAD_VERBOSE=true \
128+
bun run start
129+
```
130+
131+
### Server Output
132+
133+
The server displays a clear overview of all loaded assets at startup:
134+
135+
```txt
136+
📦 Loading static assets from ./dist/client...
137+
Max preload size: 5.00 MB
138+
Include patterns: *.js,*.css,*.woff2
139+
140+
📁 Preloaded into memory:
141+
/assets/index-a1b2c3d4.js 45.23 kB │ gzip: 15.83 kB
142+
/assets/index-e5f6g7h8.css 12.45 kB │ gzip: 4.36 kB
143+
144+
💾 Served on-demand:
145+
/assets/vendor-i9j0k1l2.js 245.67 kB │ gzip: 86.98 kB
146+
147+
✅ Preloaded 2 files (57.68 KB) into memory
148+
ℹ️ 1 files will be served on-demand (1 too large, 0 filtered)
149+
150+
🚀 Server running at http://localhost:3000
151+
```
152+
153+
## Testing
154+
155+
This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
156+
157+
```bash
158+
bun run test
159+
```
160+
161+
## Styling
162+
163+
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
164+
165+
## Linting & Formatting
166+
167+
This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.io/) for linting and formatting. Eslint is configured using [tanstack/eslint-config](https://tanstack.com/config/latest/docs/eslint). The following scripts are available:
168+
169+
```bash
170+
bun run lint
171+
bun run format
172+
bun run check
173+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-check
2+
3+
import { tanstackConfig } from '@tanstack/eslint-config'
4+
5+
export default [...tanstackConfig]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "tanstack-solid-start-bun-hosting",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite dev --port 3000",
7+
"start": "bun run server.ts",
8+
"build": "vite build",
9+
"serve": "vite preview",
10+
"test": "vitest run",
11+
"lint": "eslint",
12+
"format": "prettier",
13+
"check": "prettier --write . && eslint --fix"
14+
},
15+
"dependencies": {
16+
"@tailwindcss/vite": "^4.1.13",
17+
"@tanstack/solid-devtools": "^0.7.0",
18+
"@tanstack/solid-router": "^1.135.2",
19+
"@tanstack/solid-router-devtools": "^1.135.2",
20+
"@tanstack/solid-router-ssr-query": "^1.135.2",
21+
"@tanstack/solid-start": "^1.135.2",
22+
"@tanstack/router-plugin": "^1.135.2",
23+
"solid-js": "^1.9.10",
24+
"tailwindcss": "^4.1.13",
25+
"vite-tsconfig-paths": "^5.1.4"
26+
},
27+
"devDependencies": {
28+
"@tanstack/eslint-config": "^0.3.2",
29+
"@testing-library/dom": "^10.4.1",
30+
"@solidjs/testing-library": "^0.8.10",
31+
"@types/bun": "^1.2.22",
32+
"@types/node": "22.10.2",
33+
"vite-plugin-solid": "^2.11.10",
34+
"jsdom": "^27.0.0",
35+
"prettier": "^3.6.2",
36+
"typescript": "^5.9.2",
37+
"vite": "^7.1.7",
38+
"vitest": "^3.2.4",
39+
"web-vitals": "^5.1.0"
40+
}
41+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
3+
/** @type {import('prettier').Config} */
4+
const config = {
5+
semi: false,
6+
singleQuote: true,
7+
trailingComma: 'all',
8+
}
9+
10+
export default config
3.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)