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

Function onHydrated

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

316 * @param info - The hydrated resource value, which carries the query's `hydrationData`.
317 */
318 onHydrated(_k, info) {
319 if (info.value && 'hydrationData' in info.value) {
320 hydrate(client(), {
321 // @ts-expect-error - hydrationData is not correctly typed internally
322 queries: [{ ...info.value.hydrationData }],
323 })
324 }
325
326 if (unsubscribe) return
327 /**
328 * Do not refetch query on mount if query was fetched on server,
329 * even if `staleTime` is not set.
330 */
331 const newOptions = { ...initialOptions }
332 if (
333 (initialOptions.staleTime || !initialOptions.initialData) &&
334 info.value
335 ) {
336 newOptions.refetchOnMount = false
337 }
338 // Setting the options as an immutable object to prevent
339 // wonky behavior with observer subscriptions
340 observer().setOptions(newOptions)
341 setStateWithReconciliation(observer().getOptimisticResult(newOptions))
342 unsubscribe = createClientSubscriber()
343 },
344 },
345 )
346

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