diff --git a/packages/query-core/src/queryObserver.ts b/packages/query-core/src/queryObserver.ts index 3dc751f5cd..12fd97a09a 100644 --- a/packages/query-core/src/queryObserver.ts +++ b/packages/query-core/src/queryObserver.ts @@ -273,18 +273,14 @@ export class QueryObserver< result: QueryObserverResult, onPropTracked?: (key: keyof QueryObserverResult) => void, ): QueryObserverResult { - const trackedResult = {} as QueryObserverResult - - Object.keys(result).forEach((key) => { - Object.defineProperty(trackedResult, key, { - configurable: false, - enumerable: true, - get: () => { + const trackedResult = new Proxy(result, { + get: (target, key) => { + if (key in target) { this.trackProp(key as keyof QueryObserverResult) onPropTracked?.(key as keyof QueryObserverResult) - return result[key as keyof QueryObserverResult] - }, - }) + return target[key as keyof QueryObserverResult] + } + }, }) return trackedResult