MCPcopy Index your code
hub / github.com/TanStack/query / reconcileFn

Function reconcileFn

packages/solid-query/src/useBaseQuery.ts:27–60  ·  view source on GitHub ↗
(
  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

25} from '@tanstack/query-core'
26
27function reconcileFn<TData, TError>(
28 store: QueryObserverResult<TData, TError>,
29 result: QueryObserverResult<TData, TError>,
30 reconcileOption:
31 | string
32 | false
33 | ((oldData: TData | undefined, newData: TData) => TData),
34 queryHash?: string,
35): QueryObserverResult<TData, TError> {
36 if (reconcileOption === false) return result
37 if (typeof reconcileOption === 'function') {
38 const newData = reconcileOption(store.data, result.data as TData)
39 return { ...result, data: newData } as typeof result
40 }
41 let data = result.data
42 if (store.data === undefined) {
43 try {
44 data = structuredClone(data)
45 } catch (error) {
46 if (process.env.NODE_ENV !== 'production') {
47 if (error instanceof Error) {
48 console.warn(
49 `Unable to correctly reconcile data for query key: ${queryHash}. ` +
50 `Possibly because the query data contains data structures that aren't supported ` +
51 `by the 'structuredClone' algorithm. Consider using a callback function instead ` +
52 `to manage the reconciliation manually.\n\n Error Received: ${error.name} - ${error.message}`,
53 )
54 }
55 }
56 }
57 }
58 const newData = reconcile(data, { key: reconcileOption })(store.data)
59 return { ...result, data: newData } as typeof result
60}
61
62/**
63 * 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…