@tanstack/query-core 5.28.2 → 5.28.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/query.cjs +17 -10
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +15 -9
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/{queryClient-UWB6EkqM.d.ts → queryClient-6vLRMq5C.d.ts} +8 -1
- package/build/legacy/{queryClient-WxLAyIG_.d.cts → queryClient-C_S9rQE6.d.cts} +8 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryObserver.cjs +22 -21
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +22 -21
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/query.cjs +17 -10
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js +15 -9
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/{queryClient-UWB6EkqM.d.ts → queryClient-6vLRMq5C.d.ts} +8 -1
- package/build/modern/{queryClient-WxLAyIG_.d.cts → queryClient-C_S9rQE6.d.cts} +8 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryObserver.cjs +22 -21
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +22 -21
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/package.json +2 -1
- package/src/query.ts +22 -9
- package/src/queryObserver.ts +24 -24
- /package/src/{tests → __tests__}/focusManager.test.tsx +0 -0
- /package/src/{tests → __tests__}/hydration.test.tsx +0 -0
- /package/src/{tests → __tests__}/infiniteQueryBehavior.test.tsx +0 -0
- /package/src/{tests → __tests__}/infiniteQueryObserver.test-d.tsx +0 -0
- /package/src/{tests → __tests__}/infiniteQueryObserver.test.tsx +0 -0
- /package/src/{tests → __tests__}/mutationCache.test.tsx +0 -0
- /package/src/{tests → __tests__}/mutationObserver.test.tsx +0 -0
- /package/src/{tests → __tests__}/mutations.test.tsx +0 -0
- /package/src/{tests → __tests__}/notifyManager.test.tsx +0 -0
- /package/src/{tests → __tests__}/onlineManager.test.tsx +0 -0
- /package/src/{tests → __tests__}/queriesObserver.test.tsx +0 -0
- /package/src/{tests → __tests__}/query.test.tsx +0 -0
- /package/src/{tests → __tests__}/queryCache.test.tsx +0 -0
- /package/src/{tests → __tests__}/queryClient.test-d.tsx +0 -0
- /package/src/{tests → __tests__}/queryClient.test.tsx +0 -0
- /package/src/{tests → __tests__}/queryObserver.test-d.tsx +0 -0
- /package/src/{tests → __tests__}/queryObserver.test.tsx +0 -0
- /package/src/{tests → __tests__}/utils.test.tsx +0 -0
- /package/src/{tests → __tests__}/utils.ts +0 -0
package/src/query.ts
CHANGED
|
@@ -552,16 +552,8 @@ export class Query<
|
|
|
552
552
|
case 'fetch':
|
|
553
553
|
return {
|
|
554
554
|
...state,
|
|
555
|
-
|
|
556
|
-
fetchFailureReason: null,
|
|
555
|
+
...fetchState(state.data, this.options),
|
|
557
556
|
fetchMeta: action.meta ?? null,
|
|
558
|
-
fetchStatus: canFetch(this.options.networkMode)
|
|
559
|
-
? 'fetching'
|
|
560
|
-
: 'paused',
|
|
561
|
-
...(state.data === undefined && {
|
|
562
|
-
error: null,
|
|
563
|
-
status: 'pending',
|
|
564
|
-
}),
|
|
565
557
|
}
|
|
566
558
|
case 'success':
|
|
567
559
|
return {
|
|
@@ -620,6 +612,27 @@ export class Query<
|
|
|
620
612
|
}
|
|
621
613
|
}
|
|
622
614
|
|
|
615
|
+
export function fetchState<
|
|
616
|
+
TQueryFnData,
|
|
617
|
+
TError,
|
|
618
|
+
TData,
|
|
619
|
+
TQueryKey extends QueryKey,
|
|
620
|
+
>(
|
|
621
|
+
data: TData | undefined,
|
|
622
|
+
options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
623
|
+
) {
|
|
624
|
+
return {
|
|
625
|
+
fetchFailureCount: 0,
|
|
626
|
+
fetchFailureReason: null,
|
|
627
|
+
fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',
|
|
628
|
+
...(data === undefined &&
|
|
629
|
+
({
|
|
630
|
+
error: null,
|
|
631
|
+
status: 'pending',
|
|
632
|
+
} as const)),
|
|
633
|
+
} as const
|
|
634
|
+
}
|
|
635
|
+
|
|
623
636
|
function getDefaultState<
|
|
624
637
|
TQueryFnData,
|
|
625
638
|
TError,
|
package/src/queryObserver.ts
CHANGED
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
import { notifyManager } from './notifyManager'
|
|
10
10
|
import { focusManager } from './focusManager'
|
|
11
11
|
import { Subscribable } from './subscribable'
|
|
12
|
-
import {
|
|
13
|
-
import type { QueryClient } from './queryClient'
|
|
12
|
+
import { fetchState } from './query'
|
|
14
13
|
import type { FetchOptions, Query, QueryState } from './query'
|
|
14
|
+
import type { QueryClient } from './queryClient'
|
|
15
15
|
import type {
|
|
16
16
|
DefaultError,
|
|
17
17
|
DefaultedQueryObserverOptions,
|
|
@@ -437,7 +437,7 @@ export class QueryObserver<
|
|
|
437
437
|
: this.#currentQueryInitialState
|
|
438
438
|
|
|
439
439
|
const { state } = query
|
|
440
|
-
let
|
|
440
|
+
let newState = { ...state }
|
|
441
441
|
let isPlaceholderData = false
|
|
442
442
|
let data: TData | undefined
|
|
443
443
|
|
|
@@ -451,31 +451,31 @@ export class QueryObserver<
|
|
|
451
451
|
mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)
|
|
452
452
|
|
|
453
453
|
if (fetchOnMount || fetchOptionally) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if (state.data === undefined) {
|
|
458
|
-
status = 'pending'
|
|
454
|
+
newState = {
|
|
455
|
+
...newState,
|
|
456
|
+
...fetchState(state.data, query.options),
|
|
459
457
|
}
|
|
460
458
|
}
|
|
461
459
|
if (options._optimisticResults === 'isRestoring') {
|
|
462
|
-
fetchStatus = 'idle'
|
|
460
|
+
newState.fetchStatus = 'idle'
|
|
463
461
|
}
|
|
464
462
|
}
|
|
465
463
|
|
|
464
|
+
let { error, errorUpdatedAt, status } = newState
|
|
465
|
+
|
|
466
466
|
// Select data if needed
|
|
467
|
-
if (options.select &&
|
|
467
|
+
if (options.select && newState.data !== undefined) {
|
|
468
468
|
// Memoize select result
|
|
469
469
|
if (
|
|
470
470
|
prevResult &&
|
|
471
|
-
|
|
471
|
+
newState.data === prevResultState?.data &&
|
|
472
472
|
options.select === this.#selectFn
|
|
473
473
|
) {
|
|
474
474
|
data = this.#selectResult
|
|
475
475
|
} else {
|
|
476
476
|
try {
|
|
477
477
|
this.#selectFn = options.select
|
|
478
|
-
data = options.select(
|
|
478
|
+
data = options.select(newState.data)
|
|
479
479
|
data = replaceData(prevResult?.data, data, options)
|
|
480
480
|
this.#selectResult = data
|
|
481
481
|
this.#selectError = null
|
|
@@ -486,7 +486,7 @@ export class QueryObserver<
|
|
|
486
486
|
}
|
|
487
487
|
// Use query data
|
|
488
488
|
else {
|
|
489
|
-
data =
|
|
489
|
+
data = newState.data as unknown as TData
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
// Show placeholder data if needed
|
|
@@ -541,36 +541,36 @@ export class QueryObserver<
|
|
|
541
541
|
status = 'error'
|
|
542
542
|
}
|
|
543
543
|
|
|
544
|
-
const isFetching = fetchStatus === 'fetching'
|
|
544
|
+
const isFetching = newState.fetchStatus === 'fetching'
|
|
545
545
|
const isPending = status === 'pending'
|
|
546
546
|
const isError = status === 'error'
|
|
547
547
|
|
|
548
548
|
const isLoading = isPending && isFetching
|
|
549
|
-
const hasData =
|
|
549
|
+
const hasData = data !== undefined
|
|
550
550
|
|
|
551
551
|
const result: QueryObserverBaseResult<TData, TError> = {
|
|
552
552
|
status,
|
|
553
|
-
fetchStatus,
|
|
553
|
+
fetchStatus: newState.fetchStatus,
|
|
554
554
|
isPending,
|
|
555
555
|
isSuccess: status === 'success',
|
|
556
556
|
isError,
|
|
557
557
|
isInitialLoading: isLoading,
|
|
558
558
|
isLoading,
|
|
559
559
|
data,
|
|
560
|
-
dataUpdatedAt:
|
|
560
|
+
dataUpdatedAt: newState.dataUpdatedAt,
|
|
561
561
|
error,
|
|
562
562
|
errorUpdatedAt,
|
|
563
|
-
failureCount:
|
|
564
|
-
failureReason:
|
|
565
|
-
errorUpdateCount:
|
|
566
|
-
isFetched:
|
|
563
|
+
failureCount: newState.fetchFailureCount,
|
|
564
|
+
failureReason: newState.fetchFailureReason,
|
|
565
|
+
errorUpdateCount: newState.errorUpdateCount,
|
|
566
|
+
isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
|
|
567
567
|
isFetchedAfterMount:
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
newState.dataUpdateCount > queryInitialState.dataUpdateCount ||
|
|
569
|
+
newState.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
570
570
|
isFetching,
|
|
571
571
|
isRefetching: isFetching && !isPending,
|
|
572
572
|
isLoadingError: isError && !hasData,
|
|
573
|
-
isPaused: fetchStatus === 'paused',
|
|
573
|
+
isPaused: newState.fetchStatus === 'paused',
|
|
574
574
|
isPlaceholderData,
|
|
575
575
|
isRefetchError: isError && hasData,
|
|
576
576
|
isStale: isStale(query, options),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|