tanstack
Comprehensive guide for the TanStack ecosystem in React — Query (caching, mutations, prefetching, SSR), DB (collections, live queries, optimistic updates), Form (state, validation, fields), Router (file-based, type-safe navigation, search params, loaders), and Start (server functions, middleware, auth, SSR). Use when working with any TanStack library in a React/full-stack project. Don't use for non-TanStack data libraries (SWR, Apollo, RTK Query), non-React TanStack ports (Solid, Svelte), or backend-only work.
What this skill does
# TanStack Developer Guide
This SKILL.md is a **dispatcher**, not an encyclopedia. The load-bearing detail (code patterns, anti-patterns, edge cases, full checklists) lives in `references/*.md`. The tripwires below exist so you can detect violations during scanning — they are not the contract.
## Required Reading Router
Match the task to the row. **Read the listed file(s) in full before producing output.** They are not appendices — they are the contract. Inline content in this SKILL.md is a pointer, not a substitute.
| Task | MUST read |
|------|-----------|
| `useQuery` / `useMutation` / prefetch / infinite list / SSR hydration / cache config | `references/query-patterns.md` |
| Typed collections, live queries, optimistic collection mutations | `references/db-patterns.md` |
| Forms, field components, validation, async checks | `references/form-patterns.md` |
| Routes, search params, loaders, navigation, auth-protected layouts, router setup | `references/router-patterns.md` |
| Server functions, middleware, sessions, SSR streaming, env, deploy adapters | `references/start-patterns.md` |
| Anything that touches **two or more** layers (e.g. route loader + server fn + form) | Each file from the relevant rows — read all before designing |
## Reference Index
| File | What you get |
|------|--------------|
| `references/query-patterns.md` | Vanilla Query: key factories + `queryOptions`, `staleTime`/`gcTime`, `placeholderData` vs `initialData`, optimistic mutations with rollback, error boundaries, intent prefetch, infinite queries, SSR dehydrate/hydrate, `useQueries`, cancellation, `select`, network mode, persistence, testing |
| `references/db-patterns.md` | DB collections: 5 critical rules, collection setup, live queries with joins, optimistic updates, shared collection instances, persistence handlers, common anti-patterns, advanced patterns (computed, aggregations, pagination) |
| `references/form-patterns.md` | Form: `createFormHook` + `useAppForm`, Zod schema validation, field/form/async validators with debounce, reusable field components (TextField, SelectField, SubmitButton), array fields, error handling with a11y, performance, anti-patterns |
| `references/router-patterns.md` | Router: `declare module` registration, router defaults, `from` narrowing, pathless layouts, search-param Zod validation, parallel + deferred loaders, lazy + auto code splitting, custom serializers, `notFound()`, route masks, integration with TanStack Query |
| `references/start-patterns.md` | Start: `createServerFn` with Zod validator, request + function middleware, secure cookie sessions, route protection, SSR streaming + hydration safety, prerender/ISR, API routes, env split, file separation, deploy adapters |
---
## Tripwires (not the contract)
These bullets exist so you can spot likely violations during a scan. **They are deliberately incomplete.** The full rules, examples, and edge cases live in the reference files. If a tripwire triggers, you must consult the referenced file before fixing.
### Query / DB
- Vanilla Query and DB collections are different paradigms — never mix them on the same entity.
- `staleTime: 0` (default) refetches on every mount. Tune by data volatility.
- Optimistic mutations without `cancelQueries` + rollback context will get overwritten by in-flight refetches.
**STOP. Read `references/query-patterns.md` in full before writing a `useQuery`, `useMutation`, prefetch, or SSR hydration boundary.** **STOP. Read `references/db-patterns.md` in full before creating a collection, live query, or persistence handler.** The three bullets above only flag the most common slip-ups.
### Form
- `defaultValues` drives type inference — manual generics fight it.
- Async validators without `asyncDebounceMs` hammer the network.
- Reuse Zod schemas across form + server function (in `*.shared.ts`).
**STOP. Read `references/form-patterns.md` in full before building or modifying a form, field component, or validator.** Field-level a11y attributes, `createFormHook` setup, and array-field patterns are not in this body.
### Router
- Without `declare module '@tanstack/react-router' { interface Register { router: typeof router } }`, `Link`/`useNavigate`/`useParams` silently degrade to `unknown`.
- Sequential `await`s in a loader create waterfalls — fan out with `Promise.all`.
- Throw `notFound()` / `redirect()` from loaders, not generic `Error`.
**STOP. Read `references/router-patterns.md` in full before adding a route, changing router setup, writing a loader, or modifying search-param validation.** Defaults (`defaultPreload`, `scrollRestoration`, global error/404), pathless layouts, masks, and deferred loaders all live in the reference.
### Start
- Server logic belongs in `createServerFn` with a Zod `validator()` — not raw `fetch` + API routes.
- Auth uses HTTP-only cookies. localStorage is XSS-bait.
- SSR loaders should `await` only critical data; stream the rest via `prefetchQuery` + `Suspense`.
**STOP. Read `references/start-patterns.md` in full before writing a server function, middleware, session helper, or SSR loader.** Cookie settings, middleware composition order, hydration-safety pitfalls, and adapter trade-offs are not in this body.
---
## End-of-task checklist
Each reference file has a scoped checklist with the real validation criteria. This umbrella confirms you actually consulted them:
- [ ] For each layer you touched, the corresponding reference file was read **in full**, not skimmed
- [ ] The scoped checklist in that reference file passes
- [ ] No mixed Query/DB paradigms on the same entity
- [ ] `pnpm run typecheck` and `pnpm run test` pass
If you cannot point to which reference file you read for a given change, the change is not done.
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.