# Data flow — TanStack/query

> Canonical page: https://codevetter.com/unpack/query/data-flow

# Data flow — TanStack/query

Scanned commit 29859ae60c8dca0a5cdbf8abccc775b655cf43e2 (2026-10-02). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Keys and options enter through adapters or QueryClient methods and resolve into shared cache entries. Application callbacks produce raw data, while observers derive presentation results and notify framework subscribers. Mutations retain variables and optimistic context separately from query data. Hydration, persistence, and broadcast transfer snapshots across explicit external boundaries.
- defaultQueryOptions merges client query defaults, matching key defaults, and caller options in that order; it computes a missing queryHash and derives reconnect, Suspense-error, persister-network, and skipToken defaults. — [packages/query-core/src/queryClient.ts#L1024-L1053](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/queryClient.ts#L1024-L1053)
- hashQueryKeyByOptions chooses queryKeyHashFn or hashKey; the default hash JSON-stringifies keys with sorted plain-object properties, and QueryCache.build reuses an entry by that hash. — [packages/query-core/src/utils.ts#L267-L295](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/utils.ts#L267-L295) [packages/query-core/src/queryCache.ts#L159-L177](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/queryCache.ts#L159-L177)
- Query.fetch constructs callback context containing client, queryKey, meta, and a consumed-signal getter; an optional persister wraps queryFn and a behavior hook can replace fetchFn before retry execution. — [packages/query-core/src/query.ts#L634-L712](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/query.ts#L634-L712)
- Successful fetch data passes through replaceData and a success dispatch; the reducer updates timestamps and status, then notifies a stable observer snapshot and cache subscribers. — [packages/query-core/src/query.ts#L312-L326](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/query.ts#L312-L326) [packages/query-core/src/query.ts#L848-L863](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/query.ts#L848-L863) [packages/query-core/src/query.ts#L892-L902](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/query.ts#L892-L902) [packages/query-core/src/utils.ts#L460-L482](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/utils.ts#L460-L482)
- QueryObserver derives placeholder and selected data without replacing raw query state; select results are memoized, selector exceptions become observer errors, and property tracking filters listener notifications. — [packages/query-core/src/queryObserver.ts#L610-L684](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/queryObserver.ts#L610-L684) [packages/query-core/src/queryObserver.ts#L753-L784](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/queryObserver.ts#L753-L784)
- MutationObserver.mutate builds a new Mutation for supplied variables; Mutation.execute stores the onMutate result as context and supplies variables, context, and function metadata to lifecycle callbacks. — [packages/query-core/src/mutationObserver.ts#L207-L221](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/mutationObserver.ts#L207-L221) [packages/query-core/src/mutation.ts#L289-L345](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/mutation.ts#L289-L345) [packages/query-core/src/mutation.ts#L348-L380](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-core/src/mutation.ts#L348-L380)
- persistQueryClientSave packages buster, timestamp, and dehydrated state; the async storage adapter serializes that envelope and writes it through caller-provided storage, while restore reads and deserializes the same key. — [packages/query-persist-client-core/src/persist.ts#L113-L125](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-persist-client-core/src/persist.ts#L113-L125) [packages/query-async-storage-persister/src/index.ts#L42-L59](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-async-storage-persister/src/index.ts#L42-L59) [packages/query-async-storage-persister/src/index.ts#L84-L94](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-async-storage-persister/src/index.ts#L84-L94)
- Broadcast sends successful updates, additions, and removals with observers; incoming messages set or build query state inside an echo-suppression transaction, and cleanup unsubscribes and closes the channel. — [packages/query-broadcast-client-experimental/src/index.ts#L112-L146](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-broadcast-client-experimental/src/index.ts#L112-L146) [packages/query-broadcast-client-experimental/src/index.ts#L148-L197](https://github.com/TanStack/query/blob/29859ae60c8dca0a5cdbf8abccc775b655cf43e2/packages/query-broadcast-client-experimental/src/index.ts#L148-L197)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
