From 7618bdf78e28d0a210393da7425ae94291290ee6 Mon Sep 17 00:00:00 2001 From: Joel Jeske Date: Mon, 23 Sep 2024 16:34:20 -0500 Subject: [PATCH] [perf] improve perf, as discussed in #8091 --- packages/query-core/src/queryObserver.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/query-core/src/queryObserver.ts b/packages/query-core/src/queryObserver.ts index 2971bc6d1a..8cdd727259 100644 --- a/packages/query-core/src/queryObserver.ts +++ b/packages/query-core/src/queryObserver.ts @@ -263,18 +263,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