Open History to see the last commit
1# TanStack Query - Skill Spec
2β
3TanStack Query manages server state through a framework-agnostic cache, observers, framework adapters, persistence utilities, devtools, lint rules, and migration tooling. This draft follows the published docs order in `docs/config.json` and treats TKDodo's blog order as an external priority signal.
4β
5TanStack Start and TanStack Router are first-class composition targets here, especially for loaders, SSR hydration, streaming, and cache handoff. Next.js remains important, but it is not the default mental model for TanStack-owned routing.
6β
7The maintainer skipped live interviews, so unresolved judgment calls remain in the gaps section.
8β
9## Domains
10β
11| Domain | Description | Skills |
12| ----------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
13| Bootstrapping query clients | Creating stable clients and provider context | setup-query-client-and-providers |
14| Reading server state | Declaring reads, query identity, observers, status, and reusable abstractions | design-query-keys-and-options, build-query-abstractions, understand-query-internals-and-observers, fetch-and-observe-queries, handle-status-and-errors |
15| Coordinating query execution | Dependency, freshness, retries, pagination, prefetch | tune-defaults-freshness-retries-and-refetching, coordinate-dependent-parallel-disabled-and-background-queries, paginate-and-build-infinite-queries |
16| Writing server state | Mutations, invalidation, optimistic writes, forms, cancellation | write-mutations-and-invalidate-related-queries, automatic-invalidation-after-mutations, implement-optimistic-updates-and-cache-writes, concurrent-optimistic-updates, query-data-and-forms, cancel-queries-and-consume-abort-signals |
17| Shaping cache and render behavior | Seeded data, placeholders, selectors, derived state, render performance | seed-placeholder-select-and-transform-data, selectors-and-derived-state, shape-data-and-render-efficiently |
18| Rendering across environments | SSR, hydration, Suspense, streaming, routers | prefetch-and-remove-request-waterfalls, compose-query-with-tanstack-router-and-start, ssr-hydration-and-streaming, use-suspense-and-error-boundaries |
19| Persisting and synchronizing caches | Persistence, offline, multi-tab, realtime | persist-offline-and-restore-caches, broadcast-realtime-and-multi-tab-synchronization |
20| Framework adapter idioms | Reactivity and provider rules across adapters | use-framework-adapter-reactivity |
21| Operational quality | Devtools, testing, migration, linting | debug-with-devtools, test-query-code, migrate-major-versions-and-codemods, enforce-query-best-practices-with-eslint |
22β
23## Skill Inventory
24β
25| Skill | Type | Domain | What it covers | Failure modes |
26| ---------------------------------------------------------------- | ----------- | ----------------------------------- | --------------------------------------------------------------------------------------- | ------------- |
27| Set up QueryClient and providers | lifecycle | Bootstrapping query clients | QueryClient, providers, SSR isolation, Lit fallback | 3 |
28| Design query keys and reusable options | core | Reading server state | queryKey, queryFn, queryOptions, skipToken | 3 |
29| Build Query abstractions | core | Reading server state | queryOptions factories, custom hooks, usage-site composition, TypeScript inference | 3 |
30| Understand Query internals and observers | core | Reading server state | QueryClient, QueryCache, QueryObserver, active/inactive queries | 3 |
31| Fetch and observe queries | core | Reading server state | useQuery/createQuery/injectQuery, status, fetchStatus | 3 |
32| Handle status checks and errors | framework | Reading server state | status, fetchStatus, background errors, throwOnError, cache-level callbacks | 3 |
33| Tune defaults, freshness, retries, and refetching | core | Coordinating query execution | staleTime, gcTime, retry, refetch triggers, networkMode | 3 |
34| Coordinate dependent, parallel, disabled, and background queries | core | Coordinating query execution | useQueries, enabled, skipToken, background fetching | 3 |
35| Paginate and build infinite queries | core | Coordinating query execution | pagination, infinite queries, maxPages | 3 |
36| Write mutations and invalidate related queries | core | Writing server state | mutations, invalidation, mutation state | 3 |
37| Automatic invalidation after mutations | composition | Writing server state | MutationCache callbacks, mutationKey invalidation, meta tags, scoped invalidation | 3 |
38| Implement optimistic updates and cache writes | core | Writing server state | onMutate, rollback, setQueryData | 3 |
39| Concurrent optimistic updates | core | Writing server state | submittedAt, mutationKey filters, isMutating guards, filtered optimistic lists | 3 |
40| Query data and forms | composition | Writing server state | initial form state, dirty fields, derived server/client state, reset after invalidation | 3 |
41| Cancel queries and consume AbortSignals | core | Writing server state | AbortSignal, cancelQueries, CancelledError | 3 |
42| Seed, placeholder, select, and transform data | core | Shaping cache and render behavior | initialData, placeholderData, select | 3 |
43| Selectors and derived state | core | Shaping cache and render behavior | select, selector identity, structural sharing, render-time derivation | 3 |
44| Shape data and render efficiently | framework | Shaping cache and render behavior | structural sharing, tracked props, immutable data | 3 |
45| Prefetch and remove request waterfalls | lifecycle | Rendering across environments | prefetchQuery, router loaders, waterfalls | 3 |
46| Compose TanStack Query with TanStack Router and Start | composition | Rendering across environments | router context, loaders, `@tanstack/react-router-ssr-query`, Start SSR/streaming | 3 |
47| SSR, hydration, and streaming | lifecycle | Rendering across environments | dehydrate/hydrate, Start, Router SSR Query, RSC, SvelteKit, Nuxt | 3 |
48| Use Suspense and error boundaries | framework | Rendering across environments | suspense hooks, QueryErrorResetBoundary, React.use | 3 |
49| Persist offline and restore caches | composition | Persisting and synchronizing caches | persistQueryClient, persisters, restore races | 3 |
50| Broadcast, realtime, and multi-tab synchronization | composition | Persisting and synchronizing caches | broadcastQueryClient, WebSockets, realtime invalidation | 3 |
51| Use framework adapter reactivity | framework | Framework adapter idioms | Vue refs, Svelte runes, Angular signals, Lit controllers | 3 |
52| Debug with devtools | framework | Operational quality | framework devtools, embedded panels, production imports | 3 |
53| Test query code | lifecycle | Operational quality | test clients, retry false, cache isolation | 3 |
54| Migrate major versions and codemods | lifecycle | Operational quality | v5 object syntax, renamed options, Svelte v6 | 3 |
55| Enforce Query best practices with ESLint | composition | Operational quality | recommended configs and Query-specific rules | 3 |
56β
57## Failure Mode Inventory
58β
59| Skill | High-priority examples |
60| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
61| setup-query-client-and-providers | New client on every render; shared SSR cache between users; ambiguous Lit fallback client |
62| design-query-keys-and-options | Missing variables in query key; separated key/queryFn drift; skipToken inside suspense query |
63| build-query-abstractions | Custom hook is the only abstraction; wide UseQueryOptions wrapper breaks inference; wrapper hides Query result state |
64| understand-query-internals-and-observers | Cache presence treated as active usage; observer-level options ignored; inactive queries expected to refetch like mounted queries |
65| fetch-and-observe-queries | Void query function; only checking pending for offline state; using queries for writes |
66| handle-status-and-errors | Stale data hidden on background error; validation errors sent to global boundary; duplicate toasts per observer |
67| tune-defaults-freshness-retries-and-refetching | Confusing gcTime with freshness; static staleTime blocks invalidation; tests hang on retries |
68| coordinate-dependent-parallel-disabled-and-background-queries | Imperative disabled query; duplicate useQueries keys; full-page spinner on background refetch |
69| paginate-and-build-infinite-queries | Missing initialPageParam; overlapping infinite fetches; broken pages/pageParams shape |
70| write-mutations-and-invalidate-related-queries | Multiple mutate args; per-call callbacks after unmount; not awaiting invalidation |
71| automatic-invalidation-after-mutations | Invalidating whole app for every mutation; not returning invalidation; refetching data that should be static |
72| implement-optimistic-updates-and-cache-writes | Optimistic write without cancellation; in-place mutation; persisted persister loses optimistic write |
73| concurrent-optimistic-updates | One mutation invalidation reverts another optimistic write; filtered list mismatch; unstable pending row keys |
74| query-data-and-forms | Form defaults initialized before query data; background refetch overwrites dirty state; double submit while pending |
75| cancel-queries-and-consume-abort-signals | Ignoring AbortSignal; assuming unmount cancels; Suspense cancellation expected |
76| seed-placeholder-select-and-transform-data | initialData overwrite assumption; v4 keepPreviousData option; throwing in select |
77| selectors-and-derived-state | Effect-based derived-state sync; inline expensive select; throwing from select |
78| shape-data-and-render-efficiently | Rest destructuring; query result object in hook deps; Vue v-model on immutable result |
79| prefetch-and-remove-request-waterfalls | prefetchQuery expected to return data; staleTime only on prefetch; Suspense prefetch in effect |
80| compose-query-with-tanstack-router-and-start | Component-only route waterfall; hand-rolled Router hydration; Next.js mental model copied into Start |
81| ssr-hydration-and-streaming | RSC renders fetched data twice; suspense query not prefetched; SvelteKit query runs after response |
82| use-suspense-and-error-boundaries | Disabled suspense query; missing reset boundary; query.promise without flag |
83| persist-offline-and-restore-caches | gcTime shorter than maxAge; rendering before restore; missing default mutationFn |
84| broadcast-realtime-and-multi-tab-synchronization | Unlocked experimental broadcast; over-normalized realtime writes; broadcast on server |
85| use-framework-adapter-reactivity | Vue ref unwrapped; Svelte store syntax in v6; Angular Observable returned directly |
86| debug-with-devtools | Eager production devtools; mock offline misconception; devtools outside provider |
87| test-query-code | Shared test client; retry backoff in tests; asserting before async success |
88| migrate-major-versions-and-codemods | v4 overload syntax; removed query callbacks; cacheTime in v5 |
89| enforce-query-best-practices-with-eslint | Strict rule not enabled; infinite option order; mutation option order |
90β
91## Tensions
92β
93| Tension | Skills | Agent implication |
94| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
95| Declarative cache versus imperative fetch control | coordinate-dependent-parallel-disabled-and-background-queries <-> fetch-and-observe-queries | Agents generate manual refetch flows instead of key and enabled-driven queries. |
96| SSR freshness versus user data isolation | setup-query-client-and-providers <-> compose-query-with-tanstack-router-and-start <-> ssr-hydration-and-streaming <-> tune-defaults-freshness-retries-and-refetching | Agents leak server cache or double-fetch after hydration. |
97| Router-owned loading versus component-only queries | prefetch-and-remove-request-waterfalls <-> compose-query-with-tanstack-router-and-start <-> ssr-hydration-and-streaming <-> understand-query-internals-and-observers | Agents recreate waterfalls, use loader data as server-state ownership, and bypass Query observer behavior. |
98| Optimistic responsiveness versus server truth | implement-optimistic-updates-and-cache-writes <-> concurrent-optimistic-updates <-> write-mutations-and-invalidate-related-queries <-> persist-offline-and-restore-caches | Agents write optimistic data without cancellation, rollback, invalidation, concurrency guards, or persistence awareness. |
99| Reusable abstractions versus type erasure | design-query-keys-and-options <-> build-query-abstractions <-> selectors-and-derived-state | Agents generate custom hooks or wide options wrappers that cannot run in loaders and break select inference. |
100| Automatic invalidation versus scoped freshness | automatic-invalidation-after-mutations <-> write-mutations-and-invalidate-related-queries <-> tune-defaults-freshness-retries-and-refetching | Agents choose no invalidation or global invalidation without mutation keys, meta, or static-data exclusions. |
101| Form client ownership versus background server freshness | query-data-and-forms <-> selectors-and-derived-state <-> write-mutations-and-invalidate-related-queries | Agents overwrite dirty form fields with refetches or disable useful background updates without acknowledging the tradeoff. |
102| Framework idioms versus copied React examples | use-framework-adapter-reactivity <-> design-query-keys-and-options <-> ssr-hydration-and-streaming | Agents port React examples without preserving adapter reactivity. |
103β
104## Cross-References
105β
106| From | To | Reason |
107| ---------------------------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
108| setup-query-client-and-providers | ssr-hydration-and-streaming | Client lifetime differs between browser and server. |
109| design-query-keys-and-options | enforce-query-best-practices-with-eslint | Lint rules encode key and options mistakes. |
110| design-query-keys-and-options | build-query-abstractions | Options factories are the base abstraction for reusable keys and query functions. |
111| fetch-and-observe-queries | tune-defaults-freshness-retries-and-refetching | Status behavior depends on defaults and network mode. |
112| fetch-and-observe-queries | handle-status-and-errors | Status, fetchStatus, background errors, and throwOnError drive UI behavior. |
113| fetch-and-observe-queries | understand-query-internals-and-observers | Hooks create QueryObservers, while QueryClient reads only inspect cache. |
114| write-mutations-and-invalidate-related-queries | implement-optimistic-updates-and-cache-writes | Optimistic updates are mutation side effects. |
115| write-mutations-and-invalidate-related-queries | automatic-invalidation-after-mutations | App-level invalidation policies build on mutation keys and MutationCache callbacks. |
116| implement-optimistic-updates-and-cache-writes | cancel-queries-and-consume-abort-signals | Optimistic writes often need cancellation first. |
117| implement-optimistic-updates-and-cache-writes | concurrent-optimistic-updates | Concurrent writes need submittedAt identity, mutationKey scoping, and guarded invalidation. |
118| seed-placeholder-select-and-transform-data | ssr-hydration-and-streaming | initialData has SSR tradeoffs compared to hydration. |
119| seed-placeholder-select-and-transform-data | selectors-and-derived-state | select is both a transformation hook and a fine-grained subscription mechanism. |
120| selectors-and-derived-state | query-data-and-forms | Forms often need derived server-plus-client state instead of effect-based synchronization. |
121| build-query-abstractions | selectors-and-derived-state | Query abstractions should preserve usage-site select inference. |
122| prefetch-and-remove-request-waterfalls | compose-query-with-tanstack-router-and-start | Router and Start loaders are the highest-priority route prefetch surface in the TanStack ecosystem. |
123| compose-query-with-tanstack-router-and-start | ssr-hydration-and-streaming | Router SSR Query integration owns cache handoff and streamed query results. |
124| compose-query-with-tanstack-router-and-start | use-suspense-and-error-boundaries | Suspense queries and loader prefetches participate in Router SSR/streaming differently than plain useQuery. |
125| shape-data-and-render-efficiently | enforce-query-best-practices-with-eslint | Lint rules protect tracked render behavior. |
126| persist-offline-and-restore-caches | tune-defaults-freshness-retries-and-refetching | Persistence depends on gcTime, networkMode, and retry. |
127| use-framework-adapter-reactivity | design-query-keys-and-options | Adapter reactivity usually flows through keys and option thunks. |
128| migrate-major-versions-and-codemods | design-query-keys-and-options | v5 changed hooks and client methods to object options. |
129β
130## Subsystems & Reference Candidates
131β
132| Skill | Subsystems | Reference candidates |
133| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
134| design-query-keys-and-options | framework option helpers | queryOptions/infiniteQueryOptions/mutationOptions per adapter |
135| build-query-abstractions | queryOptions factories, custom hook wrappers, TypeScript inference | wrong/correct abstraction examples from TKDodo #31 |
136| understand-query-internals-and-observers | QueryClient, QueryCache, Query, QueryObserver, MutationCache | active/inactive observer mental model |
137| handle-status-and-errors | status, fetchStatus, throwOnError, QueryCache callbacks | stale-data-first status recipes and background error toast policies |
138| query-data-and-forms | form initial values, dirty state, mutation submit/reset | initial-only versus derived-state form recipes |
139| automatic-invalidation-after-mutations | MutationCache, mutationKey, meta, matchQuery | global invalidation policies and static-data exclusions |
140| concurrent-optimistic-updates | submittedAt, mutationKey, isMutating, useMutationState | concurrent rollback and over-invalidation recipes |
141| selectors-and-derived-state | select, stable selectors, structural sharing, derived client state | selector identity and render-time derivation recipes |
142| compose-query-with-tanstack-router-and-start | TanStack Start, TanStack Router, Router SSR Query integration | route loader, router context QueryClient, setupRouterSsrQueryIntegration, Start server function references |
143| ssr-hydration-and-streaming | TanStack Start, TanStack Router SSR Query, Next pages, Next app router, Nuxt, SvelteKit, SolidStart, Lit SSR | dehydrate/hydrate recipes by framework |
144| persist-offline-and-restore-caches | async persister, sync persister, fine-grained persister, framework providers | persister storage and retry interfaces |
145| use-framework-adapter-reactivity | React/Preact, Vue, Solid, Svelte, Angular, Lit | adapter mapping tables and reactivity rules |
146| debug-with-devtools | React, Preact, Vue, Solid, Svelte, Angular | import paths and production-lazy setup |
147| enforce-query-best-practices-with-eslint | recommended, recommended-strict, custom rules | rule-specific wrong/correct examples |
148β
149## Recommended Skill File Structure
150β
151- Core skills: `design-query-keys-and-options`, `build-query-abstractions`, `understand-query-internals-and-observers`, `fetch-and-observe-queries`, `tune-defaults-freshness-retries-and-refetching`, `coordinate-dependent-parallel-disabled-and-background-queries`, `paginate-and-build-infinite-queries`, `write-mutations-and-invalidate-related-queries`, `implement-optimistic-updates-and-cache-writes`, `concurrent-optimistic-updates`, `cancel-queries-and-consume-abort-signals`, `seed-placeholder-select-and-transform-data`, `selectors-and-derived-state`.
152- Framework skills: `handle-status-and-errors`, `use-framework-adapter-reactivity`, `shape-data-and-render-efficiently`, `use-suspense-and-error-boundaries`, `debug-with-devtools`.
153- Lifecycle skills: `setup-query-client-and-providers`, `prefetch-and-remove-request-waterfalls`, `ssr-hydration-and-streaming`, `test-query-code`, `migrate-major-versions-and-codemods`.
154- Composition skills: `compose-query-with-tanstack-router-and-start`, `query-data-and-forms`, `automatic-invalidation-after-mutations`, `persist-offline-and-restore-caches`, `broadcast-realtime-and-multi-tab-synchronization`, `enforce-query-best-practices-with-eslint`.
155- Reference files: per-adapter API mapping, SSR recipes, persistence recipes, ESLint rule examples, migration wrong/correct pairs, TKDodo source index.
156β
157## Composition Opportunities
158β
159| Library | Integration points | Composition skill needed? |
160| ----------------------------------- | -------------------------------------------------------------------------- | ------------------------- |
161| TanStack Start | routes, server functions, SSR, streaming, Query integration via Router | yes |
162| TanStack Router | route loaders, prefetch, cache handoff, `@tanstack/react-router-ssr-query` | yes |
163| React Router | loaders and query cache seeding | yes |
164| Next.js | app router, pages router, streaming | yes |
165| Remix | loaders and hydration | yes |
166| Nuxt | Vue Query SSR plugin and onServerPrefetch | yes |
167| SvelteKit | load functions, browser gating, prefetchQuery | yes |
168| SolidStart | SSR and route-level prefetch | yes |
169| Angular HttpClient | Observable to Promise conversion | yes |
170| GraphQL clients | queryFn and cancellation integration | maybe |
171| WebSocket clients | event-driven invalidation and cache updates | maybe |
172| AsyncStorage/localStorage/IndexedDB | persister storage backends | yes |
173β
174## Source Priority Notes
175β
176- In-repo docs read: all 493 markdown files under `docs/`, plus root README and package manifests.
177- Published docs priority source: `docs/config.json`, especially the `Guides & Concepts` order.
178- TKDodo priority source: React Query series order on `https://tkdodo.eu/blog/tan-stack-router-and-query` now lists 33 parts, with "TanStack Router and Query" as #32. Cross-checked gaps are recorded in `_artifacts/tkdodo_cross_check.md`.
179β
180## Remaining Gaps
181β
182| Skill | Question | Status |
183| ------------------------------------------------ | -------------------------------------------------------------------------------------------------- | ------ |
184| compose-query-with-tanstack-router-and-start | Should this composition skill be generated in Query, Router, Start, or all three with cross-links? | open |
185| broadcast-realtime-and-multi-tab-synchronization | Which realtime patterns should be blessed as skills versus examples only? | open |
186| use-framework-adapter-reactivity | Cross-framework skill with references, or package-local adapter skills? | open |
187| ssr-hydration-and-streaming | Include or exclude experimental streamed APIs? | open |
188| migrate-major-versions-and-codemods | How far back should generated migration skills go? | open |
189| enforce-query-best-practices-with-eslint | Should ESLint skills be React-only or cross-adapter where rules apply? | open |