Skip to content

Commit 74b41fd

Browse files
authored
Merge branch 'main' into rob/clerk-server-handler-update
2 parents cd616c2 + 6202162 commit 74b41fd

File tree

172 files changed

+3785
-527
lines changed

Some content is hidden

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

172 files changed

+3785
-527
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Enjoy this library? Try the entire [TanStack](https://tanstack.com)! [TanStack Q
4242
<div><a href="https://neon.tech?utm_source=tanstack">
4343
<img alt="Neon" src="https://raw.githubusercontent.com/tannerlinsley/files/master/partners/neon.svg" height="40"
4444
</a></div><br />
45+
<div><a href="https://www.prisma.io?utm_source=tanstack&via=tanstack">
46+
<img alt="Prisma" src="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-light.svg" height="40">
47+
</a></div><br />
4548
<div><a href="https://convex.dev?utm_source=tanstack">
4649
<img alt="Convex" src="https://raw.githubusercontent.com/tannerlinsley/files/master/partners/convex.svg" height="40"
4750
</a></div><br />

docs/router/framework/react/guide/navigation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,13 @@ With preloading enabled and relatively quick asynchronous route dependencies (if
667667

668668
What's even better is that by using a cache-first library like `@tanstack/query`, preloaded routes will stick around and be ready for a stale-while-revalidate experience if the user decides to navigate to the route later on.
669669

670-
### Link Preloading Timeout
670+
### Link Preloading Delay
671671

672-
Along with preloading is a configurable timeout which determines how long a user must hover over a link to trigger the intent-based preloading. The default timeout is 50 milliseconds, but you can change this by passing a `preloadTimeout` prop to the `Link` component with the number of milliseconds you'd like to wait:
672+
Along with preloading is a configurable delay which determines how long a user must hover over a link to trigger the intent-based preloading. The default delay is 50 milliseconds, but you can change this by passing a `preloadDelay` prop to the `Link` component with the number of milliseconds you'd like to wait:
673673

674674
```tsx
675675
const link = (
676-
<Link to="/blog/post/$postId" preload="intent" preloadTimeout={100}>
676+
<Link to="/blog/post/$postId" preload="intent" preloadDelay={100}>
677677
Blog Post
678678
</Link>
679679
)

docs/router/framework/react/installation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ vibe-rules install cursor
5151
```
5252

5353
But you can also use `windsurf`, `claude-code`, etc. Check the [vibe-rules](https://www.npmjs.com/package/vibe-rules) documentation for more information.
54+
55+
### Usage with yarn workspaces
56+
57+
When using yarn workspaces, you will need to add the following config to the `.yarnrc.yml` of the application using TanStack Router
58+
59+
```yml
60+
pnpFallbackMode: all
61+
pnpMode: loose
62+
```

docs/router/framework/react/quick-start.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ Create the following files:
7676
import { createRootRoute, Link, Outlet } from '@tanstack/react-router'
7777
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
7878

79-
export const Route = createRootRoute({
80-
component: () => (
81-
<>
82-
<div className="p-2 flex gap-2">
83-
<Link to="/" className="[&.active]:font-bold">
84-
Home
85-
</Link>{' '}
86-
<Link to="/about" className="[&.active]:font-bold">
87-
About
88-
</Link>
89-
</div>
90-
<hr />
91-
<Outlet />
92-
<TanStackRouterDevtools />
93-
</>
94-
),
95-
})
79+
const RootLayout = () => (
80+
<>
81+
<div className="p-2 flex gap-2">
82+
<Link to="/" className="[&.active]:font-bold">
83+
Home
84+
</Link>{' '}
85+
<Link to="/about" className="[&.active]:font-bold">
86+
About
87+
</Link>
88+
</div>
89+
<hr />
90+
<Outlet />
91+
<TanStackRouterDevtools />
92+
</>
93+
)
94+
95+
export const Route = createRootRoute({ component: RootLayout })
9696
```
9797

9898
#### `src/routes/index.tsx`

docs/start/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
"label": "Static Server Functions",
4242
"to": "framework/react/static-server-functions"
4343
},
44+
{
45+
"label": "Environment Functions",
46+
"to": "framework/react/environment-functions"
47+
},
4448
{
4549
"label": "Middleware",
4650
"to": "framework/react/middleware"
@@ -122,6 +126,10 @@
122126
"label": "Static Server Functions",
123127
"to": "framework/solid/static-server-functions"
124128
},
129+
{
130+
"label": "Environment Functions",
131+
"to": "framework/solid/environment-functions"
132+
},
125133
{
126134
"label": "Middleware",
127135
"to": "framework/solid/middleware"

docs/start/framework/react/databases.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@ Convex's declarative data model and automatic conflict resolution ensure that yo
7979
- To learn more about Convex, visit the [Convex website](https://convex.dev?utm_source=tanstack)
8080
- To sign up, visit the [Convex dashboard](https://dashboard.convex.dev/signup?utm_source=tanstack)
8181

82+
## What is Prisma Postgres?
83+
84+
<a href="https://www.prisma.io?utm_source=tanstack&via=tanstack" alt="Prisma Logo">
85+
<picture>
86+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-dark.svg" width="280">
87+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-light.svg" width="280">
88+
<img alt="Prisma logo" src="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-light.svg" width="280">
89+
</picture>
90+
</a>
91+
92+
Instant Postgres, Zero Setup: Get a production-ready Postgres database in seconds, then dive straight back into code. We handle connections, scaling, and turning knobs so your flow never breaks. Blends perfectly with TanStack Start.
93+
94+
- Edge-optimized: Local region routing means lower latency and fewer hops. Even complex queries are one fast round trip.
95+
- Fits your stack: Works with your frameworks, libraries, and tools for a smooth DX.
96+
- Web UI: A hosted interface to inspect, manage, and query data with your team.
97+
- Auto-scaling: Grows from zero to millions of users without cold starts or manual tuning.
98+
- Unikernel isolation: Each DB runs as its own unikernel for security, speed, and efficiency.
99+
<br />
100+
<br />
101+
- To learn more about Prisma Postgres, visit the [Prisma website](https://www.prisma.io?utm_source=tanstack&via=tanstack)
102+
- To sign up, visit the [Prisma Console](https://console.prisma.io/sign-up?utm_source=tanstack&via=tanstack)
103+
82104
## Documentation & APIs
83105

84106
Documentation for integrating different databases with TanStack Start is coming soon! In the meantime, keep an eye on our examples and guide to learn how to fully leverage your data layer across your TanStack Start application.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
id: environment-functions
3+
title: Environment Functions
4+
---
5+
6+
## What Are Environment Functions?
7+
8+
Environment functions are utilities designed to define and control function execution based on the runtime environment—whether the code is running on the client or the server. These utilities help ensure that environment-specific logic is executed safely and intentionally, preventing runtime errors and improving maintainability in fullstack or isomorphic applications.
9+
10+
Start provide three core environment functions:
11+
12+
- `createIsomorphicFn`: Compose a single function that adapts to both client and server environments.
13+
- `serverOnly`: Ensures a function can only run on the server.
14+
- `clientOnly`: Ensures a function can only run on the client.
15+
16+
---
17+
18+
## Isomorphic Functions
19+
20+
Use `createIsomorphicFn()` to define functions that behave differently depending on whether they are called on the client or the server. This is useful for safely sharing logic across environments while delegating environment-specific behavior to appropriate handlers.
21+
22+
### Complete Implementation
23+
24+
```tsx
25+
import { createIsomorphicFn } from '@tanstack/react-start'
26+
27+
const getEnv = createIsomorphicFn()
28+
.server(() => 'server')
29+
.client(() => 'client')
30+
31+
const env = getEnv()
32+
// ℹ️ On the **server**, it returns `'server'`.
33+
// ℹ️ On the **client**, it returns `'client'`.
34+
```
35+
36+
### Partial Implementation (Server)
37+
38+
Here is an example of `createIsomorphicFn()` with only server implementation:
39+
40+
```tsx
41+
import { createIsomorphicFn } from '@tanstack/react-start'
42+
43+
const serverImplementationOnly = createIsomorphicFn().server(() => 'server')
44+
45+
const server = serverImplementationOnly()
46+
// ℹ️ On the **server**, it returns `'server'`.
47+
// ℹ️ On the **client**, it is no-op (returns `undefined`)
48+
```
49+
50+
### Partial Implementation (Client)
51+
52+
Here is an example of `createIsomorphicFn()` with only client implementation:
53+
54+
```tsx
55+
import { createIsomorphicFn } from '@tanstack/react-start'
56+
57+
const clientImplementationOnly = createIsomorphicFn().client(() => 'client')
58+
59+
const client = clientImplementationOnly()
60+
// ℹ️ On the **server**, it is no-op (returns `undefined`)
61+
// ℹ️ On the **client**, it returns `'client'`.
62+
```
63+
64+
### No Implementation
65+
66+
Here is an example of `createIsomorphicFn()` without any environment specific implementation:
67+
68+
```tsx
69+
import { createIsomorphicFn } from '@tanstack/react-start'
70+
71+
const noImplementation = createIsomorphicFn()
72+
73+
const noop = noImplementation()
74+
// ℹ️ On both **client** and **server**, it is no-op (returns `undefined`)
75+
```
76+
77+
#### What is a no-op?
78+
79+
A no-op (short for "no operation") is a function that does nothing when executed - it simply returns `undefined` without performing any operations.
80+
81+
```tsx
82+
// basic no-op implementation
83+
function noop() {}
84+
```
85+
86+
---
87+
88+
## `env`Only Functions
89+
90+
The `serverOnly` and `clientOnly` helpers enforce strict environment-bound execution. They ensure the decorated function is only callable in the correct runtime context. If misused, they throw descriptive runtime errors to prevent unintentional logic execution.
91+
92+
### `serverOnly`
93+
94+
```tsx
95+
import { serverOnly } from '@tanstack/react-start'
96+
97+
const foo = serverOnly(() => 'bar')
98+
99+
foo() // ✅ On server: returns "bar"
100+
// ❌ On client: throws "serverOnly() functions can only be called on the server!"
101+
```
102+
103+
### `clientOnly`
104+
105+
```tsx
106+
import { clientOnly } from '@tanstack/react-start'
107+
108+
const foo = clientOnly(() => 'bar')
109+
110+
foo() // ✅ On client: returns "bar"
111+
// ❌ On server: throws "clientOnly() functions can only be called on the client!"
112+
```
113+
114+
> [!NOTE]
115+
> These functions are useful for API access, filesystem reads, using browser APIs, or other operations that are invalid or insecure outside their intended environment.
116+
117+
## Tree Shaking
118+
119+
Environment functions are tree-shaken based on the environment for each bundle produced.
120+
121+
Functions created using `createIsomorphicFn()` are tree-shaken. All codes inside `.client()` are not included in server bundle, and vice-versa.
122+
123+
On the server, implementation of `clientOnly` functions are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions on the client.

docs/start/framework/react/hosting.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ When a TanStack Start application is being deployed, the `target` value in the T
3636
- [`netlify`](#netlify): Deploy to Netlify
3737
- [`vercel`](#vercel): Deploy to Vercel
3838
- [`cloudflare-pages`](#cloudflare-pages): Deploy to Cloudflare Pages
39+
- [`railway`](#railway): Deploy to Railway
3940
- [`node-server`](#nodejs): Deploy to a Node.js server
4041
- [`bun`](#bun): Deploy to a Bun server
4142
- ... and more to come!
@@ -108,6 +109,41 @@ directory = "./.output/public"
108109

109110
Deploy your application to Cloudflare Workers using their one-click deployment process, and you're ready to go!
110111

112+
### Railway
113+
114+
Railway automatically detects Build and Start commands when building and deploying to a service.
115+
116+
Set the `target` value to `node-server` in your `vite.config.ts` file.
117+
118+
```ts
119+
// vite.config.ts
120+
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
121+
import { defineConfig } from 'vite'
122+
123+
export default defineConfig({
124+
plugins: [tanstackStart({ target: 'node-server' })],
125+
})
126+
```
127+
128+
Ensure `build` and `start` npm scripts are present in your `package.json` file:
129+
130+
```json
131+
"build": "vite build",
132+
"start": "node .output/server/index.mjs"
133+
```
134+
135+
Then you can run the following command to build your application:
136+
137+
```sh
138+
npm run build
139+
```
140+
141+
You can start your application by running:
142+
143+
```sh
144+
npm run start
145+
```
146+
111147
### Node.js
112148

113149
Set the `target` value to `node-server` in your `vite.config.ts` file.

docs/start/framework/react/overview.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ TanStack Start is not for you if:
6767

6868
TanStack works closely with our partners to provide the best possible developer experience while also providing solutions that work anywhere and are vetted by industry experts. Each of our partners plays a unique role in the TanStack ecosystem:
6969

70-
- **Clerk**
71-
<a href="https://go.clerk.com/wOwHtuJ" alt="Clerk Logo">
72-
<picture>
73-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/clerk-logo-dark.svg" style="height: 40px;">
74-
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/clerk-logo-light.svg" style="height: 40px;">
75-
<img alt="Clerk logo" src="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/clerk-logo-light.svg" style="height: 40px;">
76-
</picture>
77-
</a>
78-
The best possible authentication experience for modern web applications, including TanStack Start applications. Clerk provides TanStack Start users with first-class integrations and solutions to auth and collaborates closely with the TanStack team to ensure that TanStack Start provides APIs that are up to date with the latest in auth best practices.
7970
- **Netlify**
8071
<a href="https://www.netlify.com?utm_source=tanstack" alt="Netlify Logo">
8172
<picture>
@@ -94,6 +85,15 @@ TanStack works closely with our partners to provide the best possible developer
9485
</picture>
9586
</a>
9687
A serverless, autoscaling Postgres solution purpose-built for modern full-stack apps. Neon offers rich integration opportunities with TanStack Start, including server functions and database-backed routing. Together, we’re simplifying the database experience for developers using TanStack.
88+
- **Clerk**
89+
<a href="https://go.clerk.com/wOwHtuJ" alt="Clerk Logo">
90+
<picture>
91+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/clerk-logo-dark.svg" style="height: 40px;">
92+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/clerk-logo-light.svg" style="height: 40px;">
93+
<img alt="Clerk logo" src="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/clerk-logo-light.svg" style="height: 40px;">
94+
</picture>
95+
</a>
96+
The best possible authentication experience for modern web applications, including TanStack Start applications. Clerk provides TanStack Start users with first-class integrations and solutions to auth and collaborates closely with the TanStack team to ensure that TanStack Start provides APIs that are up to date with the latest in auth best practices.
9797
- **Convex**
9898
<a href="https://convex.dev?utm_source=tanstack" alt="Convex Logo">
9999
<picture>
@@ -112,6 +112,15 @@ TanStack works closely with our partners to provide the best possible developer
112112
</picture>
113113
</a>
114114
A powerful, full-featured observability platform that integrates seamlessly with TanStack Start. Sentry helps developers monitor and fix crashes in real-time and provides insights into your application's performance and error tracking. Sentry collaborates closely with the TanStack team to ensure that TanStack Start provides APIs that are up to date with the latest in observability best practices.
115+
- **Prisma**
116+
<a href="https://prisma.io?utm_source=tanstack&via=tanstack" alt="Prisma Logo">
117+
<picture>
118+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-dark.svg" style="height: 60px;">
119+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-light.svg" style="height: 60px;">
120+
<img alt="Prisma logo" src="https://raw.githubusercontent.com/tanstack/tanstack.com/main/src/images/prisma-light.svg" style="height: 60px;">
121+
</picture>
122+
</a>
123+
Skip the database setup, get to building. Prisma Postgres provisions production-ready Postgres databases in seconds—no resource config, no infrastructure planning, no late-night "why is my connection pool maxed out?" debugging sessions. Just connect your TanStack app and start building features that matter.
115124

116125
## Ready to get started?
117126

0 commit comments

Comments
 (0)