@tanstack/query-core 5.75.7 → 5.76.2
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-BaHDIfRR.d.ts → hydration-B3ndIyL6.d.ts} +1 -0
- package/build/legacy/{hydration-n7FlH3vr.d.cts → hydration-GTiXepW_.d.cts} +1 -0
- package/build/legacy/hydration.cjs +48 -33
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js +48 -33
- package/build/legacy/hydration.js.map +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.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/streamedQuery.d.cts +1 -1
- package/build/legacy/streamedQuery.d.ts +1 -1
- package/build/legacy/thenable.cjs +17 -2
- package/build/legacy/thenable.cjs.map +1 -1
- package/build/legacy/thenable.d.cts +12 -1
- package/build/legacy/thenable.d.ts +12 -1
- package/build/legacy/thenable.js +15 -1
- package/build/legacy/thenable.js.map +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-BaHDIfRR.d.ts → hydration-B3ndIyL6.d.ts} +1 -0
- package/build/modern/{hydration-n7FlH3vr.d.cts → hydration-GTiXepW_.d.cts} +1 -0
- package/build/modern/hydration.cjs +47 -32
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js +47 -32
- package/build/modern/hydration.js.map +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.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/streamedQuery.d.cts +1 -1
- package/build/modern/streamedQuery.d.ts +1 -1
- package/build/modern/thenable.cjs +16 -2
- package/build/modern/thenable.cjs.map +1 -1
- package/build/modern/thenable.d.cts +12 -1
- package/build/modern/thenable.d.ts +12 -1
- package/build/modern/thenable.js +14 -1
- package/build/modern/thenable.js.map +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 +1 -1
- package/src/hydration.ts +73 -46
- package/src/thenable.ts +29 -0
package/build/modern/query.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './removable.js';
|
|
2
|
-
export { bc as Action, b8 as FetchContext, b9 as FetchDirection, ba as FetchMeta, bb as FetchOptions, w as Query, b7 as QueryBehavior, v as QueryState, bd as SetStateOptions, be as fetchState } from './hydration-
|
|
2
|
+
export { bc as Action, b8 as FetchContext, b9 as FetchDirection, ba as FetchMeta, bb as FetchOptions, w as Query, b7 as QueryBehavior, v as QueryState, bd as SetStateOptions, be as fetchState } from './hydration-B3ndIyL6.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CancelledError, bA as RetryDelayValue, bz as RetryValue, by as Retryer, bB as canFetch, bC as createRetryer, o as isCancelledError } from './hydration-
|
|
1
|
+
export { C as CancelledError, bA as RetryDelayValue, bz as RetryValue, by as Retryer, bB as canFetch, bC as createRetryer, o as isCancelledError } from './hydration-GTiXepW_.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CancelledError, bA as RetryDelayValue, bz as RetryValue, by as Retryer, bB as canFetch, bC as createRetryer, o as isCancelledError } from './hydration-
|
|
1
|
+
export { C as CancelledError, bA as RetryDelayValue, bz as RetryValue, by as Retryer, bB as canFetch, bC as createRetryer, o as isCancelledError } from './hydration-B3ndIyL6.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as QueryKey, _ as QueryFunctionContext, W as QueryFunction } from './hydration-
|
|
1
|
+
import { F as QueryKey, _ as QueryFunctionContext, W as QueryFunction } from './hydration-GTiXepW_.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
|
4
4
|
|
|
@@ -20,9 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/thenable.ts
|
|
21
21
|
var thenable_exports = {};
|
|
22
22
|
__export(thenable_exports, {
|
|
23
|
-
pendingThenable: () => pendingThenable
|
|
23
|
+
pendingThenable: () => pendingThenable,
|
|
24
|
+
tryResolveSync: () => tryResolveSync
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(thenable_exports);
|
|
27
|
+
var import_utils = require("./utils.cjs");
|
|
26
28
|
function pendingThenable() {
|
|
27
29
|
let resolve;
|
|
28
30
|
let reject;
|
|
@@ -54,8 +56,20 @@ function pendingThenable() {
|
|
|
54
56
|
};
|
|
55
57
|
return thenable;
|
|
56
58
|
}
|
|
59
|
+
function tryResolveSync(promise) {
|
|
60
|
+
let data;
|
|
61
|
+
promise.then((result) => {
|
|
62
|
+
data = result;
|
|
63
|
+
return result;
|
|
64
|
+
})?.catch(import_utils.noop);
|
|
65
|
+
if (data !== void 0) {
|
|
66
|
+
return { data };
|
|
67
|
+
}
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
57
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
71
|
0 && (module.exports = {
|
|
59
|
-
pendingThenable
|
|
72
|
+
pendingThenable,
|
|
73
|
+
tryResolveSync
|
|
60
74
|
});
|
|
61
75
|
//# sourceMappingURL=thenable.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/thenable.ts"],"sourcesContent":["/**\n * Thenable types which matches React's types for promises\n *\n * React seemingly uses `.status`, `.value` and `.reason` properties on a promises to optimistically unwrap data from promises\n *\n * @see https://github.com/facebook/react/blob/main/packages/shared/ReactTypes.js#L112-L138\n * @see https://github.com/facebook/react/blob/4f604941569d2e8947ce1460a0b2997e835f37b9/packages/react-debug-tools/src/ReactDebugHooks.js#L224-L227\n */\n\ninterface Fulfilled<T> {\n status: 'fulfilled'\n value: T\n}\ninterface Rejected {\n status: 'rejected'\n reason: unknown\n}\ninterface Pending<T> {\n status: 'pending'\n\n /**\n * Resolve the promise with a value.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n resolve: (value: T) => void\n /**\n * Reject the promise with a reason.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n reject: (reason: unknown) => void\n}\n\nexport type FulfilledThenable<T> = Promise<T> & Fulfilled<T>\nexport type RejectedThenable<T> = Promise<T> & Rejected\nexport type PendingThenable<T> = Promise<T> & Pending<T>\n\nexport type Thenable<T> =\n | FulfilledThenable<T>\n | RejectedThenable<T>\n | PendingThenable<T>\n\nexport function pendingThenable<T>(): PendingThenable<T> {\n let resolve: Pending<T>['resolve']\n let reject: Pending<T>['reject']\n // this could use `Promise.withResolvers()` in the future\n const thenable = new Promise((_resolve, _reject) => {\n resolve = _resolve\n reject = _reject\n }) as PendingThenable<T>\n\n thenable.status = 'pending'\n thenable.catch(() => {\n // prevent unhandled rejection errors\n })\n\n function finalize(data: Fulfilled<T> | Rejected) {\n Object.assign(thenable, data)\n\n // clear pending props props to avoid calling them twice\n delete (thenable as Partial<PendingThenable<T>>).resolve\n delete (thenable as Partial<PendingThenable<T>>).reject\n }\n\n thenable.resolve = (value) => {\n finalize({\n status: 'fulfilled',\n value,\n })\n\n resolve(value)\n }\n thenable.reject = (reason) => {\n finalize({\n status: 'rejected',\n reason,\n })\n\n reject(reason)\n }\n\n return thenable\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../src/thenable.ts"],"sourcesContent":["/**\n * Thenable types which matches React's types for promises\n *\n * React seemingly uses `.status`, `.value` and `.reason` properties on a promises to optimistically unwrap data from promises\n *\n * @see https://github.com/facebook/react/blob/main/packages/shared/ReactTypes.js#L112-L138\n * @see https://github.com/facebook/react/blob/4f604941569d2e8947ce1460a0b2997e835f37b9/packages/react-debug-tools/src/ReactDebugHooks.js#L224-L227\n */\n\nimport { noop } from './utils'\n\ninterface Fulfilled<T> {\n status: 'fulfilled'\n value: T\n}\ninterface Rejected {\n status: 'rejected'\n reason: unknown\n}\ninterface Pending<T> {\n status: 'pending'\n\n /**\n * Resolve the promise with a value.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n resolve: (value: T) => void\n /**\n * Reject the promise with a reason.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n reject: (reason: unknown) => void\n}\n\nexport type FulfilledThenable<T> = Promise<T> & Fulfilled<T>\nexport type RejectedThenable<T> = Promise<T> & Rejected\nexport type PendingThenable<T> = Promise<T> & Pending<T>\n\nexport type Thenable<T> =\n | FulfilledThenable<T>\n | RejectedThenable<T>\n | PendingThenable<T>\n\nexport function pendingThenable<T>(): PendingThenable<T> {\n let resolve: Pending<T>['resolve']\n let reject: Pending<T>['reject']\n // this could use `Promise.withResolvers()` in the future\n const thenable = new Promise((_resolve, _reject) => {\n resolve = _resolve\n reject = _reject\n }) as PendingThenable<T>\n\n thenable.status = 'pending'\n thenable.catch(() => {\n // prevent unhandled rejection errors\n })\n\n function finalize(data: Fulfilled<T> | Rejected) {\n Object.assign(thenable, data)\n\n // clear pending props props to avoid calling them twice\n delete (thenable as Partial<PendingThenable<T>>).resolve\n delete (thenable as Partial<PendingThenable<T>>).reject\n }\n\n thenable.resolve = (value) => {\n finalize({\n status: 'fulfilled',\n value,\n })\n\n resolve(value)\n }\n thenable.reject = (reason) => {\n finalize({\n status: 'rejected',\n reason,\n })\n\n reject(reason)\n }\n\n return thenable\n}\n\n/**\n * This function takes a Promise-like input and detects whether the data\n * is synchronously available or not.\n *\n * It does not inspect .status, .value or .reason properties of the promise,\n * as those are not always available, and the .status of React's promises\n * should not be considered part of the public API.\n */\nexport function tryResolveSync(promise: Promise<unknown> | Thenable<unknown>) {\n let data: unknown\n\n promise\n .then((result) => {\n data = result\n return result\n })\n // .catch can be unavailable on certain kinds of thenable's\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n ?.catch(noop)\n\n if (data !== undefined) {\n return { data }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,mBAAqB;AAkCd,SAAS,kBAAyC;AACvD,MAAI;AACJ,MAAI;AAEJ,QAAM,WAAW,IAAI,QAAQ,CAAC,UAAU,YAAY;AAClD,cAAU;AACV,aAAS;AAAA,EACX,CAAC;AAED,WAAS,SAAS;AAClB,WAAS,MAAM,MAAM;AAAA,EAErB,CAAC;AAED,WAAS,SAAS,MAA+B;AAC/C,WAAO,OAAO,UAAU,IAAI;AAG5B,WAAQ,SAAyC;AACjD,WAAQ,SAAyC;AAAA,EACnD;AAEA,WAAS,UAAU,CAAC,UAAU;AAC5B,aAAS;AAAA,MACP,QAAQ;AAAA,MACR;AAAA,IACF,CAAC;AAED,YAAQ,KAAK;AAAA,EACf;AACA,WAAS,SAAS,CAAC,WAAW;AAC5B,aAAS;AAAA,MACP,QAAQ;AAAA,MACR;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AAAA,EACf;AAEA,SAAO;AACT;AAUO,SAAS,eAAe,SAA+C;AAC5E,MAAI;AAEJ,UACG,KAAK,CAAC,WAAW;AAChB,WAAO;AACP,WAAO;AAAA,EACT,CAAC,GAGC,MAAM,iBAAI;AAEd,MAAI,SAAS,QAAW;AACtB,WAAO,EAAE,KAAK;AAAA,EAChB;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -32,5 +32,16 @@ type RejectedThenable<T> = Promise<T> & Rejected;
|
|
|
32
32
|
type PendingThenable<T> = Promise<T> & Pending<T>;
|
|
33
33
|
type Thenable<T> = FulfilledThenable<T> | RejectedThenable<T> | PendingThenable<T>;
|
|
34
34
|
declare function pendingThenable<T>(): PendingThenable<T>;
|
|
35
|
+
/**
|
|
36
|
+
* This function takes a Promise-like input and detects whether the data
|
|
37
|
+
* is synchronously available or not.
|
|
38
|
+
*
|
|
39
|
+
* It does not inspect .status, .value or .reason properties of the promise,
|
|
40
|
+
* as those are not always available, and the .status of React's promises
|
|
41
|
+
* should not be considered part of the public API.
|
|
42
|
+
*/
|
|
43
|
+
declare function tryResolveSync(promise: Promise<unknown> | Thenable<unknown>): {
|
|
44
|
+
data: {} | null;
|
|
45
|
+
} | undefined;
|
|
35
46
|
|
|
36
|
-
export { type FulfilledThenable, type PendingThenable, type RejectedThenable, type Thenable, pendingThenable };
|
|
47
|
+
export { type FulfilledThenable, type PendingThenable, type RejectedThenable, type Thenable, pendingThenable, tryResolveSync };
|
|
@@ -32,5 +32,16 @@ type RejectedThenable<T> = Promise<T> & Rejected;
|
|
|
32
32
|
type PendingThenable<T> = Promise<T> & Pending<T>;
|
|
33
33
|
type Thenable<T> = FulfilledThenable<T> | RejectedThenable<T> | PendingThenable<T>;
|
|
34
34
|
declare function pendingThenable<T>(): PendingThenable<T>;
|
|
35
|
+
/**
|
|
36
|
+
* This function takes a Promise-like input and detects whether the data
|
|
37
|
+
* is synchronously available or not.
|
|
38
|
+
*
|
|
39
|
+
* It does not inspect .status, .value or .reason properties of the promise,
|
|
40
|
+
* as those are not always available, and the .status of React's promises
|
|
41
|
+
* should not be considered part of the public API.
|
|
42
|
+
*/
|
|
43
|
+
declare function tryResolveSync(promise: Promise<unknown> | Thenable<unknown>): {
|
|
44
|
+
data: {} | null;
|
|
45
|
+
} | undefined;
|
|
35
46
|
|
|
36
|
-
export { type FulfilledThenable, type PendingThenable, type RejectedThenable, type Thenable, pendingThenable };
|
|
47
|
+
export { type FulfilledThenable, type PendingThenable, type RejectedThenable, type Thenable, pendingThenable, tryResolveSync };
|
package/build/modern/thenable.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/thenable.ts
|
|
2
|
+
import { noop } from "./utils.js";
|
|
2
3
|
function pendingThenable() {
|
|
3
4
|
let resolve;
|
|
4
5
|
let reject;
|
|
@@ -30,7 +31,19 @@ function pendingThenable() {
|
|
|
30
31
|
};
|
|
31
32
|
return thenable;
|
|
32
33
|
}
|
|
34
|
+
function tryResolveSync(promise) {
|
|
35
|
+
let data;
|
|
36
|
+
promise.then((result) => {
|
|
37
|
+
data = result;
|
|
38
|
+
return result;
|
|
39
|
+
})?.catch(noop);
|
|
40
|
+
if (data !== void 0) {
|
|
41
|
+
return { data };
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
33
45
|
export {
|
|
34
|
-
pendingThenable
|
|
46
|
+
pendingThenable,
|
|
47
|
+
tryResolveSync
|
|
35
48
|
};
|
|
36
49
|
//# sourceMappingURL=thenable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/thenable.ts"],"sourcesContent":["/**\n * Thenable types which matches React's types for promises\n *\n * React seemingly uses `.status`, `.value` and `.reason` properties on a promises to optimistically unwrap data from promises\n *\n * @see https://github.com/facebook/react/blob/main/packages/shared/ReactTypes.js#L112-L138\n * @see https://github.com/facebook/react/blob/4f604941569d2e8947ce1460a0b2997e835f37b9/packages/react-debug-tools/src/ReactDebugHooks.js#L224-L227\n */\n\ninterface Fulfilled<T> {\n status: 'fulfilled'\n value: T\n}\ninterface Rejected {\n status: 'rejected'\n reason: unknown\n}\ninterface Pending<T> {\n status: 'pending'\n\n /**\n * Resolve the promise with a value.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n resolve: (value: T) => void\n /**\n * Reject the promise with a reason.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n reject: (reason: unknown) => void\n}\n\nexport type FulfilledThenable<T> = Promise<T> & Fulfilled<T>\nexport type RejectedThenable<T> = Promise<T> & Rejected\nexport type PendingThenable<T> = Promise<T> & Pending<T>\n\nexport type Thenable<T> =\n | FulfilledThenable<T>\n | RejectedThenable<T>\n | PendingThenable<T>\n\nexport function pendingThenable<T>(): PendingThenable<T> {\n let resolve: Pending<T>['resolve']\n let reject: Pending<T>['reject']\n // this could use `Promise.withResolvers()` in the future\n const thenable = new Promise((_resolve, _reject) => {\n resolve = _resolve\n reject = _reject\n }) as PendingThenable<T>\n\n thenable.status = 'pending'\n thenable.catch(() => {\n // prevent unhandled rejection errors\n })\n\n function finalize(data: Fulfilled<T> | Rejected) {\n Object.assign(thenable, data)\n\n // clear pending props props to avoid calling them twice\n delete (thenable as Partial<PendingThenable<T>>).resolve\n delete (thenable as Partial<PendingThenable<T>>).reject\n }\n\n thenable.resolve = (value) => {\n finalize({\n status: 'fulfilled',\n value,\n })\n\n resolve(value)\n }\n thenable.reject = (reason) => {\n finalize({\n status: 'rejected',\n reason,\n })\n\n reject(reason)\n }\n\n return thenable\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/thenable.ts"],"sourcesContent":["/**\n * Thenable types which matches React's types for promises\n *\n * React seemingly uses `.status`, `.value` and `.reason` properties on a promises to optimistically unwrap data from promises\n *\n * @see https://github.com/facebook/react/blob/main/packages/shared/ReactTypes.js#L112-L138\n * @see https://github.com/facebook/react/blob/4f604941569d2e8947ce1460a0b2997e835f37b9/packages/react-debug-tools/src/ReactDebugHooks.js#L224-L227\n */\n\nimport { noop } from './utils'\n\ninterface Fulfilled<T> {\n status: 'fulfilled'\n value: T\n}\ninterface Rejected {\n status: 'rejected'\n reason: unknown\n}\ninterface Pending<T> {\n status: 'pending'\n\n /**\n * Resolve the promise with a value.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n resolve: (value: T) => void\n /**\n * Reject the promise with a reason.\n * Will remove the `resolve` and `reject` properties from the promise.\n */\n reject: (reason: unknown) => void\n}\n\nexport type FulfilledThenable<T> = Promise<T> & Fulfilled<T>\nexport type RejectedThenable<T> = Promise<T> & Rejected\nexport type PendingThenable<T> = Promise<T> & Pending<T>\n\nexport type Thenable<T> =\n | FulfilledThenable<T>\n | RejectedThenable<T>\n | PendingThenable<T>\n\nexport function pendingThenable<T>(): PendingThenable<T> {\n let resolve: Pending<T>['resolve']\n let reject: Pending<T>['reject']\n // this could use `Promise.withResolvers()` in the future\n const thenable = new Promise((_resolve, _reject) => {\n resolve = _resolve\n reject = _reject\n }) as PendingThenable<T>\n\n thenable.status = 'pending'\n thenable.catch(() => {\n // prevent unhandled rejection errors\n })\n\n function finalize(data: Fulfilled<T> | Rejected) {\n Object.assign(thenable, data)\n\n // clear pending props props to avoid calling them twice\n delete (thenable as Partial<PendingThenable<T>>).resolve\n delete (thenable as Partial<PendingThenable<T>>).reject\n }\n\n thenable.resolve = (value) => {\n finalize({\n status: 'fulfilled',\n value,\n })\n\n resolve(value)\n }\n thenable.reject = (reason) => {\n finalize({\n status: 'rejected',\n reason,\n })\n\n reject(reason)\n }\n\n return thenable\n}\n\n/**\n * This function takes a Promise-like input and detects whether the data\n * is synchronously available or not.\n *\n * It does not inspect .status, .value or .reason properties of the promise,\n * as those are not always available, and the .status of React's promises\n * should not be considered part of the public API.\n */\nexport function tryResolveSync(promise: Promise<unknown> | Thenable<unknown>) {\n let data: unknown\n\n promise\n .then((result) => {\n data = result\n return result\n })\n // .catch can be unavailable on certain kinds of thenable's\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n ?.catch(noop)\n\n if (data !== undefined) {\n return { data }\n }\n\n return undefined\n}\n"],"mappings":";AASA,SAAS,YAAY;AAkCd,SAAS,kBAAyC;AACvD,MAAI;AACJ,MAAI;AAEJ,QAAM,WAAW,IAAI,QAAQ,CAAC,UAAU,YAAY;AAClD,cAAU;AACV,aAAS;AAAA,EACX,CAAC;AAED,WAAS,SAAS;AAClB,WAAS,MAAM,MAAM;AAAA,EAErB,CAAC;AAED,WAAS,SAAS,MAA+B;AAC/C,WAAO,OAAO,UAAU,IAAI;AAG5B,WAAQ,SAAyC;AACjD,WAAQ,SAAyC;AAAA,EACnD;AAEA,WAAS,UAAU,CAAC,UAAU;AAC5B,aAAS;AAAA,MACP,QAAQ;AAAA,MACR;AAAA,IACF,CAAC;AAED,YAAQ,KAAK;AAAA,EACf;AACA,WAAS,SAAS,CAAC,WAAW;AAC5B,aAAS;AAAA,MACP,QAAQ;AAAA,MACR;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AAAA,EACf;AAEA,SAAO;AACT;AAUO,SAAS,eAAe,SAA+C;AAC5E,MAAI;AAEJ,UACG,KAAK,CAAC,WAAW;AAChB,WAAO;AACP,WAAO;AAAA,EACT,CAAC,GAGC,MAAM,IAAI;AAEd,MAAI,SAAS,QAAW;AACtB,WAAO,EAAE,KAAK;AAAA,EAChB;AAEA,SAAO;AACT;","names":[]}
|
package/build/modern/types.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { L as AnyDataTag, b3 as CancelOptions, P as DataTag, E as DefaultError, b2 as DefaultOptions, ah as DefaultedInfiniteQueryObserverOptions, af as DefaultedQueryObserverOptions, aM as DefinedInfiniteQueryObserverResult, aD as DefinedQueryObserverResult, A as DistributiveOmit, Y as Enabled, ak as EnsureInfiniteQueryDataOptions, aj as EnsureQueryDataOptions, al as FetchInfiniteQueryOptions, as as FetchNextPageOptions, at as FetchPreviousPageOptions, ai as FetchQueryOptions, av as FetchStatus, a4 as GetNextPageParamFunction, a3 as GetPreviousPageParamFunction, T as InferDataFromTag, V as InferErrorFromTag, a5 as InfiniteData, aF as InfiniteQueryObserverBaseResult, aI as InfiniteQueryObserverLoadingErrorResult, aH as InfiniteQueryObserverLoadingResult, ag as InfiniteQueryObserverOptions, aG as InfiniteQueryObserverPendingResult, aL as InfiniteQueryObserverPlaceholderResult, aJ as InfiniteQueryObserverRefetchErrorResult, aN as InfiniteQueryObserverResult, aK as InfiniteQueryObserverSuccessResult, ab as InfiniteQueryPageParamsOptions, $ as InitialDataFunction, aa as InitialPageParam, aq as InvalidateOptions, ao as InvalidateQueryFilters, aW as MutateFunction, aV as MutateOptions, aS as MutationFunction, aO as MutationKey, aR as MutationMeta, aX as MutationObserverBaseResult, a_ as MutationObserverErrorResult, aY as MutationObserverIdleResult, aZ as MutationObserverLoadingResult, aU as MutationObserverOptions, b0 as MutationObserverResult, a$ as MutationObserverSuccessResult, aT as MutationOptions, aQ as MutationScope, aP as MutationStatus, a7 as NetworkMode, N as NoInfer, b6 as NotifyEvent, b5 as NotifyEventType, a8 as NotifyOnChangeProps, O as OmitKeyof, B as Override, a0 as PlaceholderDataFunction, a1 as QueriesPlaceholderDataFunction, b1 as QueryClientConfig, W as QueryFunction, _ as QueryFunctionContext, F as QueryKey, a2 as QueryKeyHashFunction, a6 as QueryMeta, aw as QueryObserverBaseResult, az as QueryObserverLoadingErrorResult, ay as QueryObserverLoadingResult, ad as QueryObserverOptions, ax as QueryObserverPendingResult, aC as QueryObserverPlaceholderResult, aA as QueryObserverRefetchErrorResult, aE as QueryObserverResult, aB as QueryObserverSuccessResult, a9 as QueryOptions, Z as QueryPersister, au as QueryStatus, an as RefetchOptions, ap as RefetchQueryFilters, R as Register, ar as ResetOptions, am as ResultOptions, b4 as SetDataOptions, X as StaleTime, ac as ThrowOnError, K as UnsetMarker, ae as WithRequired, I as dataTagErrorSymbol, G as dataTagSymbol, J as unsetMarker } from './hydration-
|
|
1
|
+
export { L as AnyDataTag, b3 as CancelOptions, P as DataTag, E as DefaultError, b2 as DefaultOptions, ah as DefaultedInfiniteQueryObserverOptions, af as DefaultedQueryObserverOptions, aM as DefinedInfiniteQueryObserverResult, aD as DefinedQueryObserverResult, A as DistributiveOmit, Y as Enabled, ak as EnsureInfiniteQueryDataOptions, aj as EnsureQueryDataOptions, al as FetchInfiniteQueryOptions, as as FetchNextPageOptions, at as FetchPreviousPageOptions, ai as FetchQueryOptions, av as FetchStatus, a4 as GetNextPageParamFunction, a3 as GetPreviousPageParamFunction, T as InferDataFromTag, V as InferErrorFromTag, a5 as InfiniteData, aF as InfiniteQueryObserverBaseResult, aI as InfiniteQueryObserverLoadingErrorResult, aH as InfiniteQueryObserverLoadingResult, ag as InfiniteQueryObserverOptions, aG as InfiniteQueryObserverPendingResult, aL as InfiniteQueryObserverPlaceholderResult, aJ as InfiniteQueryObserverRefetchErrorResult, aN as InfiniteQueryObserverResult, aK as InfiniteQueryObserverSuccessResult, ab as InfiniteQueryPageParamsOptions, $ as InitialDataFunction, aa as InitialPageParam, aq as InvalidateOptions, ao as InvalidateQueryFilters, aW as MutateFunction, aV as MutateOptions, aS as MutationFunction, aO as MutationKey, aR as MutationMeta, aX as MutationObserverBaseResult, a_ as MutationObserverErrorResult, aY as MutationObserverIdleResult, aZ as MutationObserverLoadingResult, aU as MutationObserverOptions, b0 as MutationObserverResult, a$ as MutationObserverSuccessResult, aT as MutationOptions, aQ as MutationScope, aP as MutationStatus, a7 as NetworkMode, N as NoInfer, b6 as NotifyEvent, b5 as NotifyEventType, a8 as NotifyOnChangeProps, O as OmitKeyof, B as Override, a0 as PlaceholderDataFunction, a1 as QueriesPlaceholderDataFunction, b1 as QueryClientConfig, W as QueryFunction, _ as QueryFunctionContext, F as QueryKey, a2 as QueryKeyHashFunction, a6 as QueryMeta, aw as QueryObserverBaseResult, az as QueryObserverLoadingErrorResult, ay as QueryObserverLoadingResult, ad as QueryObserverOptions, ax as QueryObserverPendingResult, aC as QueryObserverPlaceholderResult, aA as QueryObserverRefetchErrorResult, aE as QueryObserverResult, aB as QueryObserverSuccessResult, a9 as QueryOptions, Z as QueryPersister, au as QueryStatus, an as RefetchOptions, ap as RefetchQueryFilters, R as Register, ar as ResetOptions, am as ResultOptions, b4 as SetDataOptions, X as StaleTime, ac as ThrowOnError, K as UnsetMarker, ae as WithRequired, I as dataTagErrorSymbol, G as dataTagSymbol, J as unsetMarker } from './hydration-GTiXepW_.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
package/build/modern/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { L as AnyDataTag, b3 as CancelOptions, P as DataTag, E as DefaultError, b2 as DefaultOptions, ah as DefaultedInfiniteQueryObserverOptions, af as DefaultedQueryObserverOptions, aM as DefinedInfiniteQueryObserverResult, aD as DefinedQueryObserverResult, A as DistributiveOmit, Y as Enabled, ak as EnsureInfiniteQueryDataOptions, aj as EnsureQueryDataOptions, al as FetchInfiniteQueryOptions, as as FetchNextPageOptions, at as FetchPreviousPageOptions, ai as FetchQueryOptions, av as FetchStatus, a4 as GetNextPageParamFunction, a3 as GetPreviousPageParamFunction, T as InferDataFromTag, V as InferErrorFromTag, a5 as InfiniteData, aF as InfiniteQueryObserverBaseResult, aI as InfiniteQueryObserverLoadingErrorResult, aH as InfiniteQueryObserverLoadingResult, ag as InfiniteQueryObserverOptions, aG as InfiniteQueryObserverPendingResult, aL as InfiniteQueryObserverPlaceholderResult, aJ as InfiniteQueryObserverRefetchErrorResult, aN as InfiniteQueryObserverResult, aK as InfiniteQueryObserverSuccessResult, ab as InfiniteQueryPageParamsOptions, $ as InitialDataFunction, aa as InitialPageParam, aq as InvalidateOptions, ao as InvalidateQueryFilters, aW as MutateFunction, aV as MutateOptions, aS as MutationFunction, aO as MutationKey, aR as MutationMeta, aX as MutationObserverBaseResult, a_ as MutationObserverErrorResult, aY as MutationObserverIdleResult, aZ as MutationObserverLoadingResult, aU as MutationObserverOptions, b0 as MutationObserverResult, a$ as MutationObserverSuccessResult, aT as MutationOptions, aQ as MutationScope, aP as MutationStatus, a7 as NetworkMode, N as NoInfer, b6 as NotifyEvent, b5 as NotifyEventType, a8 as NotifyOnChangeProps, O as OmitKeyof, B as Override, a0 as PlaceholderDataFunction, a1 as QueriesPlaceholderDataFunction, b1 as QueryClientConfig, W as QueryFunction, _ as QueryFunctionContext, F as QueryKey, a2 as QueryKeyHashFunction, a6 as QueryMeta, aw as QueryObserverBaseResult, az as QueryObserverLoadingErrorResult, ay as QueryObserverLoadingResult, ad as QueryObserverOptions, ax as QueryObserverPendingResult, aC as QueryObserverPlaceholderResult, aA as QueryObserverRefetchErrorResult, aE as QueryObserverResult, aB as QueryObserverSuccessResult, a9 as QueryOptions, Z as QueryPersister, au as QueryStatus, an as RefetchOptions, ap as RefetchQueryFilters, R as Register, ar as ResetOptions, am as ResultOptions, b4 as SetDataOptions, X as StaleTime, ac as ThrowOnError, K as UnsetMarker, ae as WithRequired, I as dataTagErrorSymbol, G as dataTagSymbol, J as unsetMarker } from './hydration-
|
|
1
|
+
export { L as AnyDataTag, b3 as CancelOptions, P as DataTag, E as DefaultError, b2 as DefaultOptions, ah as DefaultedInfiniteQueryObserverOptions, af as DefaultedQueryObserverOptions, aM as DefinedInfiniteQueryObserverResult, aD as DefinedQueryObserverResult, A as DistributiveOmit, Y as Enabled, ak as EnsureInfiniteQueryDataOptions, aj as EnsureQueryDataOptions, al as FetchInfiniteQueryOptions, as as FetchNextPageOptions, at as FetchPreviousPageOptions, ai as FetchQueryOptions, av as FetchStatus, a4 as GetNextPageParamFunction, a3 as GetPreviousPageParamFunction, T as InferDataFromTag, V as InferErrorFromTag, a5 as InfiniteData, aF as InfiniteQueryObserverBaseResult, aI as InfiniteQueryObserverLoadingErrorResult, aH as InfiniteQueryObserverLoadingResult, ag as InfiniteQueryObserverOptions, aG as InfiniteQueryObserverPendingResult, aL as InfiniteQueryObserverPlaceholderResult, aJ as InfiniteQueryObserverRefetchErrorResult, aN as InfiniteQueryObserverResult, aK as InfiniteQueryObserverSuccessResult, ab as InfiniteQueryPageParamsOptions, $ as InitialDataFunction, aa as InitialPageParam, aq as InvalidateOptions, ao as InvalidateQueryFilters, aW as MutateFunction, aV as MutateOptions, aS as MutationFunction, aO as MutationKey, aR as MutationMeta, aX as MutationObserverBaseResult, a_ as MutationObserverErrorResult, aY as MutationObserverIdleResult, aZ as MutationObserverLoadingResult, aU as MutationObserverOptions, b0 as MutationObserverResult, a$ as MutationObserverSuccessResult, aT as MutationOptions, aQ as MutationScope, aP as MutationStatus, a7 as NetworkMode, N as NoInfer, b6 as NotifyEvent, b5 as NotifyEventType, a8 as NotifyOnChangeProps, O as OmitKeyof, B as Override, a0 as PlaceholderDataFunction, a1 as QueriesPlaceholderDataFunction, b1 as QueryClientConfig, W as QueryFunction, _ as QueryFunctionContext, F as QueryKey, a2 as QueryKeyHashFunction, a6 as QueryMeta, aw as QueryObserverBaseResult, az as QueryObserverLoadingErrorResult, ay as QueryObserverLoadingResult, ad as QueryObserverOptions, ax as QueryObserverPendingResult, aC as QueryObserverPlaceholderResult, aA as QueryObserverRefetchErrorResult, aE as QueryObserverResult, aB as QueryObserverSuccessResult, a9 as QueryOptions, Z as QueryPersister, au as QueryStatus, an as RefetchOptions, ap as RefetchQueryFilters, R as Register, ar as ResetOptions, am as ResultOptions, b4 as SetDataOptions, X as StaleTime, ac as ThrowOnError, K as UnsetMarker, ae as WithRequired, I as dataTagErrorSymbol, G as dataTagSymbol, J as unsetMarker } from './hydration-B3ndIyL6.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
package/build/modern/utils.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { j as MutationFilters, l as QueryFilters, bh as QueryTypeFilter, S as SkipToken, U as Updater, bu as addToEnd, bv as addToStart, bw as ensureQueryFn, bi as functionalUpdate, h as hashKey, bn as hashQueryKeyByOptions, bq as isPlainArray, br as isPlainObject, i as isServer, bj as isValidTimeout, k as keepPreviousData, f as matchMutation, m as matchQuery, n as noop, bo as partialMatchKey, bt as replaceData, r as replaceEqualDeep, bm as resolveEnabled, bl as resolveStaleTime, bp as shallowEqualObjects, g as shouldThrowError, s as skipToken, bs as sleep, bk as timeUntilStale } from './hydration-
|
|
1
|
+
export { j as MutationFilters, l as QueryFilters, bh as QueryTypeFilter, S as SkipToken, U as Updater, bu as addToEnd, bv as addToStart, bw as ensureQueryFn, bi as functionalUpdate, h as hashKey, bn as hashQueryKeyByOptions, bq as isPlainArray, br as isPlainObject, i as isServer, bj as isValidTimeout, k as keepPreviousData, f as matchMutation, m as matchQuery, n as noop, bo as partialMatchKey, bt as replaceData, r as replaceEqualDeep, bm as resolveEnabled, bl as resolveStaleTime, bp as shallowEqualObjects, g as shouldThrowError, s as skipToken, bs as sleep, bk as timeUntilStale } from './hydration-GTiXepW_.cjs';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
package/build/modern/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { j as MutationFilters, l as QueryFilters, bh as QueryTypeFilter, S as SkipToken, U as Updater, bu as addToEnd, bv as addToStart, bw as ensureQueryFn, bi as functionalUpdate, h as hashKey, bn as hashQueryKeyByOptions, bq as isPlainArray, br as isPlainObject, i as isServer, bj as isValidTimeout, k as keepPreviousData, f as matchMutation, m as matchQuery, n as noop, bo as partialMatchKey, bt as replaceData, r as replaceEqualDeep, bm as resolveEnabled, bl as resolveStaleTime, bp as shallowEqualObjects, g as shouldThrowError, s as skipToken, bs as sleep, bk as timeUntilStale } from './hydration-
|
|
1
|
+
export { j as MutationFilters, l as QueryFilters, bh as QueryTypeFilter, S as SkipToken, U as Updater, bu as addToEnd, bv as addToStart, bw as ensureQueryFn, bi as functionalUpdate, h as hashKey, bn as hashQueryKeyByOptions, bq as isPlainArray, br as isPlainObject, i as isServer, bj as isValidTimeout, k as keepPreviousData, f as matchMutation, m as matchQuery, n as noop, bo as partialMatchKey, bt as replaceData, r as replaceEqualDeep, bm as resolveEnabled, bl as resolveStaleTime, bp as shallowEqualObjects, g as shouldThrowError, s as skipToken, bs as sleep, bk as timeUntilStale } from './hydration-B3ndIyL6.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
package/package.json
CHANGED
package/src/hydration.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tryResolveSync } from './thenable'
|
|
1
2
|
import type {
|
|
2
3
|
DefaultError,
|
|
3
4
|
MutationKey,
|
|
@@ -46,6 +47,10 @@ interface DehydratedQuery {
|
|
|
46
47
|
state: QueryState
|
|
47
48
|
promise?: Promise<unknown>
|
|
48
49
|
meta?: QueryMeta
|
|
50
|
+
// This is only optional because older versions of Query might have dehydrated
|
|
51
|
+
// without it which we need to handle for backwards compatibility.
|
|
52
|
+
// This should be changed to required in the future.
|
|
53
|
+
dehydratedAt?: number
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
export interface DehydratedState {
|
|
@@ -74,6 +79,7 @@ function dehydrateQuery(
|
|
|
74
79
|
shouldRedactErrors: (error: unknown) => boolean,
|
|
75
80
|
): DehydratedQuery {
|
|
76
81
|
return {
|
|
82
|
+
dehydratedAt: Date.now(),
|
|
77
83
|
state: {
|
|
78
84
|
...query.state,
|
|
79
85
|
...(query.state.data !== undefined && {
|
|
@@ -189,52 +195,73 @@ export function hydrate(
|
|
|
189
195
|
)
|
|
190
196
|
})
|
|
191
197
|
|
|
192
|
-
queries.forEach(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
queries.forEach(
|
|
199
|
+
({ queryKey, state, queryHash, meta, promise, dehydratedAt }) => {
|
|
200
|
+
const syncData = promise ? tryResolveSync(promise) : undefined
|
|
201
|
+
const rawData = state.data === undefined ? syncData?.data : state.data
|
|
202
|
+
const data = rawData === undefined ? rawData : deserializeData(rawData)
|
|
203
|
+
|
|
204
|
+
let query = queryCache.get(queryHash)
|
|
205
|
+
const existingQueryIsPending = query?.state.status === 'pending'
|
|
206
|
+
|
|
207
|
+
// Do not hydrate if an existing query exists with newer data
|
|
208
|
+
if (query) {
|
|
209
|
+
const hasNewerSyncData =
|
|
210
|
+
syncData &&
|
|
211
|
+
// We only need this undefined check to handle older dehydration
|
|
212
|
+
// payloads that might not have dehydratedAt
|
|
213
|
+
dehydratedAt !== undefined &&
|
|
214
|
+
dehydratedAt > query.state.dataUpdatedAt
|
|
215
|
+
if (
|
|
216
|
+
state.dataUpdatedAt > query.state.dataUpdatedAt ||
|
|
217
|
+
hasNewerSyncData
|
|
218
|
+
) {
|
|
219
|
+
// omit fetchStatus from dehydrated state
|
|
220
|
+
// so that query stays in its current fetchStatus
|
|
221
|
+
const { fetchStatus: _ignored, ...serializedState } = state
|
|
222
|
+
query.setState({
|
|
223
|
+
...serializedState,
|
|
224
|
+
data,
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
// Restore query
|
|
229
|
+
query = queryCache.build(
|
|
230
|
+
client,
|
|
231
|
+
{
|
|
232
|
+
...client.getDefaultOptions().hydrate?.queries,
|
|
233
|
+
...options?.defaultOptions?.queries,
|
|
234
|
+
queryKey,
|
|
235
|
+
queryHash,
|
|
236
|
+
meta,
|
|
237
|
+
},
|
|
238
|
+
// Reset fetch status to idle to avoid
|
|
239
|
+
// query being stuck in fetching state upon hydration
|
|
240
|
+
{
|
|
241
|
+
...state,
|
|
242
|
+
data,
|
|
243
|
+
fetchStatus: 'idle',
|
|
244
|
+
status: data !== undefined ? 'success' : state.status,
|
|
245
|
+
},
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (
|
|
250
|
+
promise &&
|
|
251
|
+
!existingQueryIsPending &&
|
|
252
|
+
// Only hydrate if dehydration is newer than any existing data,
|
|
253
|
+
// this is always true for new queries
|
|
254
|
+
(dehydratedAt === undefined || dehydratedAt > query.state.dataUpdatedAt)
|
|
255
|
+
) {
|
|
256
|
+
// This doesn't actually fetch - it just creates a retryer
|
|
257
|
+
// which will re-use the passed `initialPromise`
|
|
258
|
+
// Note that we need to call these even when data was synchronously
|
|
259
|
+
// available, as we still need to set up the retryer
|
|
260
|
+
void query.fetch(undefined, {
|
|
261
|
+
// RSC transformed promises are not thenable
|
|
262
|
+
initialPromise: Promise.resolve(promise).then(deserializeData),
|
|
207
263
|
})
|
|
208
264
|
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
query = queryCache.build(
|
|
212
|
-
client,
|
|
213
|
-
{
|
|
214
|
-
...client.getDefaultOptions().hydrate?.queries,
|
|
215
|
-
...options?.defaultOptions?.queries,
|
|
216
|
-
queryKey,
|
|
217
|
-
queryHash,
|
|
218
|
-
meta,
|
|
219
|
-
},
|
|
220
|
-
// Reset fetch status to idle to avoid
|
|
221
|
-
// query being stuck in fetching state upon hydration
|
|
222
|
-
{
|
|
223
|
-
...state,
|
|
224
|
-
data,
|
|
225
|
-
fetchStatus: 'idle',
|
|
226
|
-
},
|
|
227
|
-
)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (promise) {
|
|
231
|
-
// Note: `Promise.resolve` required cause
|
|
232
|
-
// RSC transformed promises are not thenable
|
|
233
|
-
const initialPromise = Promise.resolve(promise).then(deserializeData)
|
|
234
|
-
|
|
235
|
-
// this doesn't actually fetch - it just creates a retryer
|
|
236
|
-
// which will re-use the passed `initialPromise`
|
|
237
|
-
void query.fetch(undefined, { initialPromise })
|
|
238
|
-
}
|
|
239
|
-
})
|
|
265
|
+
},
|
|
266
|
+
)
|
|
240
267
|
}
|
package/src/thenable.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* @see https://github.com/facebook/react/blob/4f604941569d2e8947ce1460a0b2997e835f37b9/packages/react-debug-tools/src/ReactDebugHooks.js#L224-L227
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { noop } from './utils'
|
|
11
|
+
|
|
10
12
|
interface Fulfilled<T> {
|
|
11
13
|
status: 'fulfilled'
|
|
12
14
|
value: T
|
|
@@ -80,3 +82,30 @@ export function pendingThenable<T>(): PendingThenable<T> {
|
|
|
80
82
|
|
|
81
83
|
return thenable
|
|
82
84
|
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* This function takes a Promise-like input and detects whether the data
|
|
88
|
+
* is synchronously available or not.
|
|
89
|
+
*
|
|
90
|
+
* It does not inspect .status, .value or .reason properties of the promise,
|
|
91
|
+
* as those are not always available, and the .status of React's promises
|
|
92
|
+
* should not be considered part of the public API.
|
|
93
|
+
*/
|
|
94
|
+
export function tryResolveSync(promise: Promise<unknown> | Thenable<unknown>) {
|
|
95
|
+
let data: unknown
|
|
96
|
+
|
|
97
|
+
promise
|
|
98
|
+
.then((result) => {
|
|
99
|
+
data = result
|
|
100
|
+
return result
|
|
101
|
+
})
|
|
102
|
+
// .catch can be unavailable on certain kinds of thenable's
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
104
|
+
?.catch(noop)
|
|
105
|
+
|
|
106
|
+
if (data !== undefined) {
|
|
107
|
+
return { data }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return undefined
|
|
111
|
+
}
|