MCPcopy
hub / github.com/TanStack/query / onHydrated

Function onHydrated

packages/solid-query/src/useBaseQuery.ts:285–310  ·  view source on GitHub ↗

* If this resource was populated on the server (either sync render, or streamed in over time), onHydrated * will be called. This is the point at which we can hydrate the query cache state, and setup the query subscriber. * * Leveraging onHydrated allows us to plug into the async

(_k, info)

Source from the content-addressed store, hash-verified

283 * Note that this is only invoked on the client, for queries that were originally run on the server.
284 */
285 onHydrated(_k, info) {
286 if (info.value && 'hydrationData' in info.value) {
287 hydrate(client(), {
288 // @ts-expect-error - hydrationData is not correctly typed internally
289 queries: [{ ...info.value.hydrationData }],
290 })
291 }
292
293 if (unsubscribe) return
294 /**
295 * Do not refetch query on mount if query was fetched on server,
296 * even if `staleTime` is not set.
297 */
298 const newOptions = { ...initialOptions }
299 if (
300 (initialOptions.staleTime || !initialOptions.initialData) &&
301 info.value
302 ) {
303 newOptions.refetchOnMount = false
304 }
305 // Setting the options as an immutable object to prevent
306 // wonky behavior with observer subscriptions
307 observer().setOptions(newOptions)
308 setStateWithReconciliation(observer().getOptimisticResult(newOptions))
309 unsubscribe = createClientSubscriber()
310 },
311 },
312 )
313

Callers

nothing calls this directly

Calls 5

hydrateFunction · 0.90
createClientSubscriberFunction · 0.85
setOptionsMethod · 0.45
getOptimisticResultMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…