Claude-skills tanstack-start
TanStack 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.
install
source · Clone the upstream repo
git clone https://github.com/secondsky/claude-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/secondsky/claude-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/tanstack-start/skills/tanstack-start" ~/.claude/skills/secondsky-claude-skills-tanstack-start && rm -rf "$T"
manifest:
plugins/tanstack-start/skills/tanstack-start/SKILL.mdsource content
TanStack Start (React) — RC-Ready Playbook
Full-stack React on TanStack Router with per-route SSR/CSR, file-based routing, server functions, and first-class Cloudflare Workers support.
Use this skill when
- Building a greenfield React app that needs route-level SSR/CSR/SSG switches.
- Migrating from Next.js/React Router while keeping file-based routing + API routes.
- Shipping to edge runtimes (Workers) with typed server functions and bindings.
- You want predictable routing with type-safe params/search + built-in preloading.
What’s inside
- References: quickstart/layout, rendering modes, server functions, Cloudflare hosting, execution/auth, plus new routing/data/navigation/devtools guides.
- Script:
scaffolds Start + Workers + binding types.scripts/bootstrap-cloudflare-start.sh <app> - Troubleshooting: hydration, API routing, bindings, navigation/preloading failures.
Quick Start (React)
npm create @tanstack/start@latest my-app cd my-app npm run dev
Manual installs (all bundle targets are supported): add
@tanstack/react-router + @tanstack/react-start with your bundler plugin (vite, webpack, or esbuild) per the official install guides.
Core layout reminder
file-based routes → router tree, automatic code-splitting + data preloading.app/routes/**
hydratesapp/entry.client.tsx
;<StartClient />
wrapsapp/entry.server.tsx
.createServerEntry
orapp/config.ts
setsapp/start.ts
,defaultSsr
, middleware, and context.spaMode
Routing + Data Best Practices
- Type-safe params & search:
infers path params; addcreateFileRoute()
(zod) to parse and coerce search params.validateSearch - Route matching order is deterministic (index → static → dynamic → splat); rely on this when adding catch-alls.
- Loaders run once per location change; return plain data, throw
/redirect()
for control flow.notFound() - Data mutations: colocate
/server functions; keep loaders read-only and invalidate viaaction
after mutation.router.invalidate() - TanStack Query bridge: create a
in router context andQueryClient
inside loaders to dedupe fetches.ensureQueryData - Deferred/external data: stream partial data or read from external loaders; prefer suspense-friendly responses.
- Head management: set
per route forhead
/meta; derive from loader data to keep SEO consistent.<title> - Not-found/auth: throw
ornotFound()
in loaders/middleware; use error boundaries for UX.redirect()
Example route (typed search + data-only SSR):
// app/routes/posts.$postId.tsx import { createFileRoute, redirect } from '@tanstack/react-router' import { z } from 'zod' export const Route = createFileRoute('/posts/$postId')({ validateSearch: z.object({ preview: z.boolean().optional() }), ssr: 'data-only', loader: async ({ params, search, context }) => { const post = await context.queryClient.ensureQueryData(['post', params.postId], () => fetch(`/api/posts/${params.postId}?preview=${!!search.preview}`).then(r => r.json()) ) if (!post.published && !search.preview) throw redirect({ to: '/drafts' }) return { post } }, })
Navigation, Preloading, and UX
- Link prefetch defaults:
(hover/focus) preloads route data/code; use<Link preload="intent">
for above-the-fold routes.preload="render" - Programmatic preloading:
to warm caches before navigation (e.g., on visibility).router.preloadRoute({ to, search }) - Route masking: keep canonical URLs while showing user-friendly masks (e.g.,
masked as/products?slug=abc
)./p/abc - Navigation blocking: protect unsaved forms with
blockers orrouter.navigate({ to, replace, from })
.useBlocker - Scroll restoration: enable
to restore positions on back/forward; customize per route when using long lists.scrollRestoration - Search param serialization: customize parse/stringify to keep numbers/dates stable and avoid stringified booleans.
Rendering & Performance
- Per-route SSR: set
on routes;ssr: true | false | 'data-only'
config sets the baseline.defaultSsr - Code-splitting: file-based routes auto-split; add
/lazy
for manual chunks on code-based routes.load - Preloading strategy: pair
links withpreload="intent"
to avoid over-fetching.defaultPreloadStaleTime - Render optimizations: keep loaders pure, memoize heavy components, and use
for CSR routes to avoid layout shift.pendingComponent
Devtools, Linting, and LLM Support
- Add
during development to inspect matches, loader states, and preloading.<RouterDevtools /> - Enable the ESLint plugin
with the recommended config to enforce inference-sensitive property order (e.g.,@tanstack/eslint-plugin-router
beforebeforeLoad
).loader - LLM-aware routing: the Router exposes structured route metadata to LLM agents; keep descriptions concise in
meta for better AI navigation.Route
Deployment Notes (Cloudflare-friendly)
- Keep
first in Vite plugins so bindings reach server entry.cloudflare({ viteEnvironment: { name: 'ssr' } }) - Regenerate bindings after changes:
.npm run cf-typegen - For static-heavy sites, enable prerender to ship HTML to Workers Assets/Pages; exclude param routes or add explicit
.pages
Ship Checklist
- Routes load without hydration warnings (prefer
for non-deterministic UI).ssr: 'data-only' - Search params validated with
and custom serializer where needed.validateSearch - Link preloading configured for high-traffic routes; blockers added for unsaved forms.
- ESLint plugin enabled (
rule) andcreate-route-property-order
passes.npm run check - Devtools verified locally;
state looks correct.router.matches - Cloudflare bindings typed (
) and streaming tested viacf-typegen
.curl -N