@tanstack/query-core 4.29.19 → 4.29.23
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/lib/focusManager.esm.js +3 -2
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +3 -2
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.mjs +3 -2
- package/build/lib/focusManager.mjs.map +1 -1
- package/build/lib/onlineManager.esm.js +3 -2
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +3 -2
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.mjs +3 -2
- package/build/lib/onlineManager.mjs.map +1 -1
- package/build/lib/queryObserver.esm.js +56 -1
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +56 -1
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +56 -1
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/umd/index.development.js +62 -5
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/focusManager.ts +3 -3
- package/src/onlineManager.ts +3 -2
- package/src/queryObserver.ts +72 -1
- package/src/tests/focusManager.test.tsx +21 -14
- package/src/tests/onlineManager.test.tsx +21 -0
- package/build/lib/focusManager.d.ts.map +0 -1
- package/build/lib/hydration.d.ts.map +0 -1
- package/build/lib/index.d.ts.map +0 -1
- package/build/lib/infiniteQueryBehavior.d.ts.map +0 -1
- package/build/lib/infiniteQueryObserver.d.ts.map +0 -1
- package/build/lib/logger.d.ts.map +0 -1
- package/build/lib/logger.native.d.ts.map +0 -1
- package/build/lib/mutation.d.ts.map +0 -1
- package/build/lib/mutationCache.d.ts.map +0 -1
- package/build/lib/mutationObserver.d.ts.map +0 -1
- package/build/lib/notifyManager.d.ts.map +0 -1
- package/build/lib/onlineManager.d.ts.map +0 -1
- package/build/lib/queriesObserver.d.ts.map +0 -1
- package/build/lib/query.d.ts.map +0 -1
- package/build/lib/queryCache.d.ts.map +0 -1
- package/build/lib/queryClient.d.ts.map +0 -1
- package/build/lib/queryObserver.d.ts.map +0 -1
- package/build/lib/removable.d.ts.map +0 -1
- package/build/lib/retryer.d.ts.map +0 -1
- package/build/lib/subscribable.d.ts.map +0 -1
- package/build/lib/tests/focusManager.test.d.ts.map +0 -1
- package/build/lib/tests/hydration.test.d.ts.map +0 -1
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts.map +0 -1
- package/build/lib/tests/infiniteQueryObserver.test.d.ts.map +0 -1
- package/build/lib/tests/mutationCache.test.d.ts.map +0 -1
- package/build/lib/tests/mutationObserver.test.d.ts.map +0 -1
- package/build/lib/tests/mutations.test.d.ts.map +0 -1
- package/build/lib/tests/notifyManager.test.d.ts.map +0 -1
- package/build/lib/tests/onlineManager.test.d.ts.map +0 -1
- package/build/lib/tests/queriesObserver.test.d.ts.map +0 -1
- package/build/lib/tests/query.test.d.ts.map +0 -1
- package/build/lib/tests/queryCache.test.d.ts.map +0 -1
- package/build/lib/tests/queryClient.test.d.ts.map +0 -1
- package/build/lib/tests/queryObserver.test.d.ts.map +0 -1
- package/build/lib/tests/utils.d.ts.map +0 -1
- package/build/lib/tests/utils.test.d.ts.map +0 -1
- package/build/lib/types.d.ts.map +0 -1
- package/build/lib/utils.d.ts.map +0 -1
|
@@ -406,9 +406,10 @@
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
setFocused(focused) {
|
|
409
|
-
this.focused
|
|
409
|
+
const changed = this.focused !== focused;
|
|
410
410
|
|
|
411
|
-
if (
|
|
411
|
+
if (changed) {
|
|
412
|
+
this.focused = focused;
|
|
412
413
|
this.onFocus();
|
|
413
414
|
}
|
|
414
415
|
}
|
|
@@ -494,9 +495,10 @@
|
|
|
494
495
|
}
|
|
495
496
|
|
|
496
497
|
setOnline(online) {
|
|
497
|
-
this.online
|
|
498
|
+
const changed = this.online !== online;
|
|
498
499
|
|
|
499
|
-
if (
|
|
500
|
+
if (changed) {
|
|
501
|
+
this.online = online;
|
|
500
502
|
this.onOnline();
|
|
501
503
|
}
|
|
502
504
|
}
|
|
@@ -2324,7 +2326,30 @@
|
|
|
2324
2326
|
|
|
2325
2327
|
getOptimisticResult(options) {
|
|
2326
2328
|
const query = this.client.getQueryCache().build(this.client, options);
|
|
2327
|
-
|
|
2329
|
+
const result = this.createResult(query, options);
|
|
2330
|
+
|
|
2331
|
+
if (shouldAssignObserverCurrentProperties(this, result, options)) {
|
|
2332
|
+
// this assigns the optimistic result to the current Observer
|
|
2333
|
+
// because if the query function changes, useQuery will be performing
|
|
2334
|
+
// an effect where it would fetch again.
|
|
2335
|
+
// When the fetch finishes, we perform a deep data cloning in order
|
|
2336
|
+
// to reuse objects references. This deep data clone is performed against
|
|
2337
|
+
// the `observer.currentResult.data` property
|
|
2338
|
+
// When QueryKey changes, we refresh the query and get new `optimistic`
|
|
2339
|
+
// result, while we leave the `observer.currentResult`, so when new data
|
|
2340
|
+
// arrives, it finds the old `observer.currentResult` which is related
|
|
2341
|
+
// to the old QueryKey. Which means that currentResult and selectData are
|
|
2342
|
+
// out of sync already.
|
|
2343
|
+
// To solve this, we move the cursor of the currentResult everytime
|
|
2344
|
+
// an observer reads an optimistic value.
|
|
2345
|
+
// When keeping the previous data, the result doesn't change until new
|
|
2346
|
+
// data arrives.
|
|
2347
|
+
this.currentResult = result;
|
|
2348
|
+
this.currentResultOptions = this.options;
|
|
2349
|
+
this.currentResultState = this.currentQuery.state;
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
return result;
|
|
2328
2353
|
}
|
|
2329
2354
|
|
|
2330
2355
|
getCurrentResult() {
|
|
@@ -2740,6 +2765,38 @@
|
|
|
2740
2765
|
|
|
2741
2766
|
function isStale(query, options) {
|
|
2742
2767
|
return query.isStaleByTime(options.staleTime);
|
|
2768
|
+
} // this function would decide if we will update the observer's 'current'
|
|
2769
|
+
// properties after an optimistic reading via getOptimisticResult
|
|
2770
|
+
|
|
2771
|
+
|
|
2772
|
+
function shouldAssignObserverCurrentProperties(observer, optimisticResult, options) {
|
|
2773
|
+
// it is important to keep this condition like this for three reasons:
|
|
2774
|
+
// 1. It will get removed in the v5
|
|
2775
|
+
// 2. it reads: don't update the properties if we want to keep the previous
|
|
2776
|
+
// data.
|
|
2777
|
+
// 3. The opposite condition (!options.keepPreviousData) would fallthrough
|
|
2778
|
+
// and will result in a bad decision
|
|
2779
|
+
if (options.keepPreviousData) {
|
|
2780
|
+
return false;
|
|
2781
|
+
} // this means we want to put some placeholder data when pending and queryKey
|
|
2782
|
+
// changed.
|
|
2783
|
+
|
|
2784
|
+
|
|
2785
|
+
if (options.placeholderData !== undefined) {
|
|
2786
|
+
// re-assign properties only if current data is placeholder data
|
|
2787
|
+
// which means that data did not arrive yet, so, if there is some cached data
|
|
2788
|
+
// we need to "prepare" to receive it
|
|
2789
|
+
return optimisticResult.isPlaceholderData;
|
|
2790
|
+
} // if the newly created result isn't what the observer is holding as current,
|
|
2791
|
+
// then we'll need to update the properties as well
|
|
2792
|
+
|
|
2793
|
+
|
|
2794
|
+
if (observer.getCurrentResult() !== optimisticResult) {
|
|
2795
|
+
return true;
|
|
2796
|
+
} // basically, just keep previous properties if nothing changed
|
|
2797
|
+
|
|
2798
|
+
|
|
2799
|
+
return false;
|
|
2743
2800
|
}
|
|
2744
2801
|
|
|
2745
2802
|
class QueriesObserver extends Subscribable {
|