From bb2d79a6e2b859b8322a485c19571e524ea59bf4 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sun, 4 Oct 2026 02:54:47 +0900 Subject: [PATCH] docs(query-core/hydration): add missing JSDoc to dehydration and hydration functions (#11835) * docs(query-core/hydration): add missing JSDoc to dehydration and hydration functions * docs(framework/*/reference): regenerate reference docs --- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../angular/reference/functions/dehydrate.md | 9 ++++- .../reference/functions/dehydrateQuery.md | 4 ++- .../angular/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../lit/reference/functions/dehydrate.md | 9 ++++- .../lit/reference/functions/dehydrateQuery.md | 4 ++- .../lit/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../preact/reference/functions/dehydrate.md | 9 ++++- .../reference/functions/dehydrateQuery.md | 4 ++- .../preact/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../react/reference/functions/dehydrate.md | 9 ++++- .../reference/functions/dehydrateQuery.md | 4 ++- .../react/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../solid/reference/functions/dehydrate.md | 9 ++++- .../reference/functions/dehydrateQuery.md | 4 ++- .../solid/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../svelte/reference/functions/dehydrate.md | 9 ++++- .../reference/functions/dehydrateQuery.md | 4 ++- .../svelte/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- .../defaultShouldDehydrateMutation.md | 6 +++- .../functions/defaultShouldDehydrateQuery.md | 6 +++- .../vue/reference/functions/dehydrate.md | 9 ++++- .../vue/reference/functions/dehydrateQuery.md | 4 ++- .../vue/reference/functions/hydrate.md | 9 ++++- .../reference/interfaces/DehydrateOptions.md | 2 +- .../reference/interfaces/DehydratedState.md | 2 +- .../reference/interfaces/HydrateOptions.md | 2 +- packages/query-core/src/hydration.ts | 35 +++++++++++++++++++ 57 files changed, 259 insertions(+), 56 deletions(-) diff --git a/docs/framework/angular/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/angular/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/angular/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/angular/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/angular/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/angular/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/angular/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/angular/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/angular/reference/functions/dehydrate.md b/docs/framework/angular/reference/functions/dehydrate.md index 201200efdf..a1db7e198e 100644 --- a/docs/framework/angular/reference/functions/dehydrate.md +++ b/docs/framework/angular/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul [`QueryClient`](../classes/QueryClient.md) +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/angular/reference/functions/dehydrateQuery.md b/docs/framework/angular/reference/functions/dehydrateQuery.md index 0dcd090469..bd80050e86 100644 --- a/docs/framework/angular/reference/functions/dehydrateQuery.md +++ b/docs/framework/angular/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/angular/reference/functions/hydrate.md b/docs/framework/angular/reference/functions/hydrate.md index 435603b3af..e3aa5d5a42 100644 --- a/docs/framework/angular/reference/functions/hydrate.md +++ b/docs/framework/angular/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm [`QueryClient`](../classes/QueryClient.md) +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/angular/reference/interfaces/DehydrateOptions.md b/docs/framework/angular/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/angular/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/angular/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/angular/reference/interfaces/DehydratedState.md b/docs/framework/angular/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/angular/reference/interfaces/DehydratedState.md +++ b/docs/framework/angular/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/angular/reference/interfaces/HydrateOptions.md b/docs/framework/angular/reference/interfaces/HydrateOptions.md index eccc9b8b51..e652f3b764 100644 --- a/docs/framework/angular/reference/interfaces/HydrateOptions.md +++ b/docs/framework/angular/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/docs/framework/lit/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/lit/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/lit/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/lit/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/lit/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/lit/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/lit/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/lit/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/lit/reference/functions/dehydrate.md b/docs/framework/lit/reference/functions/dehydrate.md index 201200efdf..a1db7e198e 100644 --- a/docs/framework/lit/reference/functions/dehydrate.md +++ b/docs/framework/lit/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul [`QueryClient`](../classes/QueryClient.md) +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/lit/reference/functions/dehydrateQuery.md b/docs/framework/lit/reference/functions/dehydrateQuery.md index 604105353e..b19fe90867 100644 --- a/docs/framework/lit/reference/functions/dehydrateQuery.md +++ b/docs/framework/lit/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/lit/reference/functions/hydrate.md b/docs/framework/lit/reference/functions/hydrate.md index a8bbe36ede..04afbd8e5a 100644 --- a/docs/framework/lit/reference/functions/hydrate.md +++ b/docs/framework/lit/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm [`QueryClient`](../classes/QueryClient.md) +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/lit/reference/interfaces/DehydrateOptions.md b/docs/framework/lit/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/lit/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/lit/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/lit/reference/interfaces/DehydratedState.md b/docs/framework/lit/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/lit/reference/interfaces/DehydratedState.md +++ b/docs/framework/lit/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/lit/reference/interfaces/HydrateOptions.md b/docs/framework/lit/reference/interfaces/HydrateOptions.md index eccc9b8b51..e652f3b764 100644 --- a/docs/framework/lit/reference/interfaces/HydrateOptions.md +++ b/docs/framework/lit/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/docs/framework/preact/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/preact/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/preact/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/preact/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/preact/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/preact/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/preact/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/preact/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/preact/reference/functions/dehydrate.md b/docs/framework/preact/reference/functions/dehydrate.md index 201200efdf..a1db7e198e 100644 --- a/docs/framework/preact/reference/functions/dehydrate.md +++ b/docs/framework/preact/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul [`QueryClient`](../classes/QueryClient.md) +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/preact/reference/functions/dehydrateQuery.md b/docs/framework/preact/reference/functions/dehydrateQuery.md index 0dcd090469..bd80050e86 100644 --- a/docs/framework/preact/reference/functions/dehydrateQuery.md +++ b/docs/framework/preact/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/preact/reference/functions/hydrate.md b/docs/framework/preact/reference/functions/hydrate.md index 435603b3af..e3aa5d5a42 100644 --- a/docs/framework/preact/reference/functions/hydrate.md +++ b/docs/framework/preact/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm [`QueryClient`](../classes/QueryClient.md) +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/preact/reference/interfaces/DehydrateOptions.md b/docs/framework/preact/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/preact/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/preact/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/preact/reference/interfaces/DehydratedState.md b/docs/framework/preact/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/preact/reference/interfaces/DehydratedState.md +++ b/docs/framework/preact/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/preact/reference/interfaces/HydrateOptions.md b/docs/framework/preact/reference/interfaces/HydrateOptions.md index eccc9b8b51..e652f3b764 100644 --- a/docs/framework/preact/reference/interfaces/HydrateOptions.md +++ b/docs/framework/preact/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/docs/framework/react/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/react/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/react/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/react/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/react/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/react/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/react/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/react/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/react/reference/functions/dehydrate.md b/docs/framework/react/reference/functions/dehydrate.md index 201200efdf..a1db7e198e 100644 --- a/docs/framework/react/reference/functions/dehydrate.md +++ b/docs/framework/react/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul [`QueryClient`](../classes/QueryClient.md) +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/react/reference/functions/dehydrateQuery.md b/docs/framework/react/reference/functions/dehydrateQuery.md index 0dcd090469..bd80050e86 100644 --- a/docs/framework/react/reference/functions/dehydrateQuery.md +++ b/docs/framework/react/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/react/reference/functions/hydrate.md b/docs/framework/react/reference/functions/hydrate.md index 435603b3af..e3aa5d5a42 100644 --- a/docs/framework/react/reference/functions/hydrate.md +++ b/docs/framework/react/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm [`QueryClient`](../classes/QueryClient.md) +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/react/reference/interfaces/DehydrateOptions.md b/docs/framework/react/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/react/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/react/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/react/reference/interfaces/DehydratedState.md b/docs/framework/react/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/react/reference/interfaces/DehydratedState.md +++ b/docs/framework/react/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/react/reference/interfaces/HydrateOptions.md b/docs/framework/react/reference/interfaces/HydrateOptions.md index eccc9b8b51..e652f3b764 100644 --- a/docs/framework/react/reference/interfaces/HydrateOptions.md +++ b/docs/framework/react/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/docs/framework/solid/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/solid/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/solid/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/solid/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/solid/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/solid/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/solid/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/solid/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/solid/reference/functions/dehydrate.md b/docs/framework/solid/reference/functions/dehydrate.md index 782758a438..d4478940b9 100644 --- a/docs/framework/solid/reference/functions/dehydrate.md +++ b/docs/framework/solid/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul `QueryClient` +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/solid/reference/functions/dehydrateQuery.md b/docs/framework/solid/reference/functions/dehydrateQuery.md index 0dcd090469..bd80050e86 100644 --- a/docs/framework/solid/reference/functions/dehydrateQuery.md +++ b/docs/framework/solid/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/solid/reference/functions/hydrate.md b/docs/framework/solid/reference/functions/hydrate.md index 926f21b445..e6ca6a6629 100644 --- a/docs/framework/solid/reference/functions/hydrate.md +++ b/docs/framework/solid/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm `QueryClient` +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/solid/reference/interfaces/DehydrateOptions.md b/docs/framework/solid/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/solid/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/solid/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/solid/reference/interfaces/DehydratedState.md b/docs/framework/solid/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/solid/reference/interfaces/DehydratedState.md +++ b/docs/framework/solid/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/solid/reference/interfaces/HydrateOptions.md b/docs/framework/solid/reference/interfaces/HydrateOptions.md index 5d60315e07..55564a91d7 100644 --- a/docs/framework/solid/reference/interfaces/HydrateOptions.md +++ b/docs/framework/solid/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/docs/framework/svelte/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/svelte/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/svelte/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/svelte/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/svelte/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/svelte/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/svelte/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/svelte/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/svelte/reference/functions/dehydrate.md b/docs/framework/svelte/reference/functions/dehydrate.md index 201200efdf..a1db7e198e 100644 --- a/docs/framework/svelte/reference/functions/dehydrate.md +++ b/docs/framework/svelte/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul [`QueryClient`](../classes/QueryClient.md) +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/svelte/reference/functions/dehydrateQuery.md b/docs/framework/svelte/reference/functions/dehydrateQuery.md index 0dcd090469..bd80050e86 100644 --- a/docs/framework/svelte/reference/functions/dehydrateQuery.md +++ b/docs/framework/svelte/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/svelte/reference/functions/hydrate.md b/docs/framework/svelte/reference/functions/hydrate.md index 435603b3af..e3aa5d5a42 100644 --- a/docs/framework/svelte/reference/functions/hydrate.md +++ b/docs/framework/svelte/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm [`QueryClient`](../classes/QueryClient.md) +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/svelte/reference/interfaces/DehydrateOptions.md b/docs/framework/svelte/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/svelte/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/svelte/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/svelte/reference/interfaces/DehydratedState.md b/docs/framework/svelte/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/svelte/reference/interfaces/DehydratedState.md +++ b/docs/framework/svelte/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/svelte/reference/interfaces/HydrateOptions.md b/docs/framework/svelte/reference/interfaces/HydrateOptions.md index eccc9b8b51..e652f3b764 100644 --- a/docs/framework/svelte/reference/interfaces/HydrateOptions.md +++ b/docs/framework/svelte/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/docs/framework/vue/reference/functions/defaultShouldDehydrateMutation.md b/docs/framework/vue/reference/functions/defaultShouldDehydrateMutation.md index 0458c88f4f..9589748f1b 100644 --- a/docs/framework/vue/reference/functions/defaultShouldDehydrateMutation.md +++ b/docs/framework/vue/reference/functions/defaultShouldDehydrateMutation.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateMutation function defaultShouldDehydrateMutation(mutation: Mutation): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178) +Defined in: [packages/query-core/src/hydration.ts:203](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L203) The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are currently paused (e.g. paused by `networkMode` while offline). @@ -18,6 +18,10 @@ currently paused (e.g. paused by `networkMode` while offline). [`Mutation`](../classes/Mutation.md) +The mutation to check. + ## Returns `boolean` + +`true` if the mutation is paused. diff --git a/docs/framework/vue/reference/functions/defaultShouldDehydrateQuery.md b/docs/framework/vue/reference/functions/defaultShouldDehydrateQuery.md index 736579349d..0186b387b3 100644 --- a/docs/framework/vue/reference/functions/defaultShouldDehydrateQuery.md +++ b/docs/framework/vue/reference/functions/defaultShouldDehydrateQuery.md @@ -7,7 +7,7 @@ title: defaultShouldDehydrateQuery function defaultShouldDehydrateQuery(query: Query): boolean; ``` -Defined in: [packages/query-core/src/hydration.ts:186](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L186) +Defined in: [packages/query-core/src/hydration.ts:213](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L213) The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is `'success'`. @@ -18,6 +18,10 @@ The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrate [`Query`](../classes/Query.md) +The query to check. + ## Returns `boolean` + +`true` if the query's status is `'success'`. diff --git a/docs/framework/vue/reference/functions/dehydrate.md b/docs/framework/vue/reference/functions/dehydrate.md index 782758a438..d4478940b9 100644 --- a/docs/framework/vue/reference/functions/dehydrate.md +++ b/docs/framework/vue/reference/functions/dehydrate.md @@ -7,7 +7,7 @@ title: dehydrate function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState; ``` -Defined in: [packages/query-core/src/hydration.ts:208](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L208) +Defined in: [packages/query-core/src/hydration.ts:239](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L239) Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`, typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`. @@ -21,14 +21,21 @@ falling back to the client's `dehydrate` default options, and finally to `defaul `QueryClient` +The client whose cache is dehydrated. + ### options [`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}` +Controls which queries and mutations are included and how their data and errors +are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + ## Returns [`DehydratedState`](../interfaces/DehydratedState.md) +The dehydrated state, with the included `queries` and `mutations`. + ## Example ```ts diff --git a/docs/framework/vue/reference/functions/dehydrateQuery.md b/docs/framework/vue/reference/functions/dehydrateQuery.md index 0dcd090469..bd80050e86 100644 --- a/docs/framework/vue/reference/functions/dehydrateQuery.md +++ b/docs/framework/vue/reference/functions/dehydrateQuery.md @@ -10,7 +10,7 @@ function dehydrateQuery( shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery; ``` -Defined in: [packages/query-core/src/hydration.ts:149](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L149) +Defined in: [packages/query-core/src/hydration.ts:172](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L172) Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g. `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the @@ -41,3 +41,5 @@ error is kept as-is instead of being redacted. ## Returns `DehydratedQuery` + +The dehydrated query. diff --git a/docs/framework/vue/reference/functions/hydrate.md b/docs/framework/vue/reference/functions/hydrate.md index 926f21b445..e6ca6a6629 100644 --- a/docs/framework/vue/reference/functions/hydrate.md +++ b/docs/framework/vue/reference/functions/hydrate.md @@ -10,7 +10,7 @@ function hydrate( options?: HydrateOptions): void; ``` -Defined in: [packages/query-core/src/hydration.ts:265](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L265) +Defined in: [packages/query-core/src/hydration.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L300) Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`. @@ -26,14 +26,21 @@ promise, it is resumed via `query.fetch()` (reusing that promise as `initialProm `QueryClient` +The client whose cache is restored into. + ### dehydratedState `Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\> +The dehydrated state, e.g. produced by `dehydrate` on the server. + ### options? [`HydrateOptions`](../interfaces/HydrateOptions.md) +`defaultOptions` merged into every restored query and mutation (on top of the +client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. + ## Returns `void` diff --git a/docs/framework/vue/reference/interfaces/DehydrateOptions.md b/docs/framework/vue/reference/interfaces/DehydrateOptions.md index 23717093d3..080a286fd4 100644 --- a/docs/framework/vue/reference/interfaces/DehydrateOptions.md +++ b/docs/framework/vue/reference/interfaces/DehydrateOptions.md @@ -3,7 +3,7 @@ id: DehydrateOptions title: DehydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:42](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L42) +Defined in: [packages/query-core/src/hydration.ts:49](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L49) Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup). diff --git a/docs/framework/vue/reference/interfaces/DehydratedState.md b/docs/framework/vue/reference/interfaces/DehydratedState.md index 8668325a62..36aaf8d99e 100644 --- a/docs/framework/vue/reference/interfaces/DehydratedState.md +++ b/docs/framework/vue/reference/interfaces/DehydratedState.md @@ -3,7 +3,7 @@ id: DehydratedState title: DehydratedState --- -Defined in: [packages/query-core/src/hydration.ts:95](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L95) +Defined in: [packages/query-core/src/hydration.ts:102](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L102) A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data diff --git a/docs/framework/vue/reference/interfaces/HydrateOptions.md b/docs/framework/vue/reference/interfaces/HydrateOptions.md index 5d60315e07..55564a91d7 100644 --- a/docs/framework/vue/reference/interfaces/HydrateOptions.md +++ b/docs/framework/vue/reference/interfaces/HydrateOptions.md @@ -3,7 +3,7 @@ id: HydrateOptions title: HydrateOptions --- -Defined in: [packages/query-core/src/hydration.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L61) +Defined in: [packages/query-core/src/hydration.ts:68](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L68) Options for `hydrate`, controlling the default options applied to queries/mutations restored from a `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`. diff --git a/packages/query-core/src/hydration.ts b/packages/query-core/src/hydration.ts index 581c7b3df9..e99bcdfebf 100644 --- a/packages/query-core/src/hydration.ts +++ b/packages/query-core/src/hydration.ts @@ -16,6 +16,13 @@ import type { Mutation, MutationState } from './mutation' // TYPES type TransformerFn = (data: any) => any +/** + * Reads the value of a promise synchronously if it has already resolved, e.g. a thenable that + * resolves within its `then` call. + * @param promise - The promise to read. + * @returns An object with the resolved `data`, or `undefined` if the promise hasn't resolved + * synchronously (or resolved with `undefined`). + */ function tryResolveSync(promise: PromiseLike) { let data: unknown @@ -99,6 +106,11 @@ export interface DehydratedState { // FUNCTIONS +/** + * Dehydrates a single `Mutation` into a serializable snapshot of its key, state, scope, and meta. + * @param mutation - The mutation to dehydrate. + * @returns The dehydrated mutation. + */ function dehydrateMutation(mutation: Mutation): DehydratedMutation { return { mutationKey: mutation.options.mutationKey, @@ -108,6 +120,16 @@ function dehydrateMutation(mutation: Mutation): DehydratedMutation { } } +/** + * Prepares the in-flight promise of a pending query for dehydration: applies `serializeData` to its + * result, and redacts its rejection error unless `shouldRedactErrors` returns `false` for it. + * @param query - The pending query whose promise is dehydrated. + * @param serializeData - Optional transform applied to the resolved data. + * @param shouldRedactErrors - Optional predicate; if it returns `false` for the rejection error, + * that + * error is kept as-is instead of being redacted. + * @returns The transformed promise, or `undefined` if the query has no in-flight promise. + */ function dehydratePromise( query: Query, serializeData?: TransformerFn, @@ -145,6 +167,7 @@ function dehydratePromise( * @param serializeData - Optional transform applied to `query.state.data` before it is included in the snapshot. * @param shouldRedactErrors - Optional predicate; if it returns `false` for the promise's rejection error, that * error is kept as-is instead of being redacted. + * @returns The dehydrated query. */ export function dehydrateQuery( query: Query, @@ -174,6 +197,8 @@ export function dehydrateQuery( /** * The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are * currently paused (e.g. paused by `networkMode` while offline). + * @param mutation - The mutation to check. + * @returns `true` if the mutation is paused. */ export function defaultShouldDehydrateMutation(mutation: Mutation) { return mutation.state.isPaused @@ -182,6 +207,8 @@ export function defaultShouldDehydrateMutation(mutation: Mutation) { /** * The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is * `'success'`. + * @param query - The query to check. + * @returns `true` if the query's status is `'success'`. */ export function defaultShouldDehydrateQuery(query: Query) { return query.state.status === 'success' @@ -193,6 +220,10 @@ export function defaultShouldDehydrateQuery(query: Query) { * Which queries/mutations are included, and how their data/errors are transformed, is controlled by `options`, * falling back to the client's `dehydrate` default options, and finally to `defaultShouldDehydrateQuery` / * `defaultShouldDehydrateMutation`. + * @param client - The client whose cache is dehydrated. + * @param options - Controls which queries and mutations are included and how their data and errors + * are transformed. Each option falls back to the client's `defaultOptions.dehydrate`. + * @returns The dehydrated state, with the included `queries` and `mutations`. * @example * ```ts * const queryClient = new QueryClient() @@ -253,6 +284,10 @@ export function dehydrate( * to `'idle'` so they don't hydrate stuck in a fetching state. If a dehydrated query still had an in-flight * promise, it is resumed via `query.fetch()` (reusing that promise as `initialPromise`) rather than re-invoking * `queryFn`. + * @param client - The client whose cache is restored into. + * @param dehydratedState - The dehydrated state, e.g. produced by `dehydrate` on the server. + * @param options - `defaultOptions` merged into every restored query and mutation (on top of the + * client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`. * @example * ```ts * // dehydratedState was produced by `dehydrate` on the server