@tanstack/react-query 4.1.3 → 4.3.0-beta.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/{types/packages/react-query/src → lib}/Hydrate.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/QueryClientProvider.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/QueryErrorResetBoundary.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/index.d.ts +0 -0
- package/build/lib/index.js +625 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +579 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/{types/packages/react-query/src → lib}/isRestoring.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/reactBatchedUpdates.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/reactBatchedUpdates.native.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/setBatchUpdatesFn.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/types.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useBaseQuery.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useInfiniteQuery.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useIsFetching.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useIsMutating.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useMutation.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useQueries.d.ts +0 -0
- package/build/{types/packages/react-query/src → lib}/useQuery.d.ts +0 -0
- package/build/lib/useSyncExternalStore.d.ts +1 -0
- package/build/lib/useSyncExternalStore.native.d.ts +1 -0
- package/build/{types/packages/react-query/src → lib}/utils.d.ts +0 -0
- package/build/umd/index.development.js +274 -9
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +3 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +17 -15
- package/src/useBaseQuery.ts +1 -1
- package/src/useIsFetching.ts +1 -1
- package/src/useIsMutating.ts +1 -1
- package/src/useMutation.ts +1 -1
- package/src/useQueries.ts +1 -1
- package/src/useSyncExternalStore.native.ts +3 -0
- package/src/useSyncExternalStore.ts +2 -0
- package/build/cjs/query-core/build/esm/index.js +0 -3123
- package/build/cjs/query-core/build/esm/index.js.map +0 -1
- package/build/cjs/react-query/src/Hydrate.js +0 -66
- package/build/cjs/react-query/src/Hydrate.js.map +0 -1
- package/build/cjs/react-query/src/QueryClientProvider.js +0 -96
- package/build/cjs/react-query/src/QueryClientProvider.js.map +0 -1
- package/build/cjs/react-query/src/QueryErrorResetBoundary.js +0 -67
- package/build/cjs/react-query/src/QueryErrorResetBoundary.js.map +0 -1
- package/build/cjs/react-query/src/index.js +0 -64
- package/build/cjs/react-query/src/index.js.map +0 -1
- package/build/cjs/react-query/src/isRestoring.js +0 -43
- package/build/cjs/react-query/src/isRestoring.js.map +0 -1
- package/build/cjs/react-query/src/useBaseQuery.js +0 -117
- package/build/cjs/react-query/src/useBaseQuery.js.map +0 -1
- package/build/cjs/react-query/src/useInfiniteQuery.js +0 -24
- package/build/cjs/react-query/src/useInfiniteQuery.js.map +0 -1
- package/build/cjs/react-query/src/useIsFetching.js +0 -50
- package/build/cjs/react-query/src/useIsFetching.js.map +0 -1
- package/build/cjs/react-query/src/useIsMutating.js +0 -50
- package/build/cjs/react-query/src/useIsMutating.js.map +0 -1
- package/build/cjs/react-query/src/useMutation.js +0 -68
- package/build/cjs/react-query/src/useMutation.js.map +0 -1
- package/build/cjs/react-query/src/useQueries.js +0 -71
- package/build/cjs/react-query/src/useQueries.js.map +0 -1
- package/build/cjs/react-query/src/useQuery.js +0 -24
- package/build/cjs/react-query/src/useQuery.js.map +0 -1
- package/build/cjs/react-query/src/utils.js +0 -25
- package/build/cjs/react-query/src/utils.js.map +0 -1
- package/build/esm/index.js +0 -3381
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -2689
- package/build/stats.json +0 -666
- package/build/types/packages/query-core/src/focusManager.d.ts +0 -16
- package/build/types/packages/query-core/src/hydration.d.ts +0 -34
- package/build/types/packages/query-core/src/index.d.ts +0 -20
- package/build/types/packages/query-core/src/infiniteQueryBehavior.d.ts +0 -15
- package/build/types/packages/query-core/src/infiniteQueryObserver.d.ts +0 -18
- package/build/types/packages/query-core/src/logger.d.ts +0 -8
- package/build/types/packages/query-core/src/mutation.d.ts +0 -70
- package/build/types/packages/query-core/src/mutationCache.d.ts +0 -57
- package/build/types/packages/query-core/src/mutationObserver.d.ts +0 -23
- package/build/types/packages/query-core/src/notifyManager.d.ts +0 -18
- package/build/types/packages/query-core/src/onlineManager.d.ts +0 -16
- package/build/types/packages/query-core/src/queriesObserver.d.ts +0 -23
- package/build/types/packages/query-core/src/query.d.ts +0 -119
- package/build/types/packages/query-core/src/queryCache.d.ts +0 -64
- package/build/types/packages/query-core/src/queryClient.d.ts +0 -65
- package/build/types/packages/query-core/src/queryObserver.d.ts +0 -61
- package/build/types/packages/query-core/src/removable.d.ts +0 -9
- package/build/types/packages/query-core/src/retryer.d.ts +0 -33
- package/build/types/packages/query-core/src/subscribable.d.ts +0 -10
- package/build/types/packages/query-core/src/types.d.ts +0 -418
- package/build/types/packages/query-core/src/utils.d.ts +0 -99
- package/build/types/packages/react-query/src/__tests__/Hydrate.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/QueryClientProvider.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/QueryResetErrorBoundary.test.d.ts +0 -6
- package/build/types/packages/react-query/src/__tests__/ssr-hydration.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/ssr.test.d.ts +0 -4
- package/build/types/packages/react-query/src/__tests__/suspense.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useInfiniteQuery.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useIsFetching.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useIsMutating.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useMutation.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useQueries.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useQuery.test.d.ts +0 -1
- package/build/types/packages/react-query/src/__tests__/useQuery.types.test.d.ts +0 -2
- package/build/types/packages/react-query/src/__tests__/utils.d.ts +0 -8
- package/build/types/tests/utils.d.ts +0 -24
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-query
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var queryCore = require('@tanstack/query-core');
|
|
16
|
+
var ReactDOM = require('react-dom');
|
|
17
|
+
var React = require('react');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
|
+
|
|
21
|
+
function _interopNamespace(e) {
|
|
22
|
+
if (e && e.__esModule) return e;
|
|
23
|
+
var n = Object.create(null);
|
|
24
|
+
if (e) {
|
|
25
|
+
Object.keys(e).forEach(function (k) {
|
|
26
|
+
if (k !== 'default') {
|
|
27
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
28
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return e[k]; }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
n["default"] = e;
|
|
36
|
+
return Object.freeze(n);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
|
|
40
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
41
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
42
|
+
|
|
43
|
+
const unstable_batchedUpdates = ReactDOM__namespace.unstable_batchedUpdates;
|
|
44
|
+
|
|
45
|
+
queryCore.notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
|
|
46
|
+
|
|
47
|
+
var shim = {exports: {}};
|
|
48
|
+
|
|
49
|
+
var useSyncExternalStoreShim_production_min = {};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @license React
|
|
53
|
+
* use-sync-external-store-shim.production.min.js
|
|
54
|
+
*
|
|
55
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
56
|
+
*
|
|
57
|
+
* This source code is licensed under the MIT license found in the
|
|
58
|
+
* LICENSE file in the root directory of this source tree.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
62
|
+
|
|
63
|
+
function requireUseSyncExternalStoreShim_production_min () {
|
|
64
|
+
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
65
|
+
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
66
|
+
var e=React__default["default"];function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
|
|
67
|
+
function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
|
|
68
|
+
return useSyncExternalStoreShim_production_min;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var useSyncExternalStoreShim_development = {};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @license React
|
|
75
|
+
* use-sync-external-store-shim.development.js
|
|
76
|
+
*
|
|
77
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the MIT license found in the
|
|
80
|
+
* LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
var hasRequiredUseSyncExternalStoreShim_development;
|
|
84
|
+
|
|
85
|
+
function requireUseSyncExternalStoreShim_development () {
|
|
86
|
+
if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
|
|
87
|
+
hasRequiredUseSyncExternalStoreShim_development = 1;
|
|
88
|
+
|
|
89
|
+
if (process.env.NODE_ENV !== "production") {
|
|
90
|
+
(function() {
|
|
91
|
+
|
|
92
|
+
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
93
|
+
if (
|
|
94
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
95
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
96
|
+
'function'
|
|
97
|
+
) {
|
|
98
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
99
|
+
}
|
|
100
|
+
var React = React__default["default"];
|
|
101
|
+
|
|
102
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
103
|
+
|
|
104
|
+
function error(format) {
|
|
105
|
+
{
|
|
106
|
+
{
|
|
107
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
108
|
+
args[_key2 - 1] = arguments[_key2];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
printWarning('error', format, args);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function printWarning(level, format, args) {
|
|
117
|
+
// When changing this logic, you might want to also
|
|
118
|
+
// update consoleWithStackDev.www.js as well.
|
|
119
|
+
{
|
|
120
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
121
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
122
|
+
|
|
123
|
+
if (stack !== '') {
|
|
124
|
+
format += '%s';
|
|
125
|
+
args = args.concat([stack]);
|
|
126
|
+
} // eslint-disable-next-line react-internal/safe-string-coercion
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
var argsWithFormat = args.map(function (item) {
|
|
130
|
+
return String(item);
|
|
131
|
+
}); // Careful: RN currently depends on this prefix
|
|
132
|
+
|
|
133
|
+
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
134
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
135
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
|
136
|
+
|
|
137
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
143
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
144
|
+
*/
|
|
145
|
+
function is(x, y) {
|
|
146
|
+
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
|
147
|
+
;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
var objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
151
|
+
|
|
152
|
+
// dispatch for CommonJS interop named imports.
|
|
153
|
+
|
|
154
|
+
var useState = React.useState,
|
|
155
|
+
useEffect = React.useEffect,
|
|
156
|
+
useLayoutEffect = React.useLayoutEffect,
|
|
157
|
+
useDebugValue = React.useDebugValue;
|
|
158
|
+
var didWarnOld18Alpha = false;
|
|
159
|
+
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
160
|
+
// because of a very particular set of implementation details and assumptions
|
|
161
|
+
// -- change any one of them and it will break. The most important assumption
|
|
162
|
+
// is that updates are always synchronous, because concurrent rendering is
|
|
163
|
+
// only available in versions of React that also have a built-in
|
|
164
|
+
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
165
|
+
// does not exist.
|
|
166
|
+
//
|
|
167
|
+
// Do not assume that the clever hacks used by this hook also work in general.
|
|
168
|
+
// The point of this shim is to replace the need for hacks by other libraries.
|
|
169
|
+
|
|
170
|
+
function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
171
|
+
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
172
|
+
// will need to track that themselves and return the correct value
|
|
173
|
+
// from `getSnapshot`.
|
|
174
|
+
getServerSnapshot) {
|
|
175
|
+
{
|
|
176
|
+
if (!didWarnOld18Alpha) {
|
|
177
|
+
if (React.startTransition !== undefined) {
|
|
178
|
+
didWarnOld18Alpha = true;
|
|
179
|
+
|
|
180
|
+
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} // Read the current snapshot from the store on every render. Again, this
|
|
184
|
+
// breaks the rules of React, and only works here because of specific
|
|
185
|
+
// implementation details, most importantly that updates are
|
|
186
|
+
// always synchronous.
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
var value = getSnapshot();
|
|
190
|
+
|
|
191
|
+
{
|
|
192
|
+
if (!didWarnUncachedGetSnapshot) {
|
|
193
|
+
var cachedValue = getSnapshot();
|
|
194
|
+
|
|
195
|
+
if (!objectIs(value, cachedValue)) {
|
|
196
|
+
error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
197
|
+
|
|
198
|
+
didWarnUncachedGetSnapshot = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} // Because updates are synchronous, we don't queue them. Instead we force a
|
|
202
|
+
// re-render whenever the subscribed state changes by updating an some
|
|
203
|
+
// arbitrary useState hook. Then, during render, we call getSnapshot to read
|
|
204
|
+
// the current value.
|
|
205
|
+
//
|
|
206
|
+
// Because we don't actually use the state returned by the useState hook, we
|
|
207
|
+
// can save a bit of memory by storing other stuff in that slot.
|
|
208
|
+
//
|
|
209
|
+
// To implement the early bailout, we need to track some things on a mutable
|
|
210
|
+
// object. Usually, we would put that in a useRef hook, but we can stash it in
|
|
211
|
+
// our useState hook instead.
|
|
212
|
+
//
|
|
213
|
+
// To force a re-render, we call forceUpdate({inst}). That works because the
|
|
214
|
+
// new object always fails an equality check.
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
var _useState = useState({
|
|
218
|
+
inst: {
|
|
219
|
+
value: value,
|
|
220
|
+
getSnapshot: getSnapshot
|
|
221
|
+
}
|
|
222
|
+
}),
|
|
223
|
+
inst = _useState[0].inst,
|
|
224
|
+
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
|
|
225
|
+
// in the layout phase so we can access it during the tearing check that
|
|
226
|
+
// happens on subscribe.
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
useLayoutEffect(function () {
|
|
230
|
+
inst.value = value;
|
|
231
|
+
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
|
|
232
|
+
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
233
|
+
// this can happen all the time, but even in synchronous mode, an earlier
|
|
234
|
+
// effect may have mutated the store.
|
|
235
|
+
|
|
236
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
237
|
+
// Force a re-render.
|
|
238
|
+
forceUpdate({
|
|
239
|
+
inst: inst
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}, [subscribe, value, getSnapshot]);
|
|
243
|
+
useEffect(function () {
|
|
244
|
+
// Check for changes right before subscribing. Subsequent changes will be
|
|
245
|
+
// detected in the subscription handler.
|
|
246
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
247
|
+
// Force a re-render.
|
|
248
|
+
forceUpdate({
|
|
249
|
+
inst: inst
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
var handleStoreChange = function () {
|
|
254
|
+
// TODO: Because there is no cross-renderer API for batching updates, it's
|
|
255
|
+
// up to the consumer of this library to wrap their subscription event
|
|
256
|
+
// with unstable_batchedUpdates. Should we try to detect when this isn't
|
|
257
|
+
// the case and print a warning in development?
|
|
258
|
+
// The store changed. Check if the snapshot changed since the last time we
|
|
259
|
+
// read from the store.
|
|
260
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
261
|
+
// Force a re-render.
|
|
262
|
+
forceUpdate({
|
|
263
|
+
inst: inst
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}; // Subscribe to the store and return a clean-up function.
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
return subscribe(handleStoreChange);
|
|
270
|
+
}, [subscribe]);
|
|
271
|
+
useDebugValue(value);
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function checkIfSnapshotChanged(inst) {
|
|
276
|
+
var latestGetSnapshot = inst.getSnapshot;
|
|
277
|
+
var prevValue = inst.value;
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
var nextValue = latestGetSnapshot();
|
|
281
|
+
return !objectIs(prevValue, nextValue);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
288
|
+
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
289
|
+
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
290
|
+
// will need to track that themselves and return the correct value
|
|
291
|
+
// from `getSnapshot`.
|
|
292
|
+
return getSnapshot();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
296
|
+
|
|
297
|
+
var isServerEnvironment = !canUseDOM;
|
|
298
|
+
|
|
299
|
+
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
300
|
+
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
301
|
+
|
|
302
|
+
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
|
|
303
|
+
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
304
|
+
if (
|
|
305
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
306
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
307
|
+
'function'
|
|
308
|
+
) {
|
|
309
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
})();
|
|
313
|
+
}
|
|
314
|
+
return useSyncExternalStoreShim_development;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
(function (module) {
|
|
318
|
+
|
|
319
|
+
if (process.env.NODE_ENV === 'production') {
|
|
320
|
+
module.exports = requireUseSyncExternalStoreShim_production_min();
|
|
321
|
+
} else {
|
|
322
|
+
module.exports = requireUseSyncExternalStoreShim_development();
|
|
323
|
+
}
|
|
324
|
+
} (shim));
|
|
325
|
+
|
|
326
|
+
const defaultContext = /*#__PURE__*/React__namespace.createContext(undefined);
|
|
327
|
+
const QueryClientSharingContext = /*#__PURE__*/React__namespace.createContext(false); // If we are given a context, we will use it.
|
|
328
|
+
// Otherwise, if contextSharing is on, we share the first and at least one
|
|
329
|
+
// instance of the context across the window
|
|
330
|
+
// to ensure that if React Query is used across
|
|
331
|
+
// different bundles or microfrontends they will
|
|
332
|
+
// all use the same **instance** of context, regardless
|
|
333
|
+
// of module scoping.
|
|
334
|
+
|
|
335
|
+
function getQueryClientContext(context, contextSharing) {
|
|
336
|
+
if (context) {
|
|
337
|
+
return context;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (contextSharing && typeof window !== 'undefined') {
|
|
341
|
+
if (!window.ReactQueryClientContext) {
|
|
342
|
+
window.ReactQueryClientContext = defaultContext;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return window.ReactQueryClientContext;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return defaultContext;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const useQueryClient = ({
|
|
352
|
+
context
|
|
353
|
+
} = {}) => {
|
|
354
|
+
const queryClient = React__namespace.useContext(getQueryClientContext(context, React__namespace.useContext(QueryClientSharingContext)));
|
|
355
|
+
|
|
356
|
+
if (!queryClient) {
|
|
357
|
+
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return queryClient;
|
|
361
|
+
};
|
|
362
|
+
const QueryClientProvider = ({
|
|
363
|
+
client,
|
|
364
|
+
children,
|
|
365
|
+
context,
|
|
366
|
+
contextSharing = false
|
|
367
|
+
}) => {
|
|
368
|
+
React__namespace.useEffect(() => {
|
|
369
|
+
client.mount();
|
|
370
|
+
return () => {
|
|
371
|
+
client.unmount();
|
|
372
|
+
};
|
|
373
|
+
}, [client]);
|
|
374
|
+
const Context = getQueryClientContext(context, contextSharing);
|
|
375
|
+
return /*#__PURE__*/React__namespace.createElement(QueryClientSharingContext.Provider, {
|
|
376
|
+
value: !context && contextSharing
|
|
377
|
+
}, /*#__PURE__*/React__namespace.createElement(Context.Provider, {
|
|
378
|
+
value: client
|
|
379
|
+
}, children));
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const IsRestoringContext = /*#__PURE__*/React__namespace.createContext(false);
|
|
383
|
+
const useIsRestoring = () => React__namespace.useContext(IsRestoringContext);
|
|
384
|
+
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
385
|
+
|
|
386
|
+
// - `context` is omitted as it is passed as a root-level option to `useQueries` instead.
|
|
387
|
+
|
|
388
|
+
function useQueries({
|
|
389
|
+
queries,
|
|
390
|
+
context
|
|
391
|
+
}) {
|
|
392
|
+
const queryClient = useQueryClient({
|
|
393
|
+
context
|
|
394
|
+
});
|
|
395
|
+
const isRestoring = useIsRestoring();
|
|
396
|
+
const defaultedQueries = React__namespace.useMemo(() => queries.map(options => {
|
|
397
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure the results are already in fetching state before subscribing or updating options
|
|
398
|
+
|
|
399
|
+
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
400
|
+
return defaultedOptions;
|
|
401
|
+
}), [queries, queryClient, isRestoring]);
|
|
402
|
+
const [observer] = React__namespace.useState(() => new queryCore.QueriesObserver(queryClient, defaultedQueries));
|
|
403
|
+
const result = observer.getOptimisticResult(defaultedQueries);
|
|
404
|
+
shim.exports.useSyncExternalStore(React__namespace.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
405
|
+
React__namespace.useEffect(() => {
|
|
406
|
+
// Do not notify on updates because of changes in the options because
|
|
407
|
+
// these changes should already be reflected in the optimistic result.
|
|
408
|
+
observer.setQueries(defaultedQueries, {
|
|
409
|
+
listeners: false
|
|
410
|
+
});
|
|
411
|
+
}, [defaultedQueries, observer]);
|
|
412
|
+
return result;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function createValue() {
|
|
416
|
+
let isReset = false;
|
|
417
|
+
return {
|
|
418
|
+
clearReset: () => {
|
|
419
|
+
isReset = false;
|
|
420
|
+
},
|
|
421
|
+
reset: () => {
|
|
422
|
+
isReset = true;
|
|
423
|
+
},
|
|
424
|
+
isReset: () => {
|
|
425
|
+
return isReset;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const QueryErrorResetBoundaryContext = /*#__PURE__*/React__namespace.createContext(createValue()); // HOOK
|
|
431
|
+
|
|
432
|
+
const useQueryErrorResetBoundary = () => React__namespace.useContext(QueryErrorResetBoundaryContext); // COMPONENT
|
|
433
|
+
|
|
434
|
+
const QueryErrorResetBoundary = ({
|
|
435
|
+
children
|
|
436
|
+
}) => {
|
|
437
|
+
const [value] = React__namespace.useState(() => createValue());
|
|
438
|
+
return /*#__PURE__*/React__namespace.createElement(QueryErrorResetBoundaryContext.Provider, {
|
|
439
|
+
value: value
|
|
440
|
+
}, typeof children === 'function' ? children(value) : children);
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
function shouldThrowError(_useErrorBoundary, params) {
|
|
444
|
+
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
445
|
+
if (typeof _useErrorBoundary === 'function') {
|
|
446
|
+
return _useErrorBoundary(...params);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return !!_useErrorBoundary;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function useBaseQuery(options, Observer) {
|
|
453
|
+
const queryClient = useQueryClient({
|
|
454
|
+
context: options.context
|
|
455
|
+
});
|
|
456
|
+
const isRestoring = useIsRestoring();
|
|
457
|
+
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
458
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
459
|
+
|
|
460
|
+
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic'; // Include callbacks in batch renders
|
|
461
|
+
|
|
462
|
+
if (defaultedOptions.onError) {
|
|
463
|
+
defaultedOptions.onError = queryCore.notifyManager.batchCalls(defaultedOptions.onError);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (defaultedOptions.onSuccess) {
|
|
467
|
+
defaultedOptions.onSuccess = queryCore.notifyManager.batchCalls(defaultedOptions.onSuccess);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (defaultedOptions.onSettled) {
|
|
471
|
+
defaultedOptions.onSettled = queryCore.notifyManager.batchCalls(defaultedOptions.onSettled);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (defaultedOptions.suspense) {
|
|
475
|
+
// Always set stale time when using suspense to prevent
|
|
476
|
+
// fetching again when directly mounting after suspending
|
|
477
|
+
if (typeof defaultedOptions.staleTime !== 'number') {
|
|
478
|
+
defaultedOptions.staleTime = 1000;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {
|
|
483
|
+
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
484
|
+
if (!errorResetBoundary.isReset()) {
|
|
485
|
+
defaultedOptions.retryOnMount = false;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const [observer] = React__namespace.useState(() => new Observer(queryClient, defaultedOptions));
|
|
490
|
+
const result = observer.getOptimisticResult(defaultedOptions);
|
|
491
|
+
shim.exports.useSyncExternalStore(React__namespace.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
492
|
+
React__namespace.useEffect(() => {
|
|
493
|
+
errorResetBoundary.clearReset();
|
|
494
|
+
}, [errorResetBoundary]);
|
|
495
|
+
React__namespace.useEffect(() => {
|
|
496
|
+
// Do not notify on updates because of changes in the options because
|
|
497
|
+
// these changes should already be reflected in the optimistic result.
|
|
498
|
+
observer.setOptions(defaultedOptions, {
|
|
499
|
+
listeners: false
|
|
500
|
+
});
|
|
501
|
+
}, [defaultedOptions, observer]); // Handle suspense
|
|
502
|
+
|
|
503
|
+
if (defaultedOptions.suspense && result.isLoading && result.isFetching && !isRestoring) {
|
|
504
|
+
throw observer.fetchOptimistic(defaultedOptions).then(({
|
|
505
|
+
data
|
|
506
|
+
}) => {
|
|
507
|
+
defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
|
|
508
|
+
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
|
|
509
|
+
}).catch(error => {
|
|
510
|
+
errorResetBoundary.clearReset();
|
|
511
|
+
defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
|
|
512
|
+
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
|
|
513
|
+
});
|
|
514
|
+
} // Handle error boundary
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
if (result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(defaultedOptions.useErrorBoundary, [result.error, observer.getCurrentQuery()])) {
|
|
518
|
+
throw result.error;
|
|
519
|
+
} // Handle result property usage tracking
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function useQuery(arg1, arg2, arg3) {
|
|
526
|
+
const parsedOptions = queryCore.parseQueryArgs(arg1, arg2, arg3);
|
|
527
|
+
return useBaseQuery(parsedOptions, queryCore.QueryObserver);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function useHydrate(state, options = {}) {
|
|
531
|
+
const queryClient = useQueryClient({
|
|
532
|
+
context: options.context
|
|
533
|
+
});
|
|
534
|
+
const optionsRef = React__namespace.useRef(options);
|
|
535
|
+
optionsRef.current = options; // Running hydrate again with the same queries is safe,
|
|
536
|
+
// it wont overwrite or initialize existing queries,
|
|
537
|
+
// relying on useMemo here is only a performance optimization.
|
|
538
|
+
// hydrate can and should be run *during* render here for SSR to work properly
|
|
539
|
+
|
|
540
|
+
React__namespace.useMemo(() => {
|
|
541
|
+
if (state) {
|
|
542
|
+
queryCore.hydrate(queryClient, state, optionsRef.current);
|
|
543
|
+
}
|
|
544
|
+
}, [queryClient, state]);
|
|
545
|
+
}
|
|
546
|
+
const Hydrate = ({
|
|
547
|
+
children,
|
|
548
|
+
options,
|
|
549
|
+
state
|
|
550
|
+
}) => {
|
|
551
|
+
useHydrate(state, options);
|
|
552
|
+
return children;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
function useIsFetching(arg1, arg2, arg3) {
|
|
556
|
+
const [filters, options = {}] = queryCore.parseFilterArgs(arg1, arg2, arg3);
|
|
557
|
+
const queryClient = useQueryClient({
|
|
558
|
+
context: options.context
|
|
559
|
+
});
|
|
560
|
+
const queryCache = queryClient.getQueryCache();
|
|
561
|
+
return shim.exports.useSyncExternalStore(React__namespace.useCallback(onStoreChange => queryCache.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [queryCache]), () => queryClient.isFetching(filters), () => queryClient.isFetching(filters));
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function useIsMutating(arg1, arg2, arg3) {
|
|
565
|
+
const [filters, options = {}] = queryCore.parseMutationFilterArgs(arg1, arg2, arg3);
|
|
566
|
+
const queryClient = useQueryClient({
|
|
567
|
+
context: options.context
|
|
568
|
+
});
|
|
569
|
+
const mutationCache = queryClient.getMutationCache();
|
|
570
|
+
return shim.exports.useSyncExternalStore(React__namespace.useCallback(onStoreChange => mutationCache.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [mutationCache]), () => queryClient.isMutating(filters), () => queryClient.isMutating(filters));
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function useMutation(arg1, arg2, arg3) {
|
|
574
|
+
const options = queryCore.parseMutationArgs(arg1, arg2, arg3);
|
|
575
|
+
const queryClient = useQueryClient({
|
|
576
|
+
context: options.context
|
|
577
|
+
});
|
|
578
|
+
const [observer] = React__namespace.useState(() => new queryCore.MutationObserver(queryClient, options));
|
|
579
|
+
React__namespace.useEffect(() => {
|
|
580
|
+
observer.setOptions(options);
|
|
581
|
+
}, [observer, options]);
|
|
582
|
+
const result = shim.exports.useSyncExternalStore(React__namespace.useCallback(onStoreChange => observer.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
583
|
+
const mutate = React__namespace.useCallback((variables, mutateOptions) => {
|
|
584
|
+
observer.mutate(variables, mutateOptions).catch(noop);
|
|
585
|
+
}, [observer]);
|
|
586
|
+
|
|
587
|
+
if (result.error && shouldThrowError(observer.options.useErrorBoundary, [result.error])) {
|
|
588
|
+
throw result.error;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return { ...result,
|
|
592
|
+
mutate,
|
|
593
|
+
mutateAsync: result.mutate
|
|
594
|
+
};
|
|
595
|
+
} // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
596
|
+
|
|
597
|
+
function noop() {}
|
|
598
|
+
|
|
599
|
+
function useInfiniteQuery(arg1, arg2, arg3) {
|
|
600
|
+
const options = queryCore.parseQueryArgs(arg1, arg2, arg3);
|
|
601
|
+
return useBaseQuery(options, queryCore.InfiniteQueryObserver);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
exports.Hydrate = Hydrate;
|
|
605
|
+
exports.IsRestoringProvider = IsRestoringProvider;
|
|
606
|
+
exports.QueryClientProvider = QueryClientProvider;
|
|
607
|
+
exports.QueryErrorResetBoundary = QueryErrorResetBoundary;
|
|
608
|
+
exports.defaultContext = defaultContext;
|
|
609
|
+
exports.useHydrate = useHydrate;
|
|
610
|
+
exports.useInfiniteQuery = useInfiniteQuery;
|
|
611
|
+
exports.useIsFetching = useIsFetching;
|
|
612
|
+
exports.useIsMutating = useIsMutating;
|
|
613
|
+
exports.useIsRestoring = useIsRestoring;
|
|
614
|
+
exports.useMutation = useMutation;
|
|
615
|
+
exports.useQueries = useQueries;
|
|
616
|
+
exports.useQuery = useQuery;
|
|
617
|
+
exports.useQueryClient = useQueryClient;
|
|
618
|
+
exports.useQueryErrorResetBoundary = useQueryErrorResetBoundary;
|
|
619
|
+
Object.keys(queryCore).forEach(function (k) {
|
|
620
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
621
|
+
enumerable: true,
|
|
622
|
+
get: function () { return queryCore[k]; }
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
//# sourceMappingURL=index.js.map
|