@tanstack/query-core 5.101.4 → 5.102.1
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/classPrivateFieldSet2-Bo0ZyOIv.cjs +56 -0
- package/build/legacy/classPrivateFieldSet2-CV7wyte-.js +27 -0
- package/build/legacy/classPrivateMethodInitSpec-CBwa_Y7C.js +7 -0
- package/build/legacy/classPrivateMethodInitSpec-DVhcLejn.cjs +12 -0
- package/build/legacy/environmentManager.cjs +25 -46
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +18 -2
- package/build/legacy/environmentManager.d.cts.map +1 -0
- package/build/legacy/environmentManager.d.ts +18 -2
- package/build/legacy/environmentManager.d.ts.map +1 -0
- package/build/legacy/environmentManager.js +23 -22
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +63 -104
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +18 -2
- package/build/legacy/focusManager.d.cts.map +1 -0
- package/build/legacy/focusManager.d.ts +18 -2
- package/build/legacy/focusManager.d.ts.map +1 -0
- package/build/legacy/focusManager.js +60 -76
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/hydration-BhSbkfZj.d.cts +1374 -0
- package/build/legacy/hydration-BhSbkfZj.d.cts.map +1 -0
- package/build/legacy/hydration-Hebl6yHM.d.ts +1374 -0
- package/build/legacy/hydration-Hebl6yHM.d.ts.map +1 -0
- package/build/legacy/hydration.cjs +111 -194
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +2 -7
- package/build/legacy/hydration.d.ts +2 -7
- package/build/legacy/hydration.js +105 -167
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.cjs +59 -111
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +10 -141
- package/build/legacy/index.d.ts +10 -141
- package/build/legacy/index.js +16 -66
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +92 -135
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +14 -3
- package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -0
- package/build/legacy/infiniteQueryBehavior.d.ts +14 -3
- package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/legacy/infiniteQueryBehavior.js +89 -115
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +59 -88
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +20 -1
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -0
- package/build/legacy/infiniteQueryObserver.d.ts +20 -1
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -0
- package/build/legacy/infiniteQueryObserver.js +57 -64
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +236 -329
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +2 -4
- package/build/legacy/mutation.d.ts +2 -4
- package/build/legacy/mutation.js +231 -299
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +121 -166
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +2 -2
- package/build/legacy/mutationCache.d.ts +2 -2
- package/build/legacy/mutationCache.js +117 -130
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +134 -187
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +2 -1
- package/build/legacy/mutationObserver.d.ts +2 -1
- package/build/legacy/mutationObserver.js +132 -160
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +76 -110
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +48 -3
- package/build/legacy/notifyManager.d.cts.map +1 -0
- package/build/legacy/notifyManager.d.ts +48 -3
- package/build/legacy/notifyManager.d.ts.map +1 -0
- package/build/legacy/notifyManager.js +73 -84
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +57 -93
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +17 -2
- package/build/legacy/onlineManager.d.cts.map +1 -0
- package/build/legacy/onlineManager.d.ts +17 -2
- package/build/legacy/onlineManager.d.ts.map +1 -0
- package/build/legacy/onlineManager.js +54 -65
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +203 -262
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +23 -2
- package/build/legacy/queriesObserver.d.cts.map +1 -0
- package/build/legacy/queriesObserver.d.ts +23 -2
- package/build/legacy/queriesObserver.d.ts.map +1 -0
- package/build/legacy/queriesObserver.js +199 -233
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +409 -491
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +2 -9
- package/build/legacy/query.d.ts +2 -9
- package/build/legacy/query.js +402 -467
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +99 -128
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +2 -3
- package/build/legacy/queryCache.d.ts +2 -3
- package/build/legacy/queryCache.js +96 -100
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +295 -345
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +2 -1
- package/build/legacy/queryClient.d.ts +2 -1
- package/build/legacy/queryClient.js +292 -318
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +350 -502
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +2 -1
- package/build/legacy/queryObserver.d.ts +2 -1
- package/build/legacy/queryObserver.js +345 -480
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/removable-DeMjhW5M.d.cts +13 -0
- package/build/legacy/removable-DeMjhW5M.d.cts.map +1 -0
- package/build/legacy/removable-DeMjhW5M.d.ts +13 -0
- package/build/legacy/removable-DeMjhW5M.d.ts.map +1 -0
- package/build/legacy/removable.cjs +31 -67
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +2 -1
- package/build/legacy/removable.d.ts +2 -1
- package/build/legacy/removable.js +28 -39
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs +127 -155
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +2 -7
- package/build/legacy/retryer.d.ts +2 -7
- package/build/legacy/retryer.js +121 -127
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +49 -78
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +33 -1
- package/build/legacy/streamedQuery.d.cts.map +1 -0
- package/build/legacy/streamedQuery.d.ts +33 -1
- package/build/legacy/streamedQuery.d.ts.map +1 -0
- package/build/legacy/streamedQuery.js +47 -54
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/subscribable-CbifVTKz.d.cts +12 -0
- package/build/legacy/subscribable-CbifVTKz.d.cts.map +1 -0
- package/build/legacy/subscribable-CbifVTKz.d.ts +12 -0
- package/build/legacy/subscribable-CbifVTKz.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +22 -48
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +2 -1
- package/build/legacy/subscribable.d.ts +2 -1
- package/build/legacy/subscribable.js +21 -25
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +64 -105
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +60 -7
- package/build/legacy/timeoutManager.d.cts.map +1 -0
- package/build/legacy/timeoutManager.d.ts +60 -7
- package/build/legacy/timeoutManager.d.ts.map +1 -0
- package/build/legacy/timeoutManager.js +60 -76
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs +10 -35
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +2 -94
- package/build/legacy/types.d.ts +2 -94
- package/build/legacy/types.js +7 -10
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +175 -300
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +2 -30
- package/build/legacy/utils.d.ts +2 -30
- package/build/legacy/utils.js +149 -252
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +25 -46
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +18 -2
- package/build/modern/environmentManager.d.cts.map +1 -0
- package/build/modern/environmentManager.d.ts +18 -2
- package/build/modern/environmentManager.d.ts.map +1 -0
- package/build/modern/environmentManager.js +23 -20
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +56 -90
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +18 -2
- package/build/modern/focusManager.d.cts.map +1 -0
- package/build/modern/focusManager.d.ts +18 -2
- package/build/modern/focusManager.d.ts.map +1 -0
- package/build/modern/focusManager.js +53 -63
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/hydration-BhSbkfZj.d.cts +1374 -0
- package/build/modern/hydration-BhSbkfZj.d.cts.map +1 -0
- package/build/modern/hydration-Hebl6yHM.d.ts +1374 -0
- package/build/modern/hydration-Hebl6yHM.d.ts.map +1 -0
- package/build/modern/hydration.cjs +102 -189
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +2 -7
- package/build/modern/hydration.d.ts +2 -7
- package/build/modern/hydration.js +96 -160
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.cjs +59 -111
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +10 -141
- package/build/modern/index.d.ts +10 -141
- package/build/modern/index.js +16 -64
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +89 -131
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +14 -3
- package/build/modern/infiniteQueryBehavior.d.cts.map +1 -0
- package/build/modern/infiniteQueryBehavior.d.ts +14 -3
- package/build/modern/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/modern/infiniteQueryBehavior.js +86 -109
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs +58 -87
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +20 -1
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -0
- package/build/modern/infiniteQueryObserver.d.ts +20 -1
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -0
- package/build/modern/infiniteQueryObserver.js +56 -61
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +221 -303
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +2 -4
- package/build/modern/mutation.d.ts +2 -4
- package/build/modern/mutation.js +216 -274
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +111 -145
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +2 -2
- package/build/modern/mutationCache.d.ts +2 -2
- package/build/modern/mutationCache.js +107 -117
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +115 -162
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +2 -1
- package/build/modern/mutationObserver.d.ts +2 -1
- package/build/modern/mutationObserver.js +113 -136
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +76 -110
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +48 -3
- package/build/modern/notifyManager.d.cts.map +1 -0
- package/build/modern/notifyManager.d.ts +48 -3
- package/build/modern/notifyManager.d.ts.map +1 -0
- package/build/modern/notifyManager.js +73 -82
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +51 -80
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +17 -2
- package/build/modern/onlineManager.d.cts.map +1 -0
- package/build/modern/onlineManager.d.ts +17 -2
- package/build/modern/onlineManager.d.ts.map +1 -0
- package/build/modern/onlineManager.js +48 -53
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +185 -237
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +23 -2
- package/build/modern/queriesObserver.d.cts.map +1 -0
- package/build/modern/queriesObserver.d.ts +23 -2
- package/build/modern/queriesObserver.d.ts.map +1 -0
- package/build/modern/queriesObserver.js +181 -209
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +384 -464
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +2 -9
- package/build/modern/query.d.ts +2 -9
- package/build/modern/query.js +377 -441
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +97 -119
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +2 -3
- package/build/modern/queryCache.d.ts +2 -3
- package/build/modern/queryCache.js +94 -92
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +281 -318
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +2 -1
- package/build/modern/queryClient.d.ts +2 -1
- package/build/modern/queryClient.js +278 -299
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +329 -475
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +2 -1
- package/build/modern/queryObserver.d.ts +2 -1
- package/build/modern/queryObserver.js +324 -454
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/removable-DeMjhW5M.d.cts +13 -0
- package/build/modern/removable-DeMjhW5M.d.cts.map +1 -0
- package/build/modern/removable-DeMjhW5M.d.ts +13 -0
- package/build/modern/removable-DeMjhW5M.d.ts.map +1 -0
- package/build/modern/removable.cjs +27 -56
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +2 -1
- package/build/modern/removable.d.ts +2 -1
- package/build/modern/removable.js +24 -29
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs +121 -151
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +2 -7
- package/build/modern/retryer.d.ts +2 -7
- package/build/modern/retryer.js +115 -121
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +49 -78
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +33 -1
- package/build/modern/streamedQuery.d.cts.map +1 -0
- package/build/modern/streamedQuery.d.ts +33 -1
- package/build/modern/streamedQuery.d.ts.map +1 -0
- package/build/modern/streamedQuery.js +47 -52
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/subscribable-CbifVTKz.d.cts +12 -0
- package/build/modern/subscribable-CbifVTKz.d.cts.map +1 -0
- package/build/modern/subscribable-CbifVTKz.d.ts +12 -0
- package/build/modern/subscribable-CbifVTKz.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +22 -48
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +2 -1
- package/build/modern/subscribable.d.ts +2 -1
- package/build/modern/subscribable.js +21 -23
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs +59 -93
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +60 -7
- package/build/modern/timeoutManager.d.cts.map +1 -0
- package/build/modern/timeoutManager.d.ts +60 -7
- package/build/modern/timeoutManager.d.ts.map +1 -0
- package/build/modern/timeoutManager.js +55 -65
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs +10 -35
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +2 -94
- package/build/modern/types.d.ts +2 -94
- package/build/modern/types.js +8 -9
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +175 -300
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +2 -30
- package/build/modern/utils.d.ts +2 -30
- package/build/modern/utils.js +149 -250
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -5
- package/src/hydration.ts +65 -56
- package/src/index.ts +1 -0
- package/src/mutation.ts +14 -6
- package/src/mutationObserver.ts +8 -0
- package/src/queriesObserver.ts +14 -8
- package/src/query.ts +14 -6
- package/src/queryClient.ts +90 -2
- package/src/queryObserver.ts +41 -64
- package/src/retryer.ts +20 -12
- package/src/types.ts +70 -58
- package/build/legacy/_tsup-dts-rollup.d.cts +0 -2188
- package/build/legacy/_tsup-dts-rollup.d.ts +0 -2188
- package/build/legacy/chunk-PXG64RU4.js +0 -25
- package/build/legacy/chunk-PXG64RU4.js.map +0 -1
- package/build/legacy/thenable.cjs +0 -76
- package/build/legacy/thenable.cjs.map +0 -1
- package/build/legacy/thenable.d.cts +0 -6
- package/build/legacy/thenable.d.ts +0 -6
- package/build/legacy/thenable.js +0 -52
- package/build/legacy/thenable.js.map +0 -1
- package/build/modern/_tsup-dts-rollup.d.cts +0 -2188
- package/build/modern/_tsup-dts-rollup.d.ts +0 -2188
- package/build/modern/thenable.cjs +0 -75
- package/build/modern/thenable.cjs.map +0 -1
- package/build/modern/thenable.d.cts +0 -6
- package/build/modern/thenable.d.ts +0 -6
- package/build/modern/thenable.js +0 -49
- package/build/modern/thenable.js.map +0 -1
- package/src/thenable.ts +0 -111
package/src/queryObserver.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { environmentManager } from './environmentManager'
|
|
|
3
3
|
import { notifyManager } from './notifyManager'
|
|
4
4
|
import { fetchState } from './query'
|
|
5
5
|
import { Subscribable } from './subscribable'
|
|
6
|
-
import { pendingThenable } from './thenable'
|
|
7
6
|
import {
|
|
8
7
|
isValidTimeout,
|
|
9
8
|
noop,
|
|
@@ -17,7 +16,6 @@ import { timeoutManager } from './timeoutManager'
|
|
|
17
16
|
import type { ManagedTimerId } from './timeoutManager'
|
|
18
17
|
import type { FetchOptions, Query, QueryState } from './query'
|
|
19
18
|
import type { QueryClient } from './queryClient'
|
|
20
|
-
import type { PendingThenable, Thenable } from './thenable'
|
|
21
19
|
import type {
|
|
22
20
|
DefaultError,
|
|
23
21
|
DefaultedQueryObserverOptions,
|
|
@@ -56,7 +54,6 @@ export class QueryObserver<
|
|
|
56
54
|
TQueryData,
|
|
57
55
|
TQueryKey
|
|
58
56
|
>
|
|
59
|
-
#currentThenable: Thenable<TData>
|
|
60
57
|
#selectError: TError | null
|
|
61
58
|
#selectFn?: (data: TQueryData) => TData
|
|
62
59
|
#selectResult?: TData
|
|
@@ -82,7 +79,6 @@ export class QueryObserver<
|
|
|
82
79
|
|
|
83
80
|
this.#client = client
|
|
84
81
|
this.#selectError = null
|
|
85
|
-
this.#currentThenable = pendingThenable()
|
|
86
82
|
|
|
87
83
|
this.bindMethods()
|
|
88
84
|
this.setOptions(options)
|
|
@@ -268,19 +264,6 @@ export class QueryObserver<
|
|
|
268
264
|
get: (target, key) => {
|
|
269
265
|
this.trackProp(key as keyof QueryObserverResult)
|
|
270
266
|
onPropTracked?.(key as keyof QueryObserverResult)
|
|
271
|
-
if (key === 'promise') {
|
|
272
|
-
this.trackProp('data')
|
|
273
|
-
if (
|
|
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
|
-
}
|
|
284
267
|
return Reflect.get(target, key)
|
|
285
268
|
},
|
|
286
269
|
})
|
|
@@ -317,7 +300,42 @@ export class QueryObserver<
|
|
|
317
300
|
.getQueryCache()
|
|
318
301
|
.build(this.#client, defaultedOptions)
|
|
319
302
|
|
|
320
|
-
|
|
303
|
+
let unsubscribe = () => {}
|
|
304
|
+
let resolveEarly:
|
|
305
|
+
| ((result: QueryObserverResult<TData, TError>) => void)
|
|
306
|
+
| undefined
|
|
307
|
+
|
|
308
|
+
const cachePromise = new Promise<QueryObserverResult<TData, TError>>(
|
|
309
|
+
(resolve) => {
|
|
310
|
+
resolveEarly = resolve
|
|
311
|
+
unsubscribe = this.#client.getQueryCache().subscribe((event) => {
|
|
312
|
+
if (
|
|
313
|
+
event.type === 'updated' &&
|
|
314
|
+
event.query.queryHash === query.queryHash &&
|
|
315
|
+
query.state.data !== undefined
|
|
316
|
+
) {
|
|
317
|
+
unsubscribe()
|
|
318
|
+
resolve(this.createResult(query, defaultedOptions))
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
},
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
return Promise.race([
|
|
325
|
+
query
|
|
326
|
+
.fetch()
|
|
327
|
+
.then(() => {
|
|
328
|
+
const result = this.createResult(query, defaultedOptions)
|
|
329
|
+
// Settle the subscriber promise so both branches always settle.
|
|
330
|
+
// This value is ignored by Promise.race since the fetch branch already won.
|
|
331
|
+
resolveEarly?.(result)
|
|
332
|
+
return result
|
|
333
|
+
})
|
|
334
|
+
.finally(() => {
|
|
335
|
+
unsubscribe()
|
|
336
|
+
}),
|
|
337
|
+
cachePromise,
|
|
338
|
+
])
|
|
321
339
|
}
|
|
322
340
|
|
|
323
341
|
protected fetch(
|
|
@@ -545,6 +563,10 @@ export class QueryObserver<
|
|
|
545
563
|
this.#selectError = selectError as TError
|
|
546
564
|
}
|
|
547
565
|
}
|
|
566
|
+
} else if (data === undefined) {
|
|
567
|
+
// a stored select error belongs to previously selected data; once that
|
|
568
|
+
// data is gone (query switch or reset), it must not leak into this result
|
|
569
|
+
this.#selectError = null
|
|
548
570
|
}
|
|
549
571
|
|
|
550
572
|
if (this.#selectError) {
|
|
@@ -552,6 +574,7 @@ export class QueryObserver<
|
|
|
552
574
|
data = this.#selectResult
|
|
553
575
|
errorUpdatedAt = Date.now()
|
|
554
576
|
status = 'error'
|
|
577
|
+
isPlaceholderData = false
|
|
555
578
|
}
|
|
556
579
|
|
|
557
580
|
const isFetching = newState.fetchStatus === 'fetching'
|
|
@@ -588,57 +611,11 @@ export class QueryObserver<
|
|
|
588
611
|
isRefetchError: isError && hasData,
|
|
589
612
|
isStale: isStale(query, options),
|
|
590
613
|
refetch: this.refetch,
|
|
591
|
-
promise: this.#currentThenable,
|
|
592
614
|
isEnabled: resolveQueryBoolean(options.enabled, query) !== false,
|
|
593
615
|
}
|
|
594
616
|
|
|
595
617
|
const nextResult = result as QueryObserverResult<TData, TError>
|
|
596
618
|
|
|
597
|
-
if (this.options.experimental_prefetchInRender) {
|
|
598
|
-
const hasResultData = nextResult.data !== undefined
|
|
599
|
-
const isErrorWithoutData = nextResult.status === 'error' && !hasResultData
|
|
600
|
-
const finalizeThenableIfPossible = (thenable: PendingThenable<TData>) => {
|
|
601
|
-
if (isErrorWithoutData) {
|
|
602
|
-
thenable.reject(nextResult.error)
|
|
603
|
-
} else if (hasResultData) {
|
|
604
|
-
thenable.resolve(nextResult.data as TData)
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Create a new thenable and result promise when the results have changed
|
|
610
|
-
*/
|
|
611
|
-
const recreateThenable = () => {
|
|
612
|
-
const pending =
|
|
613
|
-
(this.#currentThenable =
|
|
614
|
-
nextResult.promise =
|
|
615
|
-
pendingThenable())
|
|
616
|
-
|
|
617
|
-
finalizeThenableIfPossible(pending)
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
const prevThenable = this.#currentThenable
|
|
621
|
-
switch (prevThenable.status) {
|
|
622
|
-
case 'pending':
|
|
623
|
-
// Finalize the previous thenable if it was pending
|
|
624
|
-
// and we are still observing the same query
|
|
625
|
-
if (query.queryHash === prevQuery.queryHash) {
|
|
626
|
-
finalizeThenableIfPossible(prevThenable)
|
|
627
|
-
}
|
|
628
|
-
break
|
|
629
|
-
case 'fulfilled':
|
|
630
|
-
if (isErrorWithoutData || nextResult.data !== prevThenable.value) {
|
|
631
|
-
recreateThenable()
|
|
632
|
-
}
|
|
633
|
-
break
|
|
634
|
-
case 'rejected':
|
|
635
|
-
if (!isErrorWithoutData || nextResult.error !== prevThenable.reason) {
|
|
636
|
-
recreateThenable()
|
|
637
|
-
}
|
|
638
|
-
break
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
619
|
return nextResult
|
|
643
620
|
}
|
|
644
621
|
|
package/src/retryer.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { focusManager } from './focusManager'
|
|
2
2
|
import { onlineManager } from './onlineManager'
|
|
3
|
-
import { pendingThenable } from './thenable'
|
|
4
3
|
import { environmentManager } from './environmentManager'
|
|
5
|
-
import { sleep } from './utils'
|
|
6
|
-
import type { Thenable } from './thenable'
|
|
4
|
+
import { noop, sleep } from './utils'
|
|
7
5
|
import type { CancelOptions, DefaultError, NetworkMode } from './types'
|
|
8
6
|
|
|
9
7
|
// TYPES
|
|
@@ -32,6 +30,8 @@ export interface Retryer<TData = unknown> {
|
|
|
32
30
|
status: () => 'pending' | 'resolved' | 'rejected'
|
|
33
31
|
}
|
|
34
32
|
|
|
33
|
+
type RetryerStatus = 'pending' | 'resolved' | 'rejected'
|
|
34
|
+
|
|
35
35
|
export type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>
|
|
36
36
|
|
|
37
37
|
type ShouldRetryFunction<TError = DefaultError> = (
|
|
@@ -79,11 +79,17 @@ export function createRetryer<TData = unknown, TError = DefaultError>(
|
|
|
79
79
|
let isRetryCancelled = false
|
|
80
80
|
let failureCount = 0
|
|
81
81
|
let continueFn: ((value?: unknown) => void) | undefined
|
|
82
|
+
let status: RetryerStatus = 'pending'
|
|
83
|
+
let promiseResolve: (data: TData) => void
|
|
84
|
+
let promiseReject: (error: TError) => void
|
|
82
85
|
|
|
83
|
-
const
|
|
86
|
+
const promise = new Promise<TData>((resolve, reject) => {
|
|
87
|
+
promiseResolve = resolve
|
|
88
|
+
promiseReject = reject
|
|
89
|
+
})
|
|
90
|
+
promise.catch(noop)
|
|
84
91
|
|
|
85
|
-
const isResolved = () =>
|
|
86
|
-
(thenable.status as Thenable<TData>['status']) !== 'pending'
|
|
92
|
+
const isResolved = () => status !== 'pending'
|
|
87
93
|
|
|
88
94
|
const cancel = (cancelOptions?: CancelOptions): void => {
|
|
89
95
|
if (!isResolved()) {
|
|
@@ -111,14 +117,16 @@ export function createRetryer<TData = unknown, TError = DefaultError>(
|
|
|
111
117
|
const resolve = (value: any) => {
|
|
112
118
|
if (!isResolved()) {
|
|
113
119
|
continueFn?.()
|
|
114
|
-
|
|
120
|
+
status = 'resolved'
|
|
121
|
+
promiseResolve(value)
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
const reject = (value: any) => {
|
|
119
126
|
if (!isResolved()) {
|
|
120
127
|
continueFn?.()
|
|
121
|
-
|
|
128
|
+
status = 'rejected'
|
|
129
|
+
promiseReject(value)
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
|
|
@@ -206,12 +214,12 @@ export function createRetryer<TData = unknown, TError = DefaultError>(
|
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
return {
|
|
209
|
-
promise
|
|
210
|
-
status: () =>
|
|
217
|
+
promise,
|
|
218
|
+
status: () => status,
|
|
211
219
|
cancel,
|
|
212
220
|
continue: () => {
|
|
213
221
|
continueFn?.()
|
|
214
|
-
return
|
|
222
|
+
return promise
|
|
215
223
|
},
|
|
216
224
|
cancelRetry,
|
|
217
225
|
continueRetry,
|
|
@@ -223,7 +231,7 @@ export function createRetryer<TData = unknown, TError = DefaultError>(
|
|
|
223
231
|
} else {
|
|
224
232
|
pause().then(run)
|
|
225
233
|
}
|
|
226
|
-
return
|
|
234
|
+
return promise
|
|
227
235
|
},
|
|
228
236
|
}
|
|
229
237
|
}
|
package/src/types.ts
CHANGED
|
@@ -79,6 +79,14 @@ export type DataTag<
|
|
|
79
79
|
[dataTagErrorSymbol]: TError
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
export type QueryKeyWithDataTag<
|
|
83
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
84
|
+
TQueryFnData = unknown,
|
|
85
|
+
TError = DefaultError,
|
|
86
|
+
> = {
|
|
87
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>
|
|
88
|
+
}
|
|
89
|
+
|
|
82
90
|
export type InferDataFromTag<TQueryFnData, TTaggedQueryKey extends QueryKey> =
|
|
83
91
|
TTaggedQueryKey extends DataTag<unknown, infer TaggedValue, unknown>
|
|
84
92
|
? TaggedValue
|
|
@@ -429,11 +437,6 @@ export interface QueryObserverOptions<
|
|
|
429
437
|
>
|
|
430
438
|
|
|
431
439
|
_optimisticResults?: 'optimistic' | 'isRestoring'
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Enable prefetching during rendering
|
|
435
|
-
*/
|
|
436
|
-
experimental_prefetchInRender?: boolean
|
|
437
440
|
}
|
|
438
441
|
|
|
439
442
|
export type WithRequired<TTarget, TKey extends keyof TTarget> = TTarget & {
|
|
@@ -486,6 +489,27 @@ export type DefaultedInfiniteQueryObserverOptions<
|
|
|
486
489
|
'throwOnError' | 'refetchOnReconnect' | 'queryHash'
|
|
487
490
|
>
|
|
488
491
|
|
|
492
|
+
export interface QueryExecuteOptions<
|
|
493
|
+
TQueryFnData = unknown,
|
|
494
|
+
TError = DefaultError,
|
|
495
|
+
TData = TQueryFnData,
|
|
496
|
+
TQueryData = TQueryFnData,
|
|
497
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
498
|
+
TPageParam = never,
|
|
499
|
+
> extends WithRequired<
|
|
500
|
+
QueryOptions<TQueryFnData, TError, TQueryData, TQueryKey, TPageParam>,
|
|
501
|
+
'queryKey'
|
|
502
|
+
> {
|
|
503
|
+
initialPageParam?: never
|
|
504
|
+
select?: (data: TQueryData) => TData
|
|
505
|
+
/**
|
|
506
|
+
* The time in milliseconds after data is considered stale.
|
|
507
|
+
* If the data is fresh it will be returned from the cache.
|
|
508
|
+
*/
|
|
509
|
+
staleTime?: StaleTimeFunction<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** @deprecated */
|
|
489
513
|
export interface FetchQueryOptions<
|
|
490
514
|
TQueryFnData = unknown,
|
|
491
515
|
TError = DefaultError,
|
|
@@ -504,6 +528,7 @@ export interface FetchQueryOptions<
|
|
|
504
528
|
staleTime?: StaleTimeFunction<TQueryFnData, TError, TData, TQueryKey>
|
|
505
529
|
}
|
|
506
530
|
|
|
531
|
+
/** @deprecated */
|
|
507
532
|
export interface EnsureQueryDataOptions<
|
|
508
533
|
TQueryFnData = unknown,
|
|
509
534
|
TError = DefaultError,
|
|
@@ -520,6 +545,7 @@ export interface EnsureQueryDataOptions<
|
|
|
520
545
|
revalidateIfStale?: boolean
|
|
521
546
|
}
|
|
522
547
|
|
|
548
|
+
/** @deprecated */
|
|
523
549
|
export type EnsureInfiniteQueryDataOptions<
|
|
524
550
|
TQueryFnData = unknown,
|
|
525
551
|
TError = DefaultError,
|
|
@@ -536,13 +562,34 @@ export type EnsureInfiniteQueryDataOptions<
|
|
|
536
562
|
revalidateIfStale?: boolean
|
|
537
563
|
}
|
|
538
564
|
|
|
539
|
-
type
|
|
565
|
+
type InfiniteQueryPages<TQueryFnData = unknown, TPageParam = unknown> =
|
|
540
566
|
| { pages?: never }
|
|
541
567
|
| {
|
|
542
568
|
pages: number
|
|
543
569
|
getNextPageParam: GetNextPageParamFunction<TPageParam, TQueryFnData>
|
|
544
570
|
}
|
|
545
571
|
|
|
572
|
+
export type InfiniteQueryExecuteOptions<
|
|
573
|
+
TQueryFnData = unknown,
|
|
574
|
+
TError = DefaultError,
|
|
575
|
+
TData = InfiniteData<TQueryFnData>,
|
|
576
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
577
|
+
TPageParam = unknown,
|
|
578
|
+
> = Omit<
|
|
579
|
+
QueryExecuteOptions<
|
|
580
|
+
TQueryFnData,
|
|
581
|
+
TError,
|
|
582
|
+
TData,
|
|
583
|
+
InfiniteData<TQueryFnData, TPageParam>,
|
|
584
|
+
TQueryKey,
|
|
585
|
+
TPageParam
|
|
586
|
+
>,
|
|
587
|
+
'initialPageParam'
|
|
588
|
+
> &
|
|
589
|
+
InitialPageParam<TPageParam> &
|
|
590
|
+
InfiniteQueryPages<TQueryFnData, TPageParam>
|
|
591
|
+
|
|
592
|
+
/** @deprecated */
|
|
546
593
|
export type FetchInfiniteQueryOptions<
|
|
547
594
|
TQueryFnData = unknown,
|
|
548
595
|
TError = DefaultError,
|
|
@@ -560,7 +607,7 @@ export type FetchInfiniteQueryOptions<
|
|
|
560
607
|
'initialPageParam'
|
|
561
608
|
> &
|
|
562
609
|
InitialPageParam<TPageParam> &
|
|
563
|
-
|
|
610
|
+
InfiniteQueryPages<TQueryFnData, TPageParam>
|
|
564
611
|
|
|
565
612
|
export interface ResultOptions {
|
|
566
613
|
throwOnError?: boolean
|
|
@@ -743,55 +790,6 @@ export interface QueryObserverBaseResult<
|
|
|
743
790
|
* - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
744
791
|
*/
|
|
745
792
|
fetchStatus: FetchStatus
|
|
746
|
-
/**
|
|
747
|
-
* A stable promise that will be resolved with the data of the query.
|
|
748
|
-
* Requires the `experimental_prefetchInRender` feature flag to be enabled.
|
|
749
|
-
* @example
|
|
750
|
-
*
|
|
751
|
-
* ### Enabling the feature flag
|
|
752
|
-
* ```ts
|
|
753
|
-
* const client = new QueryClient({
|
|
754
|
-
* defaultOptions: {
|
|
755
|
-
* queries: {
|
|
756
|
-
* experimental_prefetchInRender: true,
|
|
757
|
-
* },
|
|
758
|
-
* },
|
|
759
|
-
* })
|
|
760
|
-
* ```
|
|
761
|
-
*
|
|
762
|
-
* ### Usage
|
|
763
|
-
* ```tsx
|
|
764
|
-
* import { useQuery } from '@tanstack/react-query'
|
|
765
|
-
* import React from 'react'
|
|
766
|
-
* import { fetchTodos, type Todo } from './api'
|
|
767
|
-
*
|
|
768
|
-
* function TodoList({ query }: { query: UseQueryResult<Todo[], Error> }) {
|
|
769
|
-
* const data = React.use(query.promise)
|
|
770
|
-
*
|
|
771
|
-
* return (
|
|
772
|
-
* <ul>
|
|
773
|
-
* {data.map(todo => (
|
|
774
|
-
* <li key={todo.id}>{todo.title}</li>
|
|
775
|
-
* ))}
|
|
776
|
-
* </ul>
|
|
777
|
-
* )
|
|
778
|
-
* }
|
|
779
|
-
*
|
|
780
|
-
* export function App() {
|
|
781
|
-
* const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
|
|
782
|
-
*
|
|
783
|
-
* return (
|
|
784
|
-
* <>
|
|
785
|
-
* <h1>Todos</h1>
|
|
786
|
-
* <React.Suspense fallback={<div>Loading...</div>}>
|
|
787
|
-
* <TodoList query={query} />
|
|
788
|
-
* </React.Suspense>
|
|
789
|
-
* </>
|
|
790
|
-
* )
|
|
791
|
-
* }
|
|
792
|
-
* ```
|
|
793
|
-
*/
|
|
794
|
-
promise: Promise<TData>
|
|
795
793
|
}
|
|
796
794
|
|
|
797
795
|
export interface QueryObserverPendingResult<
|
|
@@ -1178,14 +1176,28 @@ export interface MutateOptions<
|
|
|
1178
1176
|
) => void
|
|
1179
1177
|
}
|
|
1180
1178
|
|
|
1179
|
+
export type MutateFunctionRest<
|
|
1180
|
+
TData = unknown,
|
|
1181
|
+
TError = DefaultError,
|
|
1182
|
+
TVariables = void,
|
|
1183
|
+
TOnMutateResult = unknown,
|
|
1184
|
+
> = undefined extends TVariables
|
|
1185
|
+
? [
|
|
1186
|
+
variables?: TVariables,
|
|
1187
|
+
options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,
|
|
1188
|
+
]
|
|
1189
|
+
: [
|
|
1190
|
+
variables: TVariables,
|
|
1191
|
+
options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,
|
|
1192
|
+
]
|
|
1193
|
+
|
|
1181
1194
|
export type MutateFunction<
|
|
1182
1195
|
TData = unknown,
|
|
1183
1196
|
TError = DefaultError,
|
|
1184
1197
|
TVariables = void,
|
|
1185
1198
|
TOnMutateResult = unknown,
|
|
1186
1199
|
> = (
|
|
1187
|
-
|
|
1188
|
-
options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,
|
|
1200
|
+
...rest: MutateFunctionRest<TData, TError, TVariables, TOnMutateResult>
|
|
1189
1201
|
) => Promise<TData>
|
|
1190
1202
|
|
|
1191
1203
|
export interface MutationObserverBaseResult<
|