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

Function reconcileFn

packages/solid-query/src/useBaseQuery.ts:36–69  ·  view source on GitHub ↗

* Applies the `reconcile` option when writing a new observer result into the store. * @param store - The current result in the store. * @param result - The new observer result. * @param reconcileOption - `false` to replace the data, a function that merges the old and new * data, or the key used

(
  store: QueryObserverResult<TData, TError>,
  result: QueryObserverResult<TData, TError>,
  reconcileOption:
    | string
    | false
    | ((oldData: TData | undefined, newData: TData) => TData),
  queryHash?: string,
)

Source from the content-addressed store, hash-verified

34 * @returns The result to store, with its data reconciled.
35 */
36function reconcileFn<TData, TError>(
37 store: QueryObserverResult<TData, TError>,
38 result: QueryObserverResult<TData, TError>,
39 reconcileOption:
40 | string
41 | false
42 | ((oldData: TData | undefined, newData: TData) => TData),
43 queryHash?: string,
44): QueryObserverResult<TData, TError> {
45 if (reconcileOption === false) return result
46 if (typeof reconcileOption === 'function') {
47 const newData = reconcileOption(store.data, result.data as TData)
48 return { ...result, data: newData } as typeof result
49 }
50 let data = result.data
51 if (store.data === undefined) {
52 try {
53 data = structuredClone(data)
54 } catch (error) {
55 if (process.env.NODE_ENV !== 'production') {
56 if (error instanceof Error) {
57 console.warn(
58 `Unable to correctly reconcile data for query key: ${queryHash}. ` +
59 `Possibly because the query data contains data structures that aren't supported ` +
60 `by the 'structuredClone' algorithm. Consider using a callback function instead ` +
61 `to manage the reconciliation manually.\n\n Error Received: ${error.name} - ${error.message}`,
62 )
63 }
64 }
65 }
66 }
67 const newData = reconcile(data, { key: reconcileOption })(store.data)
68 return { ...result, data: newData } as typeof result
69}
70
71/**
72 * Solid's `onHydrated` functionality will silently "fail" (hydrate with an empty object)

Callers 1

Calls 1

reconcileFunction · 0.85

Tested by

no test coverage detected