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

Function dehydratePromise

packages/query-core/src/hydration.ts:89–115  ·  view source on GitHub ↗
(
  query: Query,
  serializeData?: TransformerFn,
  shouldRedactErrors?: (error: unknown) => boolean,
)

Source from the content-addressed store, hash-verified

87}
88
89function dehydratePromise(
90 query: Query,
91 serializeData?: TransformerFn,
92 shouldRedactErrors?: (error: unknown) => boolean,
93): Promise<unknown> | undefined {
94 const promise = query.promise?.then(serializeData).catch((error) => {
95 if (shouldRedactErrors?.(error) === false) {
96 // Reject original error if it should not be redacted
97 return Promise.reject(error)
98 }
99 // If not in production, log original error before rejecting redacted error
100 if (process.env.NODE_ENV !== 'production') {
101 console.error(
102 `A query that was dehydrated as pending ended up rejecting. [${query.queryHash}]: ${error}; The error will be redacted in production builds`,
103 )
104 }
105 return Promise.reject(new Error('redacted'))
106 })
107
108 // Avoid unhandled promise rejections
109 // We need the promise we dehydrate to reject to get the correct result into
110 // the query cache, but we also want to avoid unhandled promise rejections
111 // in whatever environment the prefetches are happening in.
112 promise?.catch(noop)
113
114 return promise
115}
116
117// Most config is not dehydrated but instead meant to configure again when
118// consuming the de/rehydrated data, typically with useQuery on the client.

Callers 1

dehydrateQueryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected