MCPcopy Create free account
hub / github.com/TanStack/query / onHydrated

Function onHydrated

packages/solid-query/src/useBaseQuery.ts:286–311  ·  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

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected