CodeVetter · Repo Unpack · Data flow
TanStack/query
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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.