Open History to see the last commit
1import { focusManager } from './focusManager'
2import { notifyManager } from './notifyManager'
3import { fetchState } from './query'
4import { Subscribable } from './subscribable'
5import { pendingThenable } from './thenable'
6import {
7 isServer,
8 isValidTimeout,
9 noop,
10 replaceData,
11 resolveEnabled,
12 resolveStaleTime,
13 shallowEqualObjects,
14 timeUntilStale,
15} from './utils'
16import type { FetchOptions, Query, QueryState } from './query'
17import type { QueryClient } from './queryClient'
18import type { PendingThenable, Thenable } from './thenable'
19import type {
20 DefaultError,
21 DefaultedQueryObserverOptions,
22 PlaceholderDataFunction,
23 QueryKey,
24 QueryObserverBaseResult,
25 QueryObserverOptions,
26 QueryObserverResult,
27 QueryOptions,
28 RefetchOptions,
29} from './types'
30β
31type QueryObserverListener<TData, TError> = (
32 result: QueryObserverResult<TData, TError>,
33) => void
34β
35interface ObserverFetchOptions extends FetchOptions {
36 throwOnError?: boolean
37}
38β
39export class QueryObserver<
40 TQueryFnData = unknown,
41 TError = DefaultError,
42 TData = TQueryFnData,
43 TQueryData = TQueryFnData,
44 TQueryKey extends QueryKey = QueryKey,
45> extends Subscribable<QueryObserverListener<TData, TError>> {
46 #client: QueryClient
47 #currentQuery: Query<TQueryFnData, TError, TQueryData, TQueryKey> = undefined!
48 #currentQueryInitialState: QueryState<TQueryData, TError> = undefined!
49 #currentResult: QueryObserverResult<TData, TError> = undefined!
50 #currentResultState?: QueryState<TQueryData, TError>
51 #currentResultOptions?: QueryObserverOptions<
52 TQueryFnData,
53 TError,
54 TData,
55 TQueryData,
56 TQueryKey
57 >
58 #currentThenable: Thenable<TData>
59 #selectError: TError | null
60 #selectFn?: (data: TQueryData) => TData
61 #selectResult?: TData
62 // This property keeps track of the last query with defined data.
63 // It will be used to pass the previous data and query to the placeholder function between renders.
64 #lastQueryWithDefinedData?: Query<TQueryFnData, TError, TQueryData, TQueryKey>
65 #staleTimeoutId?: ReturnType<typeof setTimeout>
66 #refetchIntervalId?: ReturnType<typeof setInterval>
67 #currentRefetchInterval?: number | false
68 #trackedProps = new Set<keyof QueryObserverResult>()
69β
70 constructor(
71 client: QueryClient,
72 public options: QueryObserverOptions<
73 TQueryFnData,
74 TError,
75 TData,
76 TQueryData,
77 TQueryKey
78 >,
79 ) {
80 super()
81β
82 this.#client = client
83 this.#selectError = null
84 this.#currentThenable = pendingThenable()
85β
86 this.bindMethods()
87 this.setOptions(options)
88 }
89β
90 protected bindMethods(): void {
91 this.refetch = this.refetch.bind(this)
92 }
93β
94 protected onSubscribe(): void {
95 if (this.listeners.size === 1) {
96 this.#currentQuery.addObserver(this)
97β
98 if (shouldFetchOnMount(this.#currentQuery, this.options)) {
99 this.#executeFetch()
100 } else {
101 this.updateResult()
102 }
103β
104 this.#updateTimers()
105 }
106 }
107β
108 protected onUnsubscribe(): void {
109 if (!this.hasListeners()) {
110 this.destroy()
111 }
112 }
113β
114 shouldFetchOnReconnect(): boolean {
115 return shouldFetchOn(
116 this.#currentQuery,
117 this.options,
118 this.options.refetchOnReconnect,
119 )
120 }
121β
122 shouldFetchOnWindowFocus(): boolean {
123 return shouldFetchOn(
124 this.#currentQuery,
125 this.options,
126 this.options.refetchOnWindowFocus,
127 )
128 }
129β
130 destroy(): void {
131 this.listeners = new Set()
132 this.#clearStaleTimeout()
133 this.#clearRefetchInterval()
134 this.#currentQuery.removeObserver(this)
135 }
136β
137 setOptions(
138 options: QueryObserverOptions<
139 TQueryFnData,
140 TError,
141 TData,
142 TQueryData,
143 TQueryKey
144 >,
145 ): void {
146 const prevOptions = this.options
147 const prevQuery = this.#currentQuery
148β
149 this.options = this.#client.defaultQueryOptions(options)
150β
151 if (
152 this.options.enabled !== undefined &&
153 typeof this.options.enabled !== 'boolean' &&
154 typeof this.options.enabled !== 'function' &&
155 typeof resolveEnabled(this.options.enabled, this.#currentQuery) !==
156 'boolean'
157 ) {
158 throw new Error(
159 'Expected enabled to be a boolean or a callback that returns a boolean',
160 )
161 }
162β
163 this.#updateQuery()
164 this.#currentQuery.setOptions(this.options)
165β
166 if (
167 prevOptions._defaulted &&
168 !shallowEqualObjects(this.options, prevOptions)
169 ) {
170 this.#client.getQueryCache().notify({
171 type: 'observerOptionsUpdated',
172 query: this.#currentQuery,
173 observer: this,
174 })
175 }
176β
177 const mounted = this.hasListeners()
178β
179 // Fetch if there are subscribers
180 if (
181 mounted &&
182 shouldFetchOptionally(
183 this.#currentQuery,
184 prevQuery,
185 this.options,
186 prevOptions,
187 )
188 ) {
189 this.#executeFetch()
190 }
191β
192 // Update result
193 this.updateResult()
194β
195 // Update stale interval if needed
196 if (
197 mounted &&
198 (this.#currentQuery !== prevQuery ||
199 resolveEnabled(this.options.enabled, this.#currentQuery) !==
200 resolveEnabled(prevOptions.enabled, this.#currentQuery) ||
201 resolveStaleTime(this.options.staleTime, this.#currentQuery) !==
202 resolveStaleTime(prevOptions.staleTime, this.#currentQuery))
203 ) {
204 this.#updateStaleTimeout()
205 }
206β
207 const nextRefetchInterval = this.#computeRefetchInterval()
208β
209 // Update refetch interval if needed
210 if (
211 mounted &&
212 (this.#currentQuery !== prevQuery ||
213 resolveEnabled(this.options.enabled, this.#currentQuery) !==
214 resolveEnabled(prevOptions.enabled, this.#currentQuery) ||
215 nextRefetchInterval !== this.#currentRefetchInterval)
216 ) {
217 this.#updateRefetchInterval(nextRefetchInterval)
218 }
219 }
220β
221 getOptimisticResult(
222 options: DefaultedQueryObserverOptions<
223 TQueryFnData,
224 TError,
225 TData,
226 TQueryData,
227 TQueryKey
228 >,
229 ): QueryObserverResult<TData, TError> {
230 const query = this.#client.getQueryCache().build(this.#client, options)
231β
232 const result = this.createResult(query, options)
233β
234 if (shouldAssignObserverCurrentProperties(this, result)) {
235 // this assigns the optimistic result to the current Observer
236 // because if the query function changes, useQuery will be performing
237 // an effect where it would fetch again.
238 // When the fetch finishes, we perform a deep data cloning in order
239 // to reuse objects references. This deep data clone is performed against
240 // the `observer.currentResult.data` property
241 // When QueryKey changes, we refresh the query and get new `optimistic`
242 // result, while we leave the `observer.currentResult`, so when new data
243 // arrives, it finds the old `observer.currentResult` which is related
244 // to the old QueryKey. Which means that currentResult and selectData are
245 // out of sync already.
246 // To solve this, we move the cursor of the currentResult every time
247 // an observer reads an optimistic value.
248β
249 // When keeping the previous data, the result doesn't change until new
250 // data arrives.
251 this.#currentResult = result
252 this.#currentResultOptions = this.options
253 this.#currentResultState = this.#currentQuery.state
254 }
255 return result
256 }
257β
258 getCurrentResult(): QueryObserverResult<TData, TError> {
259 return this.#currentResult
260 }
261β
262 trackResult(
263 result: QueryObserverResult<TData, TError>,
264 onPropTracked?: (key: keyof QueryObserverResult) => void,
265 ): QueryObserverResult<TData, TError> {
266 return new Proxy(result, {
267 get: (target, key) => {
268 this.trackProp(key as keyof QueryObserverResult)
269 onPropTracked?.(key as keyof QueryObserverResult)
270 if (
271 key === 'promise' &&
272 !this.options.experimental_prefetchInRender &&
273 this.#currentThenable.status === 'pending'
274 ) {
275 this.#currentThenable.reject(
276 new Error(
277 'experimental_prefetchInRender feature flag is not enabled',
278 ),
279 )
280 }
281 return Reflect.get(target, key)
282 },
283 })
284 }
285β
286 trackProp(key: keyof QueryObserverResult) {
287 this.#trackedProps.add(key)
288 }
289β
290 getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {
291 return this.#currentQuery
292 }
293β
294 refetch({ ...options }: RefetchOptions = {}): Promise<
295 QueryObserverResult<TData, TError>
296 > {
297 return this.fetch({
298 ...options,
299 })
300 }
301β
302 fetchOptimistic(
303 options: QueryObserverOptions<
304 TQueryFnData,
305 TError,
306 TData,
307 TQueryData,
308 TQueryKey
309 >,
310 ): Promise<QueryObserverResult<TData, TError>> {
311 const defaultedOptions = this.#client.defaultQueryOptions(options)
312β
313 const query = this.#client
314 .getQueryCache()
315 .build(this.#client, defaultedOptions)
316β
317 return query.fetch().then(() => this.createResult(query, defaultedOptions))
318 }
319β
320 protected fetch(
321 fetchOptions: ObserverFetchOptions,
322 ): Promise<QueryObserverResult<TData, TError>> {
323 return this.#executeFetch({
324 ...fetchOptions,
325 cancelRefetch: fetchOptions.cancelRefetch ?? true,
326 }).then(() => {
327 this.updateResult()
328 return this.#currentResult
329 })
330 }
331β
332 #executeFetch(
333 fetchOptions?: Omit<ObserverFetchOptions, 'initialPromise'>,
334 ): Promise<TQueryData | undefined> {
335 // Make sure we reference the latest query as the current one might have been removed
336 this.#updateQuery()
337β
338 // Fetch
339 let promise: Promise<TQueryData | undefined> = this.#currentQuery.fetch(
340 this.options as QueryOptions<TQueryFnData, TError, TQueryData, TQueryKey>,
341 fetchOptions,
342 )
343β
344 if (!fetchOptions?.throwOnError) {
345 promise = promise.catch(noop)
346 }
347β
348 return promise
349 }
350β
351 #updateStaleTimeout(): void {
352 this.#clearStaleTimeout()
353 const staleTime = resolveStaleTime(
354 this.options.staleTime,
355 this.#currentQuery,
356 )
357β
358 if (isServer || this.#currentResult.isStale || !isValidTimeout(staleTime)) {
359 return
360 }
361β
362 const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)
363β
364 // The timeout is sometimes triggered 1 ms before the stale time expiration.
365 // To mitigate this issue we always add 1 ms to the timeout.
366 const timeout = time + 1
367β
368 this.#staleTimeoutId = setTimeout(() => {
369 if (!this.#currentResult.isStale) {
370 this.updateResult()
371 }
372 }, timeout)
373 }
374β
375 #computeRefetchInterval() {
376 return (
377 (typeof this.options.refetchInterval === 'function'
378 ? this.options.refetchInterval(this.#currentQuery)
379 : this.options.refetchInterval) ?? false
380 )
381 }
382β
383 #updateRefetchInterval(nextInterval: number | false): void {
384 this.#clearRefetchInterval()
385β
386 this.#currentRefetchInterval = nextInterval
387β
388 if (
389 isServer ||
390 resolveEnabled(this.options.enabled, this.#currentQuery) === false ||
391 !isValidTimeout(this.#currentRefetchInterval) ||
392 this.#currentRefetchInterval === 0
393 ) {
394 return
395 }
396β
397 this.#refetchIntervalId = setInterval(() => {
398 if (
399 this.options.refetchIntervalInBackground ||
400 focusManager.isFocused()
401 ) {
402 this.#executeFetch()
403 }
404 }, this.#currentRefetchInterval)
405 }
406β
407 #updateTimers(): void {
408 this.#updateStaleTimeout()
409 this.#updateRefetchInterval(this.#computeRefetchInterval())
410 }
411β
412 #clearStaleTimeout(): void {
413 if (this.#staleTimeoutId) {
414 clearTimeout(this.#staleTimeoutId)
415 this.#staleTimeoutId = undefined
416 }
417 }
418β
419 #clearRefetchInterval(): void {
420 if (this.#refetchIntervalId) {
421 clearInterval(this.#refetchIntervalId)
422 this.#refetchIntervalId = undefined
423 }
424 }
425β
426 protected createResult(
427 query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
428 options: QueryObserverOptions<
429 TQueryFnData,
430 TError,
431 TData,
432 TQueryData,
433 TQueryKey
434 >,
435 ): QueryObserverResult<TData, TError> {
436 const prevQuery = this.#currentQuery
437 const prevOptions = this.options
438 const prevResult = this.#currentResult as
439 | QueryObserverResult<TData, TError>
440 | undefined
441 const prevResultState = this.#currentResultState
442 const prevResultOptions = this.#currentResultOptions
443 const queryChange = query !== prevQuery
444 const queryInitialState = queryChange
445 ? query.state
446 : this.#currentQueryInitialState
447β
448 const { state } = query
449 let newState = { ...state }
450 let isPlaceholderData = false
451 let data: TData | undefined
452β
453 // Optimistically set result in fetching state if needed
454 if (options._optimisticResults) {
455 const mounted = this.hasListeners()
456β
457 const fetchOnMount = !mounted && shouldFetchOnMount(query, options)
458β
459 const fetchOptionally =
460 mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)
461β
462 if (fetchOnMount || fetchOptionally) {
463 newState = {
464 ...newState,
465 ...fetchState(state.data, query.options),
466 }
467 }
468 if (options._optimisticResults === 'isRestoring') {
469 newState.fetchStatus = 'idle'
470 }
471 }
472β
473 let { error, errorUpdatedAt, status } = newState
474β
475 // Per default, use query data
476 data = newState.data as unknown as TData
477 let skipSelect = false
478β
479 // use placeholderData if needed
480 if (
481 options.placeholderData !== undefined &&
482 data === undefined &&
483 status === 'pending'
484 ) {
485 let placeholderData
486β
487 // Memoize placeholder data
488 if (
489 prevResult?.isPlaceholderData &&
490 options.placeholderData === prevResultOptions?.placeholderData
491 ) {
492 placeholderData = prevResult.data
493 // we have to skip select when reading this memoization
494 // because prevResult.data is already "selected"
495 skipSelect = true
496 } else {
497 // compute placeholderData
498 placeholderData =
499 typeof options.placeholderData === 'function'
500 ? (
501 options.placeholderData as unknown as PlaceholderDataFunction<TQueryData>
502 )(
503 this.#lastQueryWithDefinedData?.state.data,
504 this.#lastQueryWithDefinedData as any,
505 )
506 : options.placeholderData
507 }
508β
509 if (placeholderData !== undefined) {
510 status = 'success'
511 data = replaceData(
512 prevResult?.data,
513 placeholderData as unknown,
514 options,
515 ) as TData
516 isPlaceholderData = true
517 }
518 }
519β
520 // Select data if needed
521 // this also runs placeholderData through the select function
522 if (options.select && data !== undefined && !skipSelect) {
523 // Memoize select result
524 if (
525 prevResult &&
526 data === prevResultState?.data &&
527 options.select === this.#selectFn
528 ) {
529 data = this.#selectResult
530 } else {
531 try {
532 this.#selectFn = options.select
533 data = options.select(data as any)
534 data = replaceData(prevResult?.data, data, options)
535 this.#selectResult = data
536 this.#selectError = null
537 } catch (selectError) {
538 this.#selectError = selectError as TError
539 }
540 }
541 }
542β
543 if (this.#selectError) {
544 error = this.#selectError as any
545 data = this.#selectResult
546 errorUpdatedAt = Date.now()
547 status = 'error'
548 }
549β
550 const isFetching = newState.fetchStatus === 'fetching'
551 const isPending = status === 'pending'
552 const isError = status === 'error'
553β
554 const isLoading = isPending && isFetching
555 const hasData = data !== undefined
556β
557 const result: QueryObserverBaseResult<TData, TError> = {
558 status,
559 fetchStatus: newState.fetchStatus,
560 isPending,
561 isSuccess: status === 'success',
562 isError,
563 isInitialLoading: isLoading,
564 isLoading,
565 data,
566 dataUpdatedAt: newState.dataUpdatedAt,
567 error,
568 errorUpdatedAt,
569 failureCount: newState.fetchFailureCount,
570 failureReason: newState.fetchFailureReason,
571 errorUpdateCount: newState.errorUpdateCount,
572 isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
573 isFetchedAfterMount:
574 newState.dataUpdateCount > queryInitialState.dataUpdateCount ||
575 newState.errorUpdateCount > queryInitialState.errorUpdateCount,
576 isFetching,
577 isRefetching: isFetching && !isPending,
578 isLoadingError: isError && !hasData,
579 isPaused: newState.fetchStatus === 'paused',
580 isPlaceholderData,
581 isRefetchError: isError && hasData,
582 isStale: isStale(query, options),
583 refetch: this.refetch,
584 promise: this.#currentThenable,
585 isEnabled: resolveEnabled(options.enabled, query) !== false,
586 }
587β
588 const nextResult = result as QueryObserverResult<TData, TError>
589β
590 if (this.options.experimental_prefetchInRender) {
591 const finalizeThenableIfPossible = (thenable: PendingThenable<TData>) => {
592 if (nextResult.status === 'error') {
593 thenable.reject(nextResult.error)
594 } else if (nextResult.data !== undefined) {
595 thenable.resolve(nextResult.data)
596 }
597 }
598β
599 /**
600 * Create a new thenable and result promise when the results have changed
601 */
602 const recreateThenable = () => {
603 const pending =
604 (this.#currentThenable =
605 nextResult.promise =
606 pendingThenable())
607β
608 finalizeThenableIfPossible(pending)
609 }
610β
611 const prevThenable = this.#currentThenable
612 switch (prevThenable.status) {
613 case 'pending':
614 // Finalize the previous thenable if it was pending
615 // and we are still observing the same query
616 if (query.queryHash === prevQuery.queryHash) {
617 finalizeThenableIfPossible(prevThenable)
618 }
619 break
620 case 'fulfilled':
621 if (
622 nextResult.status === 'error' ||
623 nextResult.data !== prevThenable.value
624 ) {
625 recreateThenable()
626 }
627 break
628 case 'rejected':
629 if (
630 nextResult.status !== 'error' ||
631 nextResult.error !== prevThenable.reason
632 ) {
633 recreateThenable()
634 }
635 break
636 }
637 }
638β
639 return nextResult
640 }
641β
642 updateResult(): void {
643 const prevResult = this.#currentResult as
644 | QueryObserverResult<TData, TError>
645 | undefined
646β
647 const nextResult = this.createResult(this.#currentQuery, this.options)
648β
649 this.#currentResultState = this.#currentQuery.state
650 this.#currentResultOptions = this.options
651β
652 if (this.#currentResultState.data !== undefined) {
653 this.#lastQueryWithDefinedData = this.#currentQuery
654 }
655β
656 // Only notify and update result if something has changed
657 if (shallowEqualObjects(nextResult, prevResult)) {
658 return
659 }
660β
661 this.#currentResult = nextResult
662β
663 const shouldNotifyListeners = (): boolean => {
664 if (!prevResult) {
665 return true
666 }
667β
668 const { notifyOnChangeProps } = this.options
669 const notifyOnChangePropsValue =
670 typeof notifyOnChangeProps === 'function'
671 ? notifyOnChangeProps()
672 : notifyOnChangeProps
673β
674 if (
675 notifyOnChangePropsValue === 'all' ||
676 (!notifyOnChangePropsValue && !this.#trackedProps.size)
677 ) {
678 return true
679 }
680β
681 const includedProps = new Set(
682 notifyOnChangePropsValue ?? this.#trackedProps,
683 )
684β
685 if (this.options.throwOnError) {
686 includedProps.add('error')
687 }
688β
689 return Object.keys(this.#currentResult).some((key) => {
690 const typedKey = key as keyof QueryObserverResult
691 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
692β
693 return changed && includedProps.has(typedKey)
694 })
695 }
696β
697 this.#notify({ listeners: shouldNotifyListeners() })
698 }
699β
700 #updateQuery(): void {
701 const query = this.#client.getQueryCache().build(this.#client, this.options)
702β
703 if (query === this.#currentQuery) {
704 return
705 }
706β
707 const prevQuery = this.#currentQuery as
708 | Query<TQueryFnData, TError, TQueryData, TQueryKey>
709 | undefined
710 this.#currentQuery = query
711 this.#currentQueryInitialState = query.state
712β
713 if (this.hasListeners()) {
714 prevQuery?.removeObserver(this)
715 query.addObserver(this)
716 }
717 }
718β
719 onQueryUpdate(): void {
720 this.updateResult()
721β
722 if (this.hasListeners()) {
723 this.#updateTimers()
724 }
725 }
726β
727 #notify(notifyOptions: { listeners: boolean }): void {
728 notifyManager.batch(() => {
729 // First, trigger the listeners
730 if (notifyOptions.listeners) {
731 this.listeners.forEach((listener) => {
732 listener(this.#currentResult)
733 })
734 }
735β
736 // Then the cache listeners
737 this.#client.getQueryCache().notify({
738 query: this.#currentQuery,
739 type: 'observerResultsUpdated',
740 })
741 })
742 }
743}
744β
745function shouldLoadOnMount(
746 query: Query<any, any, any, any>,
747 options: QueryObserverOptions<any, any, any, any>,
748): boolean {
749 return (
750 resolveEnabled(options.enabled, query) !== false &&
751 query.state.data === undefined &&
752 !(query.state.status === 'error' && options.retryOnMount === false)
753 )
754}
755β
756function shouldFetchOnMount(
757 query: Query<any, any, any, any>,
758 options: QueryObserverOptions<any, any, any, any, any>,
759): boolean {
760 return (
761 shouldLoadOnMount(query, options) ||
762 (query.state.data !== undefined &&
763 shouldFetchOn(query, options, options.refetchOnMount))
764 )
765}
766β
767function shouldFetchOn(
768 query: Query<any, any, any, any>,
769 options: QueryObserverOptions<any, any, any, any, any>,
770 field: (typeof options)['refetchOnMount'] &
771 (typeof options)['refetchOnWindowFocus'] &
772 (typeof options)['refetchOnReconnect'],
773) {
774 if (
775 resolveEnabled(options.enabled, query) !== false &&
776 resolveStaleTime(options.staleTime, query) !== 'static'
777 ) {
778 const value = typeof field === 'function' ? field(query) : field
779β
780 return value === 'always' || (value !== false && isStale(query, options))
781 }
782 return false
783}
784β
785function shouldFetchOptionally(
786 query: Query<any, any, any, any>,
787 prevQuery: Query<any, any, any, any>,
788 options: QueryObserverOptions<any, any, any, any, any>,
789 prevOptions: QueryObserverOptions<any, any, any, any, any>,
790): boolean {
791 return (
792 (query !== prevQuery ||
793 resolveEnabled(prevOptions.enabled, query) === false) &&
794 (!options.suspense || query.state.status !== 'error') &&
795 isStale(query, options)
796 )
797}
798β
799function isStale(
800 query: Query<any, any, any, any>,
801 options: QueryObserverOptions<any, any, any, any, any>,
802): boolean {
803 return (
804 resolveEnabled(options.enabled, query) !== false &&
805 query.isStaleByTime(resolveStaleTime(options.staleTime, query))
806 )
807}
808β
809// this function would decide if we will update the observer's 'current'
810// properties after an optimistic reading via getOptimisticResult
811function shouldAssignObserverCurrentProperties<
812 TQueryFnData = unknown,
813 TError = unknown,
814 TData = TQueryFnData,
815 TQueryData = TQueryFnData,
816 TQueryKey extends QueryKey = QueryKey,
817>(
818 observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
819 optimisticResult: QueryObserverResult<TData, TError>,
820) {
821 // if the newly created result isn't what the observer is holding as current,
822 // then we'll need to update the properties as well
823 if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
824 return true
825 }
826β
827 // basically, just keep previous properties if nothing changed
828 return false
829}