tanstack-start-server-runtime-and-apis
TanStack Start Server Runtime and APIs
Use this skill when the task is primarily about TanStack Start's request lifecycle, server-side APIs, middleware flow, or safe server and client separation.
Scope
- server functions and server routes
- middleware composition and ordering
src/server.tsandsrc/client.tsxentrypoint concerns- request and response lifecycle
- environment functions and env-variable boundaries
- typed request context propagation
Routing cues
createServerFn,useServerFn,server: { handlers },createHandlers,createMiddleware,useSession,setResponseHeaders,setResponseStatus,src/server.ts,src/client.tsx, orVITE_env boundaries -> use this skill- SSR-mode selection, hydration, or import protection as the primary concern -> use
tanstack-start-rendering-and-execution - hosting provider selection, Nitro, Cloudflare, Netlify, or observability plumbing -> use
tanstack-start-deployment-and-runtime-ops - auth provider strategy, sessions as product behavior, or route protection flows -> use
tanstack-start-auth-and-backend-integrations
Workflow
- Read references/server-runtime-and-request-flow.md first.
- Decide whether the task needs a server function, a server route, or middleware before writing code.
- Keep server-only helpers in server-only files and import them from the server boundary, not from arbitrary shared UI modules.
- Keep
src/server.tsminimal unless the app truly needs custom fetch handling or typed request context at the entry point.
Quick example
import { createServerFn } from '@tanstack/react-start'
export const saveDraft = createServerFn({ method: 'POST' })
.inputValidator((data: { title: string }) => data)
.handler(async ({ data }) => {
return db.drafts.insert(data)
})
Guardrails
- Prefer static imports for server functions. The docs explicitly warn against dynamic imports for them.
createServerFn()is a networked server boundary.createServerOnlyFn()andcreateClientOnlyFn()are runtime-enforced environment helpers, not RPCs.- Request middleware and function middleware are not interchangeable. Function middleware can depend on request middleware, not the other way around.
- Middleware ordering matters. Dependency-first execution and missing
next()calls change behavior quickly. - Route-level middleware runs before handler-specific middleware in server routes.
- Server route paths must stay unique; mixed file-name and directory forms can collide.
- Client code only gets
VITE_values fromimport.meta.env. Secrets stay inprocess.envon the server. - If the client needs a runtime-only secret-derived value, pass it through a loader or server function instead of reading non-
VITE_env vars directly. staticFunctionMiddlewareis experimental and must be the final middleware on a static server function.
Canonical APIs
createServerFnuseServerFncreateMiddlewarecreateStartHandlercreateServerEntrysetResponseHeaderssetResponseStatusgetRequestgetRequestHeader
Maintenance
- Snapshot date: 2026-03-24
- Package snapshot:
@tanstack/react-start@1.167.2latest published 2026-03-21 - Docs status snapshot: official docs still label TanStack Start as RC / feature-complete and recommend pinning versions for production
References
More from dobroslavradosavljevic/skills
base-ui-typescript-surface
Use for Base UI namespace contracts, change event types, generic render types, and wrapper typing patterns.
4base-ui-basic-primitives
Use for simple primitives with low integration complexity (Avatar, Button, Meter, Progress, Scroll Area, Separator).
4base-ui-root-providers
Use for CSP Provider, Direction Provider, and useDirection when wiring Base UI at the app root or across portals.
4base-ui-menus-navigation-and-toast
Use for Menu, Context Menu, Menubar, Navigation Menu, Toolbar, Toast, and shared command-surface patterns such as detached triggers and menu payloads.
4base-ui-forms-and-validation
Use for Base UI Field/Form primitives, validation flows, form controls, and advanced Number Field, Slider, and RadioGroup behavior.
4base-ui-disclosure-and-tabs
Use for stateful visibility components (Accordion, Collapsible) and tab navigation semantics.
4