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 if (!this.options.experimental_prefetchInRender) {
86 this.#currentThenable.reject(
87 new Error('experimental_prefetchInRender feature flag is not enabled'),
88 )
89 }
90β
91 this.bindMethods()
92 this.setOptions(options)
93 }
94β
95 protected bindMethods(): void {
96 this.refetch = this.refetch.bind(this)
97 }
98β
99 protected onSubscribe(): void {
100 if (this.listeners.size === 1) {
101 this.#currentQuery.addObserver(this)
102β
103 if (shouldFetchOnMount(this.#currentQuery, this.options)) {
104 this.#executeFetch()
105 } else {
106 this.updateResult()
107 }
108β
109 this.#updateTimers()
110 }
111 }
112β
113 protected onUnsubscribe(): void {
114 if (!this.hasListeners()) {
115 this.destroy()
116 }
117 }
118β
119 shouldFetchOnReconnect(): boolean {
120 return shouldFetchOn(
121 this.#currentQuery,
122 this.options,
123 this.options.refetchOnReconnect,
124 )
125 }
126β
127 shouldFetchOnWindowFocus(): boolean {
128 return shouldFetchOn(
129 this.#currentQuery,
130 this.options,
131 this.options.refetchOnWindowFocus,
132 )
133 }
134β
135 destroy(): void {
136 this.listeners = new Set()
137 this.#clearStaleTimeout()
138 this.#clearRefetchInterval()
139 this.#currentQuery.removeObserver(this)
140 }
141β
142 setOptions(
143 options: QueryObserverOptions<
144 TQueryFnData,
145 TError,
146 TData,
147 TQueryData,
148 TQueryKey
149 >,
150 ): void {
151 const prevOptions = this.options
152 const prevQuery = this.#currentQuery
153β
154 this.options = this.#client.defaultQueryOptions(options)
155β
156 if (
157 this.options.enabled !== undefined &&
158 typeof this.options.enabled !== 'boolean' &&
159 typeof this.options.enabled !== 'function' &&
160 typeof resolveEnabled(this.options.enabled, this.#currentQuery) !==
161 'boolean'
162 ) {
163 throw new Error(
164 'Expected enabled to be a boolean or a callback that returns a boolean',
165 )
166 }
167β
168 this.#updateQuery()
169 this.#currentQuery.setOptions(this.options)
170β
171 if (
172 prevOptions._defaulted &&
173 !shallowEqualObjects(this.options, prevOptions)
174 ) {
175 this.#client.getQueryCache().notify({
176 type: 'observerOptionsUpdated',
177 query: this.#currentQuery,
178 observer: this,
179 })
180 }
181β
182 const mounted = this.hasListeners()
183β
184 // Fetch if there are subscribers
185 if (
186 mounted &&
187 shouldFetchOptionally(
188 this.#currentQuery,
189 prevQuery,
190 this.options,
191 prevOptions,
192 )
193 ) {
194 this.#executeFetch()
195 }
196β
197 // Update result
198 this.updateResult()
199β
200 // Update stale interval if needed
201 if (
202 mounted &&
203 (this.#currentQuery !== prevQuery ||
204 resolveEnabled(this.options.enabled, this.#currentQuery) !==
205 resolveEnabled(prevOptions.enabled, this.#currentQuery) ||
206 resolveStaleTime(this.options.staleTime, this.#currentQuery) !==
207 resolveStaleTime(prevOptions.staleTime, this.#currentQuery))
208 ) {
209 this.#updateStaleTimeout()
210 }
211β
212 const nextRefetchInterval = this.#computeRefetchInterval()
213β
214 // Update refetch interval if needed
215 if (
216 mounted &&
217 (this.#currentQuery !== prevQuery ||
218 resolveEnabled(this.options.enabled, this.#currentQuery) !==
219 resolveEnabled(prevOptions.enabled, this.#currentQuery) ||
220 nextRefetchInterval !== this.#currentRefetchInterval)
221 ) {
222 this.#updateRefetchInterval(nextRefetchInterval)
223 }
224 }
225β
226 getOptimisticResult(
227 options: DefaultedQueryObserverOptions<
228 TQueryFnData,
229 TError,
230 TData,
231 TQueryData,
232 TQueryKey
233 >,
234 ): QueryObserverResult<TData, TError> {
235 const query = this.#client.getQueryCache().build(this.#client, options)
236β
237 const result = this.createResult(query, options)
238β
239 if (shouldAssignObserverCurrentProperties(this, result)) {
240 // this assigns the optimistic result to the current Observer
241 // because if the query function changes, useQuery will be performing
242 // an effect where it would fetch again.
243 // When the fetch finishes, we perform a deep data cloning in order
244 // to reuse objects references. This deep data clone is performed against
245 // the `observer.currentResult.data` property
246 // When QueryKey changes, we refresh the query and get new `optimistic`
247 // result, while we leave the `observer.currentResult`, so when new data
248 // arrives, it finds the old `observer.currentResult` which is related
249 // to the old QueryKey. Which means that currentResult and selectData are
250 // out of sync already.
251 // To solve this, we move the cursor of the currentResult every time
252 // an observer reads an optimistic value.
253β
254 // When keeping the previous data, the result doesn't change until new
255 // data arrives.
256 this.#currentResult = result
257 this.#currentResultOptions = this.options
258 this.#currentResultState = this.#currentQuery.state
259 }
260 return result
261 }
262β
263 getCurrentResult(): QueryObserverResult<TData, TError> {
264 return this.#currentResult
265 }
266β
267 trackResult(
268 result: QueryObserverResult<TData, TError>,
269 onPropTracked?: (key: keyof QueryObserverResult) => void,
270 ): QueryObserverResult<TData, TError> {
271 const trackedResult = {} as QueryObserverResult<TData, TError>
272β
273 Object.keys(result).forEach((key) => {
274 Object.defineProperty(trackedResult, key, {
275 configurable: false,
276 enumerable: true,
277 get: () => {
278 this.trackProp(key as keyof QueryObserverResult)
279 onPropTracked?.(key as keyof QueryObserverResult)
280 return result[key as keyof QueryObserverResult]
281 },
282 })
283 })
284β
285 return trackedResult
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 = 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 = 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 clearTimeout(this.#staleTimeoutId)
417 this.#staleTimeoutId = undefined
418 }
419 }
420β
421 #clearRefetchInterval(): void {
422 if (this.#refetchIntervalId) {
423 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 // Select data if needed
478 if (options.select && newState.data !== undefined) {
479 // Memoize select result
480 if (
481 prevResult &&
482 newState.data === prevResultState?.data &&
483 options.select === this.#selectFn
484 ) {
485 data = this.#selectResult
486 } else {
487 try {
488 this.#selectFn = options.select
489 data = options.select(newState.data)
490 data = replaceData(prevResult?.data, data, options)
491 this.#selectResult = data
492 this.#selectError = null
493 } catch (selectError) {
494 this.#selectError = selectError as TError
495 }
496 }
497 }
498 // Use query data
499 else {
500 data = newState.data as unknown as TData
501 }
502β
503 // Show placeholder data if needed
504 if (
505 options.placeholderData !== undefined &&
506 data === undefined &&
507 status === 'pending'
508 ) {
509 let placeholderData
510β
511 // Memoize placeholder data
512 if (
513 prevResult?.isPlaceholderData &&
514 options.placeholderData === prevResultOptions?.placeholderData
515 ) {
516 placeholderData = prevResult.data
517 } else {
518 placeholderData =
519 typeof options.placeholderData === 'function'
520 ? (
521 options.placeholderData as unknown as PlaceholderDataFunction<TQueryData>
522 )(
523 this.#lastQueryWithDefinedData?.state.data,
524 this.#lastQueryWithDefinedData as any,
525 )
526 : options.placeholderData
527 if (options.select && placeholderData !== undefined) {
528 try {
529 placeholderData = options.select(placeholderData)
530 this.#selectError = null
531 } catch (selectError) {
532 this.#selectError = selectError as TError
533 }
534 }
535 }
536β
537 if (placeholderData !== undefined) {
538 status = 'success'
539 data = replaceData(
540 prevResult?.data,
541 placeholderData as unknown,
542 options,
543 ) as TData
544 isPlaceholderData = true
545 }
546 }
547β
548 if (this.#selectError) {
549 error = this.#selectError as any
550 data = this.#selectResult
551 errorUpdatedAt = Date.now()
552 status = 'error'
553 }
554β
555 const isFetching = newState.fetchStatus === 'fetching'
556 const isPending = status === 'pending'
557 const isError = status === 'error'
558β
559 const isLoading = isPending && isFetching
560 const hasData = data !== undefined
561β
562 const result: QueryObserverBaseResult<TData, TError> = {
563 status,
564 fetchStatus: newState.fetchStatus,
565 isPending,
566 isSuccess: status === 'success',
567 isError,
568 isInitialLoading: isLoading,
569 isLoading,
570 data,
571 dataUpdatedAt: newState.dataUpdatedAt,
572 error,
573 errorUpdatedAt,
574 failureCount: newState.fetchFailureCount,
575 failureReason: newState.fetchFailureReason,
576 errorUpdateCount: newState.errorUpdateCount,
577 isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
578 isFetchedAfterMount:
579 newState.dataUpdateCount > queryInitialState.dataUpdateCount ||
580 newState.errorUpdateCount > queryInitialState.errorUpdateCount,
581 isFetching,
582 isRefetching: isFetching && !isPending,
583 isLoadingError: isError && !hasData,
584 isPaused: newState.fetchStatus === 'paused',
585 isPlaceholderData,
586 isRefetchError: isError && hasData,
587 isStale: isStale(query, options),
588 refetch: this.refetch,
589 promise: this.#currentThenable,
590 }
591β
592 const nextResult = result as QueryObserverResult<TData, TError>
593β
594 if (this.options.experimental_prefetchInRender) {
595 const finalizeThenableIfPossible = (thenable: PendingThenable<TData>) => {
596 if (nextResult.status === 'error') {
597 thenable.reject(nextResult.error)
598 } else if (nextResult.data !== undefined) {
599 thenable.resolve(nextResult.data)
600 }
601 }
602β
603 /**
604 * Create a new thenable and result promise when the results have changed
605 */
606 const recreateThenable = () => {
607 const pending =
608 (this.#currentThenable =
609 nextResult.promise =
610 pendingThenable())
611β
612 finalizeThenableIfPossible(pending)
613 }
614β
615 const prevThenable = this.#currentThenable
616 switch (prevThenable.status) {
617 case 'pending':
618 // Finalize the previous thenable if it was pending
619 // and we are still observing the same query
620 if (query.queryHash === prevQuery.queryHash) {
621 finalizeThenableIfPossible(prevThenable)
622 }
623 break
624 case 'fulfilled':
625 if (
626 nextResult.status === 'error' ||
627 nextResult.data !== prevThenable.value
628 ) {
629 recreateThenable()
630 }
631 break
632 case 'rejected':
633 if (
634 nextResult.status !== 'error' ||
635 nextResult.error !== prevThenable.reason
636 ) {
637 recreateThenable()
638 }
639 break
640 }
641 }
642β
643 return nextResult
644 }
645β
646 updateResult(): void {
647 const prevResult = this.#currentResult as
648 | QueryObserverResult<TData, TError>
649 | undefined
650β
651 const nextResult = this.createResult(this.#currentQuery, this.options)
652β
653 this.#currentResultState = this.#currentQuery.state
654 this.#currentResultOptions = this.options
655β
656 if (this.#currentResultState.data !== undefined) {
657 this.#lastQueryWithDefinedData = this.#currentQuery
658 }
659β
660 // Only notify and update result if something has changed
661 if (shallowEqualObjects(nextResult, prevResult)) {
662 return
663 }
664β
665 this.#currentResult = nextResult
666β
667 const shouldNotifyListeners = (): boolean => {
668 if (!prevResult) {
669 return true
670 }
671β
672 const { notifyOnChangeProps } = this.options
673 const notifyOnChangePropsValue =
674 typeof notifyOnChangeProps === 'function'
675 ? notifyOnChangeProps()
676 : notifyOnChangeProps
677β
678 if (
679 notifyOnChangePropsValue === 'all' ||
680 (!notifyOnChangePropsValue && !this.#trackedProps.size)
681 ) {
682 return true
683 }
684β
685 const includedProps = new Set(
686 notifyOnChangePropsValue ?? this.#trackedProps,
687 )
688β
689 if (this.options.throwOnError) {
690 includedProps.add('error')
691 }
692β
693 return Object.keys(this.#currentResult).some((key) => {
694 const typedKey = key as keyof QueryObserverResult
695 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
696β
697 return changed && includedProps.has(typedKey)
698 })
699 }
700β
701 this.#notify({ listeners: shouldNotifyListeners() })
702 }
703β
704 #updateQuery(): void {
705 const query = this.#client.getQueryCache().build(this.#client, this.options)
706β
707 if (query === this.#currentQuery) {
708 return
709 }
710β
711 const prevQuery = this.#currentQuery as
712 | Query<TQueryFnData, TError, TQueryData, TQueryKey>
713 | undefined
714 this.#currentQuery = query
715 this.#currentQueryInitialState = query.state
716β
717 if (this.hasListeners()) {
718 prevQuery?.removeObserver(this)
719 query.addObserver(this)
720 }
721 }
722β
723 onQueryUpdate(): void {
724 this.updateResult()
725β
726 if (this.hasListeners()) {
727 this.#updateTimers()
728 }
729 }
730β
731 #notify(notifyOptions: { listeners: boolean }): void {
732 notifyManager.batch(() => {
733 // First, trigger the listeners
734 if (notifyOptions.listeners) {
735 this.listeners.forEach((listener) => {
736 listener(this.#currentResult)
737 })
738 }
739β
740 // Then the cache listeners
741 this.#client.getQueryCache().notify({
742 query: this.#currentQuery,
743 type: 'observerResultsUpdated',
744 })
745 })
746 }
747}
748β
749function shouldLoadOnMount(
750 query: Query<any, any, any, any>,
751 options: QueryObserverOptions<any, any, any, any>,
752): boolean {
753 return (
754 resolveEnabled(options.enabled, query) !== false &&
755 query.state.data === undefined &&
756 !(query.state.status === 'error' && options.retryOnMount === false)
757 )
758}
759β
760function shouldFetchOnMount(
761 query: Query<any, any, any, any>,
762 options: QueryObserverOptions<any, any, any, any, any>,
763): boolean {
764 return (
765 shouldLoadOnMount(query, options) ||
766 (query.state.data !== undefined &&
767 shouldFetchOn(query, options, options.refetchOnMount))
768 )
769}
770β
771function shouldFetchOn(
772 query: Query<any, any, any, any>,
773 options: QueryObserverOptions<any, any, any, any, any>,
774 field: (typeof options)['refetchOnMount'] &
775 (typeof options)['refetchOnWindowFocus'] &
776 (typeof options)['refetchOnReconnect'],
777) {
778 if (resolveEnabled(options.enabled, query) !== false) {
779 const value = typeof field === 'function' ? field(query) : field
780β
781 return value === 'always' || (value !== false && isStale(query, options))
782 }
783 return false
784}
785β
786function shouldFetchOptionally(
787 query: Query<any, any, any, any>,
788 prevQuery: Query<any, any, any, any>,
789 options: QueryObserverOptions<any, any, any, any, any>,
790 prevOptions: QueryObserverOptions<any, any, any, any, any>,
791): boolean {
792 return (
793 (query !== prevQuery ||
794 resolveEnabled(prevOptions.enabled, query) === false) &&
795 (!options.suspense || query.state.status !== 'error') &&
796 isStale(query, options)
797 )
798}
799β
800function isStale(
801 query: Query<any, any, any, any>,
802 options: QueryObserverOptions<any, any, any, any, any>,
803): boolean {
804 return (
805 resolveEnabled(options.enabled, query) !== false &&
806 query.isStaleByTime(resolveStaleTime(options.staleTime, query))
807 )
808}
809β
810// this function would decide if we will update the observer's 'current'
811// properties after an optimistic reading via getOptimisticResult
812function shouldAssignObserverCurrentProperties<
813 TQueryFnData = unknown,
814 TError = unknown,
815 TData = TQueryFnData,
816 TQueryData = TQueryFnData,
817 TQueryKey extends QueryKey = QueryKey,
818>(
819 observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
820 optimisticResult: QueryObserverResult<TData, TError>,
821) {
822 // if the newly created result isn't what the observer is holding as current,
823 // then we'll need to update the properties as well
824 if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
825 return true
826 }
827β
828 // basically, just keep previous properties if nothing changed
829 return false
830}