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 // 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 }
588β
589 const nextResult = result as QueryObserverResult<TData, TError>
590β
591 if (this.options.experimental_prefetchInRender) {
592 const finalizeThenableIfPossible = (thenable: PendingThenable<TData>) => {
593 if (nextResult.status === 'error') {
594 thenable.reject(nextResult.error)
595 } else if (nextResult.data !== undefined) {
596 thenable.resolve(nextResult.data)
597 }
598 }
599β
600 /**
601 * Create a new thenable and result promise when the results have changed
602 */
603 const recreateThenable = () => {
604 const pending =
605 (this.#currentThenable =
606 nextResult.promise =
607 pendingThenable())
608β
609 finalizeThenableIfPossible(pending)
610 }
611β
612 const prevThenable = this.#currentThenable
613 switch (prevThenable.status) {
614 case 'pending':
615 // Finalize the previous thenable if it was pending
616 // and we are still observing the same query
617 if (query.queryHash === prevQuery.queryHash) {
618 finalizeThenableIfPossible(prevThenable)
619 }
620 break
621 case 'fulfilled':
622 if (
623 nextResult.status === 'error' ||
624 nextResult.data !== prevThenable.value
625 ) {
626 recreateThenable()
627 }
628 break
629 case 'rejected':
630 if (
631 nextResult.status !== 'error' ||
632 nextResult.error !== prevThenable.reason
633 ) {
634 recreateThenable()
635 }
636 break
637 }
638 }
639β
640 return nextResult
641 }
642β
643 updateResult(): void {
644 const prevResult = this.#currentResult as
645 | QueryObserverResult<TData, TError>
646 | undefined
647β
648 const nextResult = this.createResult(this.#currentQuery, this.options)
649β
650 this.#currentResultState = this.#currentQuery.state
651 this.#currentResultOptions = this.options
652β
653 if (this.#currentResultState.data !== undefined) {
654 this.#lastQueryWithDefinedData = this.#currentQuery
655 }
656β
657 // Only notify and update result if something has changed
658 if (shallowEqualObjects(nextResult, prevResult)) {
659 return
660 }
661β
662 this.#currentResult = nextResult
663β
664 const shouldNotifyListeners = (): boolean => {
665 if (!prevResult) {
666 return true
667 }
668β
669 const { notifyOnChangeProps } = this.options
670 const notifyOnChangePropsValue =
671 typeof notifyOnChangeProps === 'function'
672 ? notifyOnChangeProps()
673 : notifyOnChangeProps
674β
675 if (
676 notifyOnChangePropsValue === 'all' ||
677 (!notifyOnChangePropsValue && !this.#trackedProps.size)
678 ) {
679 return true
680 }
681β
682 const includedProps = new Set(
683 notifyOnChangePropsValue ?? this.#trackedProps,
684 )
685β
686 if (this.options.throwOnError) {
687 includedProps.add('error')
688 }
689β
690 return Object.keys(this.#currentResult).some((key) => {
691 const typedKey = key as keyof QueryObserverResult
692 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
693β
694 return changed && includedProps.has(typedKey)
695 })
696 }
697β
698 this.#notify({ listeners: shouldNotifyListeners() })
699 }
700β
701 #updateQuery(): void {
702 const query = this.#client.getQueryCache().build(this.#client, this.options)
703β
704 if (query === this.#currentQuery) {
705 return
706 }
707β
708 const prevQuery = this.#currentQuery as
709 | Query<TQueryFnData, TError, TQueryData, TQueryKey>
710 | undefined
711 this.#currentQuery = query
712 this.#currentQueryInitialState = query.state
713β
714 if (this.hasListeners()) {
715 prevQuery?.removeObserver(this)
716 query.addObserver(this)
717 }
718 }
719β
720 onQueryUpdate(): void {
721 this.updateResult()
722β
723 if (this.hasListeners()) {
724 this.#updateTimers()
725 }
726 }
727β
728 #notify(notifyOptions: { listeners: boolean }): void {
729 notifyManager.batch(() => {
730 // First, trigger the listeners
731 if (notifyOptions.listeners) {
732 this.listeners.forEach((listener) => {
733 listener(this.#currentResult)
734 })
735 }
736β
737 // Then the cache listeners
738 this.#client.getQueryCache().notify({
739 query: this.#currentQuery,
740 type: 'observerResultsUpdated',
741 })
742 })
743 }
744}
745β
746function shouldLoadOnMount(
747 query: Query<any, any, any, any>,
748 options: QueryObserverOptions<any, any, any, any>,
749): boolean {
750 return (
751 resolveEnabled(options.enabled, query) !== false &&
752 query.state.data === undefined &&
753 !(query.state.status === 'error' && options.retryOnMount === false)
754 )
755}
756β
757function shouldFetchOnMount(
758 query: Query<any, any, any, any>,
759 options: QueryObserverOptions<any, any, any, any, any>,
760): boolean {
761 return (
762 shouldLoadOnMount(query, options) ||
763 (query.state.data !== undefined &&
764 shouldFetchOn(query, options, options.refetchOnMount))
765 )
766}
767β
768function shouldFetchOn(
769 query: Query<any, any, any, any>,
770 options: QueryObserverOptions<any, any, any, any, any>,
771 field: (typeof options)['refetchOnMount'] &
772 (typeof options)['refetchOnWindowFocus'] &
773 (typeof options)['refetchOnReconnect'],
774) {
775 if (resolveEnabled(options.enabled, query) !== false) {
776 const value = typeof field === 'function' ? field(query) : field
777β
778 return value === 'always' || (value !== false && isStale(query, options))
779 }
780 return false
781}
782β
783function shouldFetchOptionally(
784 query: Query<any, any, any, any>,
785 prevQuery: Query<any, any, any, any>,
786 options: QueryObserverOptions<any, any, any, any, any>,
787 prevOptions: QueryObserverOptions<any, any, any, any, any>,
788): boolean {
789 return (
790 (query !== prevQuery ||
791 resolveEnabled(prevOptions.enabled, query) === false) &&
792 (!options.suspense || query.state.status !== 'error') &&
793 isStale(query, options)
794 )
795}
796β
797function isStale(
798 query: Query<any, any, any, any>,
799 options: QueryObserverOptions<any, any, any, any, any>,
800): boolean {
801 return (
802 resolveEnabled(options.enabled, query) !== false &&
803 query.isStaleByTime(resolveStaleTime(options.staleTime, query))
804 )
805}
806β
807// this function would decide if we will update the observer's 'current'
808// properties after an optimistic reading via getOptimisticResult
809function shouldAssignObserverCurrentProperties<
810 TQueryFnData = unknown,
811 TError = unknown,
812 TData = TQueryFnData,
813 TQueryData = TQueryFnData,
814 TQueryKey extends QueryKey = QueryKey,
815>(
816 observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
817 optimisticResult: QueryObserverResult<TData, TError>,
818) {
819 // if the newly created result isn't what the observer is holding as current,
820 // then we'll need to update the properties as well
821 if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
822 return true
823 }
824β
825 // basically, just keep previous properties if nothing changed
826 return false
827}