@tanstack/query-core 4.24.9 → 4.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/hydration.esm.js +9 -4
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +9 -4
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +9 -4
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +1 -1
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/umd/index.development.js +10 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/hydration.ts +10 -3
- package/src/index.ts +1 -0
- package/src/tests/hydration.test.tsx +40 -0
|
@@ -73,11 +73,16 @@ function hydrate(client, dehydratedState, options) {
|
|
|
73
73
|
queries.forEach(dehydratedQuery => {
|
|
74
74
|
var _options$defaultOptio2;
|
|
75
75
|
|
|
76
|
-
const query = queryCache.get(dehydratedQuery.queryHash); //
|
|
76
|
+
const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid
|
|
77
|
+
// query being stuck in fetching state upon hydration
|
|
78
|
+
|
|
79
|
+
const dehydratedQueryState = { ...dehydratedQuery.state,
|
|
80
|
+
fetchStatus: 'idle'
|
|
81
|
+
}; // Do not hydrate if an existing query exists with newer data
|
|
77
82
|
|
|
78
83
|
if (query) {
|
|
79
|
-
if (query.state.dataUpdatedAt <
|
|
80
|
-
query.setState(
|
|
84
|
+
if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
|
|
85
|
+
query.setState(dehydratedQueryState);
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
return;
|
|
@@ -87,7 +92,7 @@ function hydrate(client, dehydratedState, options) {
|
|
|
87
92
|
queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
|
|
88
93
|
queryKey: dehydratedQuery.queryKey,
|
|
89
94
|
queryHash: dehydratedQuery.queryHash
|
|
90
|
-
},
|
|
95
|
+
}, dehydratedQueryState);
|
|
91
96
|
});
|
|
92
97
|
}
|
|
93
98
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.esm.js","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach((dehydratedQuery) => {\n const query = queryCache.get(dehydratedQuery.queryHash)\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt <
|
|
1
|
+
{"version":3,"file":"hydration.esm.js","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach((dehydratedQuery) => {\n const query = queryCache.get(dehydratedQuery.queryHash)\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle' as const,\n }\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState)\n }\n return\n }\n\n // Restore query\n queryCache.build(\n client,\n {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash,\n },\n dehydratedQueryState,\n )\n })\n}\n"],"names":["dehydrateMutation","mutation","mutationKey","options","state","dehydrateQuery","query","queryKey","queryHash","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","status","dehydrate","client","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","dehydrateQueries","shouldDehydrateQuery","getQueryCache","hydrate","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","dehydratedQuery","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState"],"mappings":"AAUA;AAoCA;AAEA,SAASA,iBAAT,CAA2BC,QAA3B,EAAmE;EACjE,OAAO;AACLC,IAAAA,WAAW,EAAED,QAAQ,CAACE,OAAT,CAAiBD,WADzB;IAELE,KAAK,EAAEH,QAAQ,CAACG,KAAAA;GAFlB,CAAA;AAID;AAGD;AACA;AACA;;;AACA,SAASC,cAAT,CAAwBC,KAAxB,EAAuD;EACrD,OAAO;IACLF,KAAK,EAAEE,KAAK,CAACF,KADR;IAELG,QAAQ,EAAED,KAAK,CAACC,QAFX;IAGLC,SAAS,EAAEF,KAAK,CAACE,SAAAA;GAHnB,CAAA;AAKD,CAAA;;AAEM,SAASC,8BAAT,CAAwCR,QAAxC,EAA4D;AACjE,EAAA,OAAOA,QAAQ,CAACG,KAAT,CAAeM,QAAtB,CAAA;AACD,CAAA;AAEM,SAASC,2BAAT,CAAqCL,KAArC,EAAmD;AACxD,EAAA,OAAOA,KAAK,CAACF,KAAN,CAAYQ,MAAZ,KAAuB,SAA9B,CAAA;AACD,CAAA;AAEM,SAASC,SAAT,CACLC,MADK,EAELX,OAAyB,GAAG,EAFvB,EAGY;EACjB,MAAMY,SAA+B,GAAG,EAAxC,CAAA;EACA,MAAMC,OAA0B,GAAG,EAAnC,CAAA;;AAEA,EAAA,IAAIb,OAAO,CAACc,kBAAR,KAA+B,KAAnC,EAA0C;AACxC,IAAA,MAAMC,uBAAuB,GAC3Bf,OAAO,CAACe,uBAAR,IAAmCT,8BADrC,CAAA;IAGAK,MAAM,CACHK,gBADH,EAEGC,CAAAA,MAFH,GAGGC,OAHH,CAGYpB,QAAD,IAAc;AACrB,MAAA,IAAIiB,uBAAuB,CAACjB,QAAD,CAA3B,EAAuC;AACrCc,QAAAA,SAAS,CAACO,IAAV,CAAetB,iBAAiB,CAACC,QAAD,CAAhC,CAAA,CAA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F;MAEEb,WAAW,EAAE4B,kBAAkB,CAAC5B,WAAAA;KAJpC,EAME4B,kBAAkB,CAAC1B,KANrB,CAAA,CAAA;GADF,CAAA,CAAA;AAWAY,EAAAA,OAAO,CAACK,OAAR,CAAiBY,eAAD,IAAqB;AAAA,IAAA,IAAA,sBAAA,CAAA;;IACnC,MAAM3B,KAAK,GAAGuB,UAAU,CAACK,GAAX,CAAeD,eAAe,CAACzB,SAA/B,CAAd,CADmC;AAInC;;AACA,IAAA,MAAM2B,oBAAoB,GAAG,EAC3B,GAAGF,eAAe,CAAC7B,KADQ;AAE3BgC,MAAAA,WAAW,EAAE,MAAA;AAFc,KAA7B,CALmC;;AAWnC,IAAA,IAAI9B,KAAJ,EAAW;MACT,IAAIA,KAAK,CAACF,KAAN,CAAYiC,aAAZ,GAA4BF,oBAAoB,CAACE,aAArD,EAAoE;QAClE/B,KAAK,CAACgC,QAAN,CAAeH,oBAAf,CAAA,CAAA;AACD,OAAA;;AACD,MAAA,OAAA;AACD,KAhBkC;;;AAmBnCN,IAAAA,UAAU,CAACE,KAAX,CACEjB,MADF,EAEE,EACE,IAAGX,OAAH,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,CAAA,sBAAA,GAAGA,OAAO,CAAE6B,cAAZ,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,sBAAA,CAAyBhB,OAA5B,CADF;MAEET,QAAQ,EAAE0B,eAAe,CAAC1B,QAF5B;MAGEC,SAAS,EAAEyB,eAAe,CAACzB,SAAAA;AAH7B,KAFF,EAOE2B,oBAPF,CAAA,CAAA;GAnBF,CAAA,CAAA;AA6BD;;;;"}
|
package/build/lib/hydration.js
CHANGED
|
@@ -77,11 +77,16 @@ function hydrate(client, dehydratedState, options) {
|
|
|
77
77
|
queries.forEach(dehydratedQuery => {
|
|
78
78
|
var _options$defaultOptio2;
|
|
79
79
|
|
|
80
|
-
const query = queryCache.get(dehydratedQuery.queryHash); //
|
|
80
|
+
const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid
|
|
81
|
+
// query being stuck in fetching state upon hydration
|
|
82
|
+
|
|
83
|
+
const dehydratedQueryState = { ...dehydratedQuery.state,
|
|
84
|
+
fetchStatus: 'idle'
|
|
85
|
+
}; // Do not hydrate if an existing query exists with newer data
|
|
81
86
|
|
|
82
87
|
if (query) {
|
|
83
|
-
if (query.state.dataUpdatedAt <
|
|
84
|
-
query.setState(
|
|
88
|
+
if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
|
|
89
|
+
query.setState(dehydratedQueryState);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
return;
|
|
@@ -91,7 +96,7 @@ function hydrate(client, dehydratedState, options) {
|
|
|
91
96
|
queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
|
|
92
97
|
queryKey: dehydratedQuery.queryKey,
|
|
93
98
|
queryHash: dehydratedQuery.queryHash
|
|
94
|
-
},
|
|
99
|
+
}, dehydratedQueryState);
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.js","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach((dehydratedQuery) => {\n const query = queryCache.get(dehydratedQuery.queryHash)\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt <
|
|
1
|
+
{"version":3,"file":"hydration.js","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach((dehydratedQuery) => {\n const query = queryCache.get(dehydratedQuery.queryHash)\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle' as const,\n }\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState)\n }\n return\n }\n\n // Restore query\n queryCache.build(\n client,\n {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash,\n },\n dehydratedQueryState,\n )\n })\n}\n"],"names":["dehydrateMutation","mutation","mutationKey","options","state","dehydrateQuery","query","queryKey","queryHash","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","status","dehydrate","client","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","dehydrateQueries","shouldDehydrateQuery","getQueryCache","hydrate","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","dehydratedQuery","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState"],"mappings":";;;;AAUA;AAoCA;AAEA,SAASA,iBAAT,CAA2BC,QAA3B,EAAmE;EACjE,OAAO;AACLC,IAAAA,WAAW,EAAED,QAAQ,CAACE,OAAT,CAAiBD,WADzB;IAELE,KAAK,EAAEH,QAAQ,CAACG,KAAAA;GAFlB,CAAA;AAID;AAGD;AACA;AACA;;;AACA,SAASC,cAAT,CAAwBC,KAAxB,EAAuD;EACrD,OAAO;IACLF,KAAK,EAAEE,KAAK,CAACF,KADR;IAELG,QAAQ,EAAED,KAAK,CAACC,QAFX;IAGLC,SAAS,EAAEF,KAAK,CAACE,SAAAA;GAHnB,CAAA;AAKD,CAAA;;AAEM,SAASC,8BAAT,CAAwCR,QAAxC,EAA4D;AACjE,EAAA,OAAOA,QAAQ,CAACG,KAAT,CAAeM,QAAtB,CAAA;AACD,CAAA;AAEM,SAASC,2BAAT,CAAqCL,KAArC,EAAmD;AACxD,EAAA,OAAOA,KAAK,CAACF,KAAN,CAAYQ,MAAZ,KAAuB,SAA9B,CAAA;AACD,CAAA;AAEM,SAASC,SAAT,CACL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OAAO,CAAE6B,cAAZ,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,sBAAA,CAAyBhB,OAA5B,CADF;MAEET,QAAQ,EAAE0B,eAAe,CAAC1B,QAF5B;MAGEC,SAAS,EAAEyB,eAAe,CAACzB,SAAAA;AAH7B,KAFF,EAOE2B,oBAPF,CAAA,CAAA;GAnBF,CAAA,CAAA;AA6BD;;;;;;;"}
|
package/build/lib/hydration.mjs
CHANGED
|
@@ -73,11 +73,16 @@ function hydrate(client, dehydratedState, options) {
|
|
|
73
73
|
queries.forEach(dehydratedQuery => {
|
|
74
74
|
var _options$defaultOptio2;
|
|
75
75
|
|
|
76
|
-
const query = queryCache.get(dehydratedQuery.queryHash); //
|
|
76
|
+
const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid
|
|
77
|
+
// query being stuck in fetching state upon hydration
|
|
78
|
+
|
|
79
|
+
const dehydratedQueryState = { ...dehydratedQuery.state,
|
|
80
|
+
fetchStatus: 'idle'
|
|
81
|
+
}; // Do not hydrate if an existing query exists with newer data
|
|
77
82
|
|
|
78
83
|
if (query) {
|
|
79
|
-
if (query.state.dataUpdatedAt <
|
|
80
|
-
query.setState(
|
|
84
|
+
if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
|
|
85
|
+
query.setState(dehydratedQueryState);
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
return;
|
|
@@ -87,7 +92,7 @@ function hydrate(client, dehydratedState, options) {
|
|
|
87
92
|
queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
|
|
88
93
|
queryKey: dehydratedQuery.queryKey,
|
|
89
94
|
queryHash: dehydratedQuery.queryHash
|
|
90
|
-
},
|
|
95
|
+
}, dehydratedQueryState);
|
|
91
96
|
});
|
|
92
97
|
}
|
|
93
98
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.mjs","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach((dehydratedQuery) => {\n const query = queryCache.get(dehydratedQuery.queryHash)\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt <
|
|
1
|
+
{"version":3,"file":"hydration.mjs","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach((dehydratedQuery) => {\n const query = queryCache.get(dehydratedQuery.queryHash)\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle' as const,\n }\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState)\n }\n return\n }\n\n // Restore query\n queryCache.build(\n client,\n {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash,\n },\n dehydratedQueryState,\n )\n })\n}\n"],"names":["dehydrateMutation","mutation","mutationKey","options","state","dehydrateQuery","query","queryKey","queryHash","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","status","dehydrate","client","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","dehydrateQueries","shouldDehydrateQuery","getQueryCache","hydrate","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","dehydratedQuery","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState"],"mappings":"AAUA;AAoCA;AAEA,SAASA,iBAAT,CAA2BC,QAA3B,EAAmE;EACjE,OAAO;AACLC,IAAAA,WAAW,EAAED,QAAQ,CAACE,OAAT,CAAiBD,WADzB;IAELE,KAAK,EAAEH,QAAQ,CAACG,KAAAA;GAFlB,C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mC;AAInC;;AACA,IAAA,MAAM2B,oBAAoB,GAAG,EAC3B,GAAGF,eAAe,CAAC7B,KADQ;AAE3BgC,MAAAA,WAAW,EAAE,MAAA;AAFc,KAA7B,CALmC;;AAWnC,IAAA,IAAI9B,KAAJ,EAAW;MACT,IAAIA,KAAK,CAACF,KAAN,CAAYiC,aAAZ,GAA4BF,oBAAoB,CAACE,aAArD,EAAoE;QAClE/B,KAAK,CAACgC,QAAN,CAAeH,oBAAf,CAAA,CAAA;AACD,OAAA;;AACD,MAAA,OAAA;AACD,KAhBkC;;;AAmBnCN,IAAAA,UAAU,CAACE,KAAX,CACEjB,MADF,EAEE,EACE,IAAGX,OAAH,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,CAAA,sBAAA,GAAGA,OAAO,CAAE6B,cAAZ,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,sBAAA,CAAyBhB,OAA5B,CADF;MAEET,QAAQ,EAAE0B,eAAe,CAAC1B,QAF5B;MAGEC,SAAS,EAAEyB,eAAe,CAACzB,SAAAA;AAH7B,KAFF,EAOE2B,oBAPF,CAAA,CAAA;GAnBF,CAAA,CAAA;AA6BD;;;;"}
|
package/build/lib/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { MutationObserver } from './mutationObserver';
|
|
|
9
9
|
export { notifyManager } from './notifyManager';
|
|
10
10
|
export { focusManager } from './focusManager';
|
|
11
11
|
export { onlineManager } from './onlineManager';
|
|
12
|
-
export { hashQueryKey, replaceEqualDeep, isError, isServer, parseQueryArgs, parseFilterArgs, parseMutationFilterArgs, parseMutationArgs, } from './utils';
|
|
12
|
+
export { hashQueryKey, replaceEqualDeep, isError, isServer, matchQuery, parseQueryArgs, parseFilterArgs, parseMutationFilterArgs, parseMutationArgs, } from './utils';
|
|
13
13
|
export type { MutationFilters, QueryFilters, Updater } from './utils';
|
|
14
14
|
export { isCancelledError } from './retryer';
|
|
15
15
|
export { dehydrate, hydrate, defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, } from './hydration';
|
package/build/lib/index.esm.js
CHANGED
|
@@ -9,6 +9,6 @@ export { MutationObserver } from './mutationObserver.esm.js';
|
|
|
9
9
|
export { notifyManager } from './notifyManager.esm.js';
|
|
10
10
|
export { focusManager } from './focusManager.esm.js';
|
|
11
11
|
export { onlineManager } from './onlineManager.esm.js';
|
|
12
|
-
export { hashQueryKey, isError, isServer, parseFilterArgs, parseMutationArgs, parseMutationFilterArgs, parseQueryArgs, replaceEqualDeep } from './utils.esm.js';
|
|
12
|
+
export { hashQueryKey, isError, isServer, matchQuery, parseFilterArgs, parseMutationArgs, parseMutationFilterArgs, parseQueryArgs, replaceEqualDeep } from './utils.esm.js';
|
|
13
13
|
export { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate } from './hydration.esm.js';
|
|
14
14
|
//# sourceMappingURL=index.esm.js.map
|
package/build/lib/index.js
CHANGED
|
@@ -33,6 +33,7 @@ exports.onlineManager = onlineManager.onlineManager;
|
|
|
33
33
|
exports.hashQueryKey = utils.hashQueryKey;
|
|
34
34
|
exports.isError = utils.isError;
|
|
35
35
|
exports.isServer = utils.isServer;
|
|
36
|
+
exports.matchQuery = utils.matchQuery;
|
|
36
37
|
exports.parseFilterArgs = utils.parseFilterArgs;
|
|
37
38
|
exports.parseMutationArgs = utils.parseMutationArgs;
|
|
38
39
|
exports.parseMutationFilterArgs = utils.parseMutationFilterArgs;
|
package/build/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/lib/index.mjs
CHANGED
|
@@ -9,6 +9,6 @@ export { MutationObserver } from './mutationObserver.mjs';
|
|
|
9
9
|
export { notifyManager } from './notifyManager.mjs';
|
|
10
10
|
export { focusManager } from './focusManager.mjs';
|
|
11
11
|
export { onlineManager } from './onlineManager.mjs';
|
|
12
|
-
export { hashQueryKey, isError, isServer, parseFilterArgs, parseMutationArgs, parseMutationFilterArgs, parseQueryArgs, replaceEqualDeep } from './utils.mjs';
|
|
12
|
+
export { hashQueryKey, isError, isServer, matchQuery, parseFilterArgs, parseMutationArgs, parseMutationFilterArgs, parseQueryArgs, replaceEqualDeep } from './utils.mjs';
|
|
13
13
|
export { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate } from './hydration.mjs';
|
|
14
14
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -3146,11 +3146,16 @@
|
|
|
3146
3146
|
queries.forEach(dehydratedQuery => {
|
|
3147
3147
|
var _options$defaultOptio2;
|
|
3148
3148
|
|
|
3149
|
-
const query = queryCache.get(dehydratedQuery.queryHash); //
|
|
3149
|
+
const query = queryCache.get(dehydratedQuery.queryHash); // Reset fetch status to idle in the dehydrated state to avoid
|
|
3150
|
+
// query being stuck in fetching state upon hydration
|
|
3151
|
+
|
|
3152
|
+
const dehydratedQueryState = { ...dehydratedQuery.state,
|
|
3153
|
+
fetchStatus: 'idle'
|
|
3154
|
+
}; // Do not hydrate if an existing query exists with newer data
|
|
3150
3155
|
|
|
3151
3156
|
if (query) {
|
|
3152
|
-
if (query.state.dataUpdatedAt <
|
|
3153
|
-
query.setState(
|
|
3157
|
+
if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
|
|
3158
|
+
query.setState(dehydratedQueryState);
|
|
3154
3159
|
}
|
|
3155
3160
|
|
|
3156
3161
|
return;
|
|
@@ -3160,7 +3165,7 @@
|
|
|
3160
3165
|
queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
|
|
3161
3166
|
queryKey: dehydratedQuery.queryKey,
|
|
3162
3167
|
queryHash: dehydratedQuery.queryHash
|
|
3163
|
-
},
|
|
3168
|
+
}, dehydratedQueryState);
|
|
3164
3169
|
});
|
|
3165
3170
|
}
|
|
3166
3171
|
|
|
@@ -3181,6 +3186,7 @@
|
|
|
3181
3186
|
exports.isCancelledError = isCancelledError;
|
|
3182
3187
|
exports.isError = isError;
|
|
3183
3188
|
exports.isServer = isServer;
|
|
3189
|
+
exports.matchQuery = matchQuery;
|
|
3184
3190
|
exports.notifyManager = notifyManager;
|
|
3185
3191
|
exports.onlineManager = onlineManager;
|
|
3186
3192
|
exports.parseFilterArgs = parseFilterArgs;
|