secondsky/claude-skills / plugins/tanstack-start/skills/tanstack-start
tanstack-start
VerifiedTanStack Start (RC) full-stack React with server functions, SSR, Cloudflare Workers. Use for Next.js migration, edge rendering, or encountering hydration, auth, data pattern errors.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.4 KB |
| references/cloudflare-hosting-and-env.md | markdown | 2.6 KB |
| references/devtools-and-llm-support.md | markdown | 1.2 KB |
| references/execution-and-auth.md | markdown | 2.1 KB |
| references/navigation-and-preloading.md | markdown | 1.6 KB |
| references/quickstart-and-layout.md | markdown | 2.8 KB |
| references/rendering-modes.md | markdown | 2.0 KB |
| references/routing-and-data-loading.md | markdown | 2.3 KB |
| references/server-functions-and-middleware.md | markdown | 2.9 KB |
| scripts/bootstrap-cloudflare-start.sh | script | 1.1 KB |
references/server-functions-and-middleware.md
View on GitHub# Server Functions, Routes & Middleware
## Server Functions (RPC-style)
```ts
import { createServerFn } from '@tanstack/react-start'
import { z } from 'zod'
export const saveNote = createServerFn({ method: 'POST' })
.inputValidator(z.object({ body: z.string().min(1) }))
.handler(async ({ data, request }) => {
const userId = request.headers.get('x-user-id')
if (!userId) throw new Response('Unauthorized', { status: 401 })
await db.notes.insert({ userId, body: data.body })
return { ok: true }
})
// Call from client or loaders:
await saveNote({ body: 'hello' })
```
- Runs only on the server; the client call becomes a fetch to the compiled endpoint.
- Access request with `getRequest()` helpers or handler args; headers/cookies available.
- Return plain data, `Response`, redirects (`throw redirect({ to: '/login' })`), or not-found.
### Static server functions (prerender-friendly)
```ts
import { staticFunctionMiddleware } from '@tanstack/start-static-server-functions'
export const cachedSettings = createServerFn()
.middleware([staticFunctionMiddleware]) // execute at build, emit static JSON
.handler(async () => fetchSettingsFromCms())
```
## Server Routes (raw HTTP)
```ts
// app/routes/api/health.ts
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/api/health')({
server: {
handlers: {
GET: () => Response.json({ ok: true, at: Date.now() }),
POST: async ({ request }) => {
const body = await request.json()
return Response.json({ echoed: body })
},
},
},
})
```
- Lives beside page routes; supports params (`/api/users/$id.ts`), splats, and route-level middleware.
- Use for webhooks, form posts, or streaming responses without React render.
## Middleware Patterns
```ts
import { createMiddleware, createServerFn } from '@tanstack/react-start'
import { redirect } from '@tanstack/react-router'
const requireAuth = createMiddleware({ type: 'function' })
.server(async ({ next, context }) => {
const user = await getSessionUser()
if (!user) throw redirect({ to: '/login' })
return next({ context: { user } })
})
export const updateProfile = createServerFn({ method: 'POST' })
.middleware([requireAuth])
.handler(async ({ data, context }) => {
return db.user.update(context.user.id, data)
})
```
- `createMiddleware()` defaults to request middleware; use `{ type: 'function' }` for server-function-specific flows.
- Chain middleware with `.middleware([...])`; always `return next()` to continue.
- Register global middleware in `createStart(() => ({ requestMiddleware: [...], functionMiddleware: [...] }))`.
## Error Boundaries & Hydration Safety
- Throw `redirect()` or `notFound()` from loaders/server functions; Start will surface in route error boundaries.
- For hydration-sensitive components, pair with `ssr: 'data-only'` (see rendering-modes.md) or wrap UI in a client-only boundary.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |