Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

skill_spec.md

189 lines34.9 KB

TanStack Query - Skill Spec

TanStack 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.

TanStack 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.

The maintainer skipped live interviews, so unresolved judgment calls remain in the gaps section.

Domains

DomainDescriptionSkills
Bootstrapping query clientsCreating stable clients and provider contextsetup-query-client-and-providers
Reading server stateDeclaring reads, query identity, observers, status, and reusable abstractionsdesign-query-keys-and-options, build-query-abstractions, understand-query-internals-and-observers, fetch-and-observe-queries, handle-status-and-errors
Coordinating query executionDependency, freshness, retries, pagination, prefetchtune-defaults-freshness-retries-and-refetching, coordinate-dependent-parallel-disabled-and-background-queries, paginate-and-build-infinite-queries
Writing server stateMutations, invalidation, optimistic writes, forms, cancellationwrite-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
Shaping cache and render behaviorSeeded data, placeholders, selectors, derived state, render performanceseed-placeholder-select-and-transform-data, selectors-and-derived-state, shape-data-and-render-efficiently
Rendering across environmentsSSR, hydration, Suspense, streaming, routersprefetch-and-remove-request-waterfalls, compose-query-with-tanstack-router-and-start, ssr-hydration-and-streaming, use-suspense-and-error-boundaries
Persisting and synchronizing cachesPersistence, offline, multi-tab, realtimepersist-offline-and-restore-caches, broadcast-realtime-and-multi-tab-synchronization
Framework adapter idiomsReactivity and provider rules across adaptersuse-framework-adapter-reactivity
Operational qualityDevtools, testing, migration, lintingdebug-with-devtools, test-query-code, migrate-major-versions-and-codemods, enforce-query-best-practices-with-eslint

Skill Inventory

SkillTypeDomainWhat it coversFailure modes
Set up QueryClient and providerslifecycleBootstrapping query clientsQueryClient, providers, SSR isolation, Lit fallback3
Design query keys and reusable optionscoreReading server statequeryKey, queryFn, queryOptions, skipToken3
Build Query abstractionscoreReading server statequeryOptions factories, custom hooks, usage-site composition, TypeScript inference3
Understand Query internals and observerscoreReading server stateQueryClient, QueryCache, QueryObserver, active/inactive queries3
Fetch and observe queriescoreReading server stateuseQuery/createQuery/injectQuery, status, fetchStatus3
Handle status checks and errorsframeworkReading server statestatus, fetchStatus, background errors, throwOnError, cache-level callbacks3
Tune defaults, freshness, retries, and refetchingcoreCoordinating query executionstaleTime, gcTime, retry, refetch triggers, networkMode3
Coordinate dependent, parallel, disabled, and background queriescoreCoordinating query executionuseQueries, enabled, skipToken, background fetching3
Paginate and build infinite queriescoreCoordinating query executionpagination, infinite queries, maxPages3
Write mutations and invalidate related queriescoreWriting server statemutations, invalidation, mutation state3
Automatic invalidation after mutationscompositionWriting server stateMutationCache callbacks, mutationKey invalidation, meta tags, scoped invalidation3
Implement optimistic updates and cache writescoreWriting server stateonMutate, rollback, setQueryData3
Concurrent optimistic updatescoreWriting server statesubmittedAt, mutationKey filters, isMutating guards, filtered optimistic lists3
Query data and formscompositionWriting server stateinitial form state, dirty fields, derived server/client state, reset after invalidation3
Cancel queries and consume AbortSignalscoreWriting server stateAbortSignal, cancelQueries, CancelledError3
Seed, placeholder, select, and transform datacoreShaping cache and render behaviorinitialData, placeholderData, select3
Selectors and derived statecoreShaping cache and render behaviorselect, selector identity, structural sharing, render-time derivation3
Shape data and render efficientlyframeworkShaping cache and render behaviorstructural sharing, tracked props, immutable data3
Prefetch and remove request waterfallslifecycleRendering across environmentsprefetchQuery, router loaders, waterfalls3
Compose TanStack Query with TanStack Router and StartcompositionRendering across environmentsrouter context, loaders, @tanstack/react-router-ssr-query, Start SSR/streaming3
SSR, hydration, and streaminglifecycleRendering across environmentsdehydrate/hydrate, Start, Router SSR Query, RSC, SvelteKit, Nuxt3
Use Suspense and error boundariesframeworkRendering across environmentssuspense hooks, QueryErrorResetBoundary, React.use3
Persist offline and restore cachescompositionPersisting and synchronizing cachespersistQueryClient, persisters, restore races3
Broadcast, realtime, and multi-tab synchronizationcompositionPersisting and synchronizing cachesbroadcastQueryClient, WebSockets, realtime invalidation3
Use framework adapter reactivityframeworkFramework adapter idiomsVue refs, Svelte runes, Angular signals, Lit controllers3
Debug with devtoolsframeworkOperational qualityframework devtools, embedded panels, production imports3
Test query codelifecycleOperational qualitytest clients, retry false, cache isolation3
Migrate major versions and codemodslifecycleOperational qualityv5 object syntax, renamed options, Svelte v63
Enforce Query best practices with ESLintcompositionOperational qualityrecommended configs and Query-specific rules3

Failure Mode Inventory

SkillHigh-priority examples
setup-query-client-and-providersNew client on every render; shared SSR cache between users; ambiguous Lit fallback client
design-query-keys-and-optionsMissing variables in query key; separated key/queryFn drift; skipToken inside suspense query
build-query-abstractionsCustom hook is the only abstraction; wide UseQueryOptions wrapper breaks inference; wrapper hides Query result state
understand-query-internals-and-observersCache presence treated as active usage; observer-level options ignored; inactive queries expected to refetch like mounted queries
fetch-and-observe-queriesVoid query function; only checking pending for offline state; using queries for writes
handle-status-and-errorsStale data hidden on background error; validation errors sent to global boundary; duplicate toasts per observer
tune-defaults-freshness-retries-and-refetchingConfusing gcTime with freshness; static staleTime blocks invalidation; tests hang on retries
coordinate-dependent-parallel-disabled-and-background-queriesImperative disabled query; duplicate useQueries keys; full-page spinner on background refetch
paginate-and-build-infinite-queriesMissing initialPageParam; overlapping infinite fetches; broken pages/pageParams shape
write-mutations-and-invalidate-related-queriesMultiple mutate args; per-call callbacks after unmount; not awaiting invalidation
automatic-invalidation-after-mutationsInvalidating whole app for every mutation; not returning invalidation; refetching data that should be static
implement-optimistic-updates-and-cache-writesOptimistic write without cancellation; in-place mutation; persisted persister loses optimistic write
concurrent-optimistic-updatesOne mutation invalidation reverts another optimistic write; filtered list mismatch; unstable pending row keys
query-data-and-formsForm defaults initialized before query data; background refetch overwrites dirty state; double submit while pending
cancel-queries-and-consume-abort-signalsIgnoring AbortSignal; assuming unmount cancels; Suspense cancellation expected
seed-placeholder-select-and-transform-datainitialData overwrite assumption; v4 keepPreviousData option; throwing in select
selectors-and-derived-stateEffect-based derived-state sync; inline expensive select; throwing from select
shape-data-and-render-efficientlyRest destructuring; query result object in hook deps; Vue v-model on immutable result
prefetch-and-remove-request-waterfallsprefetchQuery expected to return data; staleTime only on prefetch; Suspense prefetch in effect
compose-query-with-tanstack-router-and-startComponent-only route waterfall; hand-rolled Router hydration; Next.js mental model copied into Start
ssr-hydration-and-streamingRSC renders fetched data twice; suspense query not prefetched; SvelteKit query runs after response
use-suspense-and-error-boundariesDisabled suspense query; missing reset boundary; query.promise without flag
persist-offline-and-restore-cachesgcTime shorter than maxAge; rendering before restore; missing default mutationFn
broadcast-realtime-and-multi-tab-synchronizationUnlocked experimental broadcast; over-normalized realtime writes; broadcast on server
use-framework-adapter-reactivityVue ref unwrapped; Svelte store syntax in v6; Angular Observable returned directly
debug-with-devtoolsEager production devtools; mock offline misconception; devtools outside provider
test-query-codeShared test client; retry backoff in tests; asserting before async success
migrate-major-versions-and-codemodsv4 overload syntax; removed query callbacks; cacheTime in v5
enforce-query-best-practices-with-eslintStrict rule not enabled; infinite option order; mutation option order

Tensions

TensionSkillsAgent implication
Declarative cache versus imperative fetch controlcoordinate-dependent-parallel-disabled-and-background-queries <-> fetch-and-observe-queriesAgents generate manual refetch flows instead of key and enabled-driven queries.
SSR freshness versus user data isolationsetup-query-client-and-providers <-> compose-query-with-tanstack-router-and-start <-> ssr-hydration-and-streaming <-> tune-defaults-freshness-retries-and-refetchingAgents leak server cache or double-fetch after hydration.
Router-owned loading versus component-only queriesprefetch-and-remove-request-waterfalls <-> compose-query-with-tanstack-router-and-start <-> ssr-hydration-and-streaming <-> understand-query-internals-and-observersAgents recreate waterfalls, use loader data as server-state ownership, and bypass Query observer behavior.
Optimistic responsiveness versus server truthimplement-optimistic-updates-and-cache-writes <-> concurrent-optimistic-updates <-> write-mutations-and-invalidate-related-queries <-> persist-offline-and-restore-cachesAgents write optimistic data without cancellation, rollback, invalidation, concurrency guards, or persistence awareness.
Reusable abstractions versus type erasuredesign-query-keys-and-options <-> build-query-abstractions <-> selectors-and-derived-stateAgents generate custom hooks or wide options wrappers that cannot run in loaders and break select inference.
Automatic invalidation versus scoped freshnessautomatic-invalidation-after-mutations <-> write-mutations-and-invalidate-related-queries <-> tune-defaults-freshness-retries-and-refetchingAgents choose no invalidation or global invalidation without mutation keys, meta, or static-data exclusions.
Form client ownership versus background server freshnessquery-data-and-forms <-> selectors-and-derived-state <-> write-mutations-and-invalidate-related-queriesAgents overwrite dirty form fields with refetches or disable useful background updates without acknowledging the tradeoff.
Framework idioms versus copied React examplesuse-framework-adapter-reactivity <-> design-query-keys-and-options <-> ssr-hydration-and-streamingAgents port React examples without preserving adapter reactivity.

Cross-References

FromToReason
setup-query-client-and-providersssr-hydration-and-streamingClient lifetime differs between browser and server.
design-query-keys-and-optionsenforce-query-best-practices-with-eslintLint rules encode key and options mistakes.
design-query-keys-and-optionsbuild-query-abstractionsOptions factories are the base abstraction for reusable keys and query functions.
fetch-and-observe-queriestune-defaults-freshness-retries-and-refetchingStatus behavior depends on defaults and network mode.
fetch-and-observe-querieshandle-status-and-errorsStatus, fetchStatus, background errors, and throwOnError drive UI behavior.
fetch-and-observe-queriesunderstand-query-internals-and-observersHooks create QueryObservers, while QueryClient reads only inspect cache.
write-mutations-and-invalidate-related-queriesimplement-optimistic-updates-and-cache-writesOptimistic updates are mutation side effects.
write-mutations-and-invalidate-related-queriesautomatic-invalidation-after-mutationsApp-level invalidation policies build on mutation keys and MutationCache callbacks.
implement-optimistic-updates-and-cache-writescancel-queries-and-consume-abort-signalsOptimistic writes often need cancellation first.
implement-optimistic-updates-and-cache-writesconcurrent-optimistic-updatesConcurrent writes need submittedAt identity, mutationKey scoping, and guarded invalidation.
seed-placeholder-select-and-transform-datassr-hydration-and-streaminginitialData has SSR tradeoffs compared to hydration.
seed-placeholder-select-and-transform-dataselectors-and-derived-stateselect is both a transformation hook and a fine-grained subscription mechanism.
selectors-and-derived-statequery-data-and-formsForms often need derived server-plus-client state instead of effect-based synchronization.
build-query-abstractionsselectors-and-derived-stateQuery abstractions should preserve usage-site select inference.
prefetch-and-remove-request-waterfallscompose-query-with-tanstack-router-and-startRouter and Start loaders are the highest-priority route prefetch surface in the TanStack ecosystem.
compose-query-with-tanstack-router-and-startssr-hydration-and-streamingRouter SSR Query integration owns cache handoff and streamed query results.
compose-query-with-tanstack-router-and-startuse-suspense-and-error-boundariesSuspense queries and loader prefetches participate in Router SSR/streaming differently than plain useQuery.
shape-data-and-render-efficientlyenforce-query-best-practices-with-eslintLint rules protect tracked render behavior.
persist-offline-and-restore-cachestune-defaults-freshness-retries-and-refetchingPersistence depends on gcTime, networkMode, and retry.
use-framework-adapter-reactivitydesign-query-keys-and-optionsAdapter reactivity usually flows through keys and option thunks.
migrate-major-versions-and-codemodsdesign-query-keys-and-optionsv5 changed hooks and client methods to object options.

Subsystems & Reference Candidates

SkillSubsystemsReference candidates
design-query-keys-and-optionsframework option helpersqueryOptions/infiniteQueryOptions/mutationOptions per adapter
build-query-abstractionsqueryOptions factories, custom hook wrappers, TypeScript inferencewrong/correct abstraction examples from TKDodo #31
understand-query-internals-and-observersQueryClient, QueryCache, Query, QueryObserver, MutationCacheactive/inactive observer mental model
handle-status-and-errorsstatus, fetchStatus, throwOnError, QueryCache callbacksstale-data-first status recipes and background error toast policies
query-data-and-formsform initial values, dirty state, mutation submit/resetinitial-only versus derived-state form recipes
automatic-invalidation-after-mutationsMutationCache, mutationKey, meta, matchQueryglobal invalidation policies and static-data exclusions
concurrent-optimistic-updatessubmittedAt, mutationKey, isMutating, useMutationStateconcurrent rollback and over-invalidation recipes
selectors-and-derived-stateselect, stable selectors, structural sharing, derived client stateselector identity and render-time derivation recipes
compose-query-with-tanstack-router-and-startTanStack Start, TanStack Router, Router SSR Query integrationroute loader, router context QueryClient, setupRouterSsrQueryIntegration, Start server function references
ssr-hydration-and-streamingTanStack Start, TanStack Router SSR Query, Next pages, Next app router, Nuxt, SvelteKit, SolidStart, Lit SSRdehydrate/hydrate recipes by framework
persist-offline-and-restore-cachesasync persister, sync persister, fine-grained persister, framework providerspersister storage and retry interfaces
use-framework-adapter-reactivityReact/Preact, Vue, Solid, Svelte, Angular, Litadapter mapping tables and reactivity rules
debug-with-devtoolsReact, Preact, Vue, Solid, Svelte, Angularimport paths and production-lazy setup
enforce-query-best-practices-with-eslintrecommended, recommended-strict, custom rulesrule-specific wrong/correct examples
  • 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.
  • Framework skills: handle-status-and-errors, use-framework-adapter-reactivity, shape-data-and-render-efficiently, use-suspense-and-error-boundaries, debug-with-devtools.
  • Lifecycle skills: setup-query-client-and-providers, prefetch-and-remove-request-waterfalls, ssr-hydration-and-streaming, test-query-code, migrate-major-versions-and-codemods.
  • 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.
  • Reference files: per-adapter API mapping, SSR recipes, persistence recipes, ESLint rule examples, migration wrong/correct pairs, TKDodo source index.

Composition Opportunities

LibraryIntegration pointsComposition skill needed?
TanStack Startroutes, server functions, SSR, streaming, Query integration via Routeryes
TanStack Routerroute loaders, prefetch, cache handoff, @tanstack/react-router-ssr-queryyes
React Routerloaders and query cache seedingyes
Next.jsapp router, pages router, streamingyes
Remixloaders and hydrationyes
NuxtVue Query SSR plugin and onServerPrefetchyes
SvelteKitload functions, browser gating, prefetchQueryyes
SolidStartSSR and route-level prefetchyes
Angular HttpClientObservable to Promise conversionyes
GraphQL clientsqueryFn and cancellation integrationmaybe
WebSocket clientsevent-driven invalidation and cache updatesmaybe
AsyncStorage/localStorage/IndexedDBpersister storage backendsyes

Source Priority Notes

  • In-repo docs read: all 493 markdown files under docs/, plus root README and package manifests.
  • Published docs priority source: docs/config.json, especially the Guides & Concepts order.
  • 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.

Remaining Gaps

SkillQuestionStatus
compose-query-with-tanstack-router-and-startShould this composition skill be generated in Query, Router, Start, or all three with cross-links?open
broadcast-realtime-and-multi-tab-synchronizationWhich realtime patterns should be blessed as skills versus examples only?open
use-framework-adapter-reactivityCross-framework skill with references, or package-local adapter skills?open
ssr-hydration-and-streamingInclude or exclude experimental streamed APIs?open
migrate-major-versions-and-codemodsHow far back should generated migration skills go?open
enforce-query-best-practices-with-eslintShould ESLint skills be React-only or cross-adapter where rules apply?open