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

Function onHydrated

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

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

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