@@ -72,7 +72,7 @@ export class QueryObserver<
7272 private staleTimeoutId ?: number
7373 private refetchIntervalId ?: number
7474 private currentRefetchInterval ?: number | false
75- private trackedProps ! : Array < keyof QueryObserverResult >
75+ private trackedProps ! : Set < keyof QueryObserverResult >
7676
7777 constructor (
7878 client : QueryClient ,
@@ -88,7 +88,7 @@ export class QueryObserver<
8888
8989 this . client = client
9090 this . options = options
91- this . trackedProps = [ ]
91+ this . trackedProps = new Set ( )
9292 this . previousSelectError = null
9393 this . bindMethods ( )
9494 this . setOptions ( options )
@@ -235,25 +235,19 @@ export class QueryObserver<
235235 ) : QueryObserverResult < TData , TError > {
236236 const trackedResult = { } as QueryObserverResult < TData , TError >
237237
238- const trackProp = ( key : keyof QueryObserverResult ) => {
239- if ( ! this . trackedProps . includes ( key ) ) {
240- this . trackedProps . push ( key )
241- }
242- }
243-
244238 Object . keys ( result ) . forEach ( key => {
245239 Object . defineProperty ( trackedResult , key , {
246240 configurable : false ,
247241 enumerable : true ,
248242 get : ( ) => {
249- trackProp ( key as keyof QueryObserverResult )
243+ this . trackedProps . add ( key as keyof QueryObserverResult )
250244 return result [ key as keyof QueryObserverResult ]
251245 } ,
252246 } )
253247 } )
254248
255249 if ( defaultedOptions . useErrorBoundary ) {
256- trackProp ( 'error' )
250+ this . trackedProps . add ( 'error' )
257251 }
258252
259253 return trackedResult
@@ -605,18 +599,17 @@ export class QueryObserver<
605599
606600 if (
607601 notifyOnChangeProps === 'all' ||
608- ( ! notifyOnChangeProps && ! this . trackedProps . length )
602+ ( ! notifyOnChangeProps && ! this . trackedProps . size )
609603 ) {
610604 return true
611605 }
612606
613- const includedProps = notifyOnChangeProps ?? this . trackedProps
607+ const includedProps = new Set ( notifyOnChangeProps ?? this . trackedProps )
614608
615609 return Object . keys ( result ) . some ( key => {
616610 const typedKey = key as keyof QueryObserverResult
617611 const changed = result [ typedKey ] !== prevResult [ typedKey ]
618- const isIncluded = includedProps ?. some ( x => x === key )
619- return changed && ( ! includedProps || isIncluded )
612+ return changed && includedProps . has ( typedKey )
620613 } )
621614 }
622615
0 commit comments