Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

dehydrateSettled.md

71 lines2.8 KB

function dehydrateSettled(client: QueryClient, options?: DehydrateOptions): Promise<DehydratedState>;

Defined in: packages/solid-query/src/dehydrateSettled.ts:31

Waits for every fetch the client has in flight to settle, then dehydrates. This is the extraction half of a single-flight collector: after route data functions run for the mutation's target URL, loaders commonly kick off prefetches without awaiting them β€” plain dehydrate() would snapshot those mid-fetch and ship nothing.

registerFlightDataSource(FLIGHT_DATA_SOURCE, (event, outcome) =>
  loadFlightTarget({
    router,
    event,
    outcome,
    collect: () => dehydrateSettled(queryClient),
  }),
)

Settling is chased to quiescence β€” awaiting one batch of fetches can dispatch more (dependent queries keyed off a first result) β€” so an unconditionally self-refetching query would keep this pending; that's an app bug mirrored, not guarded.

Parameters

client

QueryClient

The QueryClient whose cache is dehydrated.

options?

DehydrateOptions

The DehydrateOptions forwarded to dehydrate.

options properties

PropertyTypeDescription
serializeData?TransformerFnTransforms a query's data before it is dehydrated. Useful for non-JSON-serializable data.
shouldDehydrateMutation?(mutation: Mutation) => booleanPredicate to decide whether a given Mutation should be dehydrated. Defaults to defaultShouldDehydrateMutation.
shouldDehydrateQuery?(query: Query) => booleanPredicate to decide whether a given Query should be dehydrated. Defaults to defaultShouldDehydrateQuery.
shouldRedactErrors?(error: unknown) => booleanPredicate to decide whether a query's error should be redacted before dehydration. Errors are redacted (replaced with a generic Error('redacted')) unless this function is provided and returns false for the given error, in which case the original error is kept.

Returns

Promise<DehydratedState>

A promise for the dehydrated state, taken once no fetch is in flight.

Result properties

Built from DehydratedState. See the type above for what it changes.