Skip to content

Commit e8757e3

Browse files
authored
Merge branch 'main' into fix/buildlocation-href-rewrite
2 parents 710f5cc + 51da7fb commit e8757e3

File tree

216 files changed

+6166
-1146
lines changed

Some content is hidden

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

216 files changed

+6166
-1146
lines changed

docs/router/api/file-based-routing.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ The following options are available for configuring the file-based routing:
1818
- [`routeToken`](#routetoken)
1919
- [`quoteStyle`](#quotestyle)
2020
- [`semicolons`](#semicolons)
21-
- [`apiBase`](#apibase)
2221
- [`autoCodeSplitting`](#autocodesplitting)
2322
- [`disableTypes`](#disabletypes)
2423
- [`addExtensions`](#addextensions)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ By default, all links are absolute unless a `from` route path is provided. This
185185

186186
Relative links can be combined with a `from` route path. If a from route path isn't provided, relative paths default to the current active location.
187187

188+
> [!NOTE]
189+
> Keep in mind that when calling useNavigate as a method on the route, for example `Route.useNavigate`, then the `from` location is predefined to be the route it's called on.
190+
>
191+
> Another common pitfall is when using this in a pathless layout route, since the pathless layout route does not have an actual path, the `from` location is regarded as the parent of the pathless layout route. Hence relative routing will be resolved from this parent.
192+
188193
```tsx
189194
const postIdRoute = createRoute({
190195
path: '/blog/post/$postId',

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ declare module '@tanstack/react-router' {
7070

7171
### Rendering the Application on the Server
7272

73-
Now that you have a router instance that has loaded all of the critical data for the current URL, you can render your application on the server:
73+
Now that you have a router instance that has loaded all the critical data for the current URL, you can render your application on the server:
7474

75-
using `defaultRenderToString`
75+
using `defaultRenderHandler`
7676

7777
```tsx
7878
// src/entry-server.tsx
@@ -85,7 +85,7 @@ import { createRouter } from './router'
8585
export async function render({ request }: { request: Request }) {
8686
const handler = createRequestHandler({ request, createRouter })
8787

88-
return await handler(defaultRenderToString)
88+
return await handler(defaultRenderHandler)
8989
}
9090
```
9191

@@ -144,7 +144,7 @@ With this setup, your application will be rendered on the server and then hydrat
144144

145145
## Streaming SSR
146146

147-
Streaming SSR is the most modern flavor of SSR and is the process of continuously and incrementally sending HTML markup to the client as it is rendered on the server. This is slightly different from traditional SSR in concept because beyond being able to dehydrate and rehydrate a critical first paint, markup and data with less priority or slower response times can be streamed to the client after the initial render, but in the same request.
147+
Streaming SSR is the most modern flavor of SSR and is the process of continuously and incrementally sending HTML markup to the client as it is rendered on the server. This is slightly different from traditional SSR in concept because beyond being able to dehydrate and rehydrate a critical first paint, markup and data with lower priority or slower response times can be streamed to the client after the initial render, but in the same request.
148148

149149
This pattern can be useful for pages that have slow or high-latency data fetching requirements. For example, if you have a page that needs to fetch data from a third-party API, you can stream the critical initial markup and data to the client and then stream the less-critical third-party data to the client as it is resolved.
150150

docs/start/framework/react/authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ TanStack Start provides secure HTTP-only cookie sessions:
9595

9696
```tsx
9797
// utils/session.ts
98-
import { useSession } from '@tanstack/react-start'
98+
import { useSession } from '@tanstack/react-start/server'
9999

100100
type SessionData = {
101101
userId?: string

docs/start/framework/react/fetching-external-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ At this point, the project structure should look like this:
6161
│ ├── routeTree.gen.ts # Generated route tree
6262
│ └── styles.css # Global styles
6363
├── public/ # Static assets
64-
├── app.config.ts # TanStack Start configuration
64+
├── vite.config.ts # TanStack Start configuration
6565
├── package.json # Project dependencies
6666
└── tsconfig.json # TypeScript configuration
6767

docs/start/framework/react/hosting.md

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,15 @@ Once you've chosen a deployment target, you can follow the deployment guidelines
3737
</picture>
3838
</a>
3939

40-
### Cloudflare Workers
41-
4240
When deploying to Cloudflare Workers, you'll need to complete a few extra steps before your users can start using your app.
4341

44-
1. Install `@cloudflare/vite-plugin`
42+
1. Install `@cloudflare/vite-plugin` and `wrangler`
4543

4644
```bash
47-
pnpm install @cloudflare/vite-plugin -D
45+
pnpm add -D @cloudflare/vite-plugin wrangler
4846
```
4947

50-
2. Update `vite.config.ts`
51-
52-
Add the cloudflare plugin to your `vite.config.ts` file.
48+
2. Add the Cloudflare plugin to your `vite.config.ts` file
5349

5450
```ts
5551
// vite.config.ts
@@ -67,42 +63,36 @@ export default defineConfig({
6763
})
6864
```
6965

70-
3. Install `wrangler`
71-
72-
```bash
73-
pnpm add wrangler -D
74-
```
75-
76-
4. Add a `wrangler.json` config file
66+
3. Add a `wrangler.jsonc` config file
7767

7868
```json
7969
{
8070
"$schema": "node_modules/wrangler/config-schema.json",
8171
"name": "tanstack-start-app",
8272
"compatibility_date": "2025-09-02",
8373
"compatibility_flags": ["nodejs_compat"],
84-
"main": "@tanstack/react-start/server-entry",
85-
"vars": {
86-
"MY_VAR": "Hello from Cloudflare"
87-
}
74+
"main": "@tanstack/react-start/server-entry"
8875
}
8976
```
9077

91-
5. Modify package.json script
78+
4. Modify the scripts in your `package.json` file
9279

9380
```json
9481
{
9582
"scripts": {
9683
"dev": "vite dev",
9784
"build": "vite build && tsc --noEmit",
85+
// ============ 👇 remove this line ============
9886
"start": "node .output/server/index.mjs",
99-
// ============ 👇 add this line ============
100-
"deploy": "wrangler deploy"
87+
// ============ 👇 add these lines ============
88+
"preview": "vite preview",
89+
"deploy": "wrangler deploy",
90+
"cf-typegen": "wrangler types"
10191
}
10292
}
10393
```
10494

105-
6. Build and deploy
95+
5. Build and deploy
10696

10797
```bash
10898
pnpm run build && pnpm run deploy

docs/start/framework/react/middleware.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const loggingMiddleware = createMiddleware().server(async ({ next }) => {
8181

8282
## Request Middleware
8383

84-
Request middleware is used to customize the behavior of any server request that passes through it, including both server routes and server functions.
84+
Request middleware is used to customize the behavior of any server request that passes through it, including server routes, SSR and server functions.
8585

8686
To create a request middleware, call the `createMiddleware` function. You may call this function with the `type` property set to 'request', but this is the default value so you can omit it if you'd like.
8787

@@ -418,7 +418,7 @@ export const startInstance = createStart(() => {
418418
```
419419

420420
> [!NOTE]
421-
> Global **request** middleware runs before **every request, including both server routes and server functions**.
421+
> Global **request** middleware runs before **every request, including server routes, SSR and server functions**.
422422
423423
### Global Server Function Middleware
424424

docs/start/framework/react/path-aliases.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ After updating your `tsconfig.json` file, you'll need to install the `vite-tscon
2626
npm install -D vite-tsconfig-paths
2727
```
2828

29-
Now, you'll need to update your `app.config.ts` file to include the following:
29+
Now, you'll need to update your `vite.config.ts` file to include the following:
3030

3131
```ts
32-
// app.config.ts
33-
import { defineConfig } from '@tanstack/react-start/config'
32+
// vite.config.ts
33+
import { defineConfig } from 'vite'
3434
import viteTsConfigPaths from 'vite-tsconfig-paths'
3535

3636
export default defineConfig({

docs/start/framework/react/reading-writing-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ At this point, the project structure should look like this -
7979
│ ├── ssr.tsx # Server-side rendering
8080
│ └── styles.css # Global styles
8181
├── public/ # Static assets
82-
├── app.config.ts # TanStack Start configuration
82+
├── vite.config.ts # TanStack Start configuration
8383
├── package.json # Project dependencies
8484
└── tsconfig.json # TypeScript configuration
8585
```

docs/start/framework/react/server-entry-point.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
}
3232
```
3333

34-
Whether we are statically generating our app or serving it dynamically, the `server.ts` file is the entry point for doing all SSR-related work.
34+
Whether we are statically generating our app or serving it dynamically, the `server.ts` file is the entry point for doing all SSR-related work as well as for handling server routes and server function requests.
3535

3636
## Custom Server Handlers
3737

@@ -42,13 +42,13 @@ You can create custom server handlers to modify how your application is rendered
4242
import {
4343
createStartHandler,
4444
defaultStreamHandler,
45+
defineHandlerCallback,
4546
} from '@tanstack/react-start/server'
4647

47-
// Custom handler example
48-
const customHandler = (request, response) => {
49-
// Add custom logic here
50-
return defaultStreamHandler(request, response)
51-
}
48+
const customHandler = defineHandlerCallback((ctx) => {
49+
// add custom logic here
50+
return defaultStreamHandler(ctx)
51+
})
5252

5353
const fetch = createStartHandler(customHandler)
5454

@@ -57,6 +57,35 @@ export default {
5757
}
5858
```
5959

60+
## Request context
61+
62+
When your server needs to pass additional, typed data into request handlers (for example, authenticated user info, a database connection, or per-request flags), register a request context type via TypeScript module augmentation. The registered context is delivered as the second argument to the server `fetch` handler and is available throughout the server-side middleware chain — including global middleware, request/function middleware, server routes, server functions, and the router itself.
63+
64+
To add types for your request context, augment the `Register` interface from `@tanstack/react-start` with a `server.requestContext` property. The runtime `context` you pass to `handler.fetch` will then match that type. Example:
65+
66+
```tsx
67+
import handler from '@tanstack/react-start/server-entry'
68+
69+
type MyRequestContext = {
70+
hello: string
71+
foo: number
72+
}
73+
74+
declare module '@tanstack/react-start' {
75+
interface Register {
76+
server: {
77+
requestContext: MyRequestContext
78+
}
79+
}
80+
}
81+
82+
export default {
83+
async fetch(request: Request): Promise<Response> {
84+
return handler.fetch(request, { context: { hello: 'world', foo: 123 } })
85+
},
86+
}
87+
```
88+
6089
## Server Configuration
6190

6291
The server entry point is where you can configure server-specific behavior:

0 commit comments

Comments
 (0)