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