@apollo/client 3.6.1 → 3.6.4

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.
Files changed (89) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +133 -78
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs.native.js +2289 -0
  6. package/core/ApolloClient.d.ts.map +1 -1
  7. package/core/ApolloClient.js.map +1 -1
  8. package/core/ObservableQuery.d.ts.map +1 -1
  9. package/core/ObservableQuery.js +3 -1
  10. package/core/ObservableQuery.js.map +1 -1
  11. package/core/core.cjs +4 -2
  12. package/core/core.cjs.map +1 -1
  13. package/core/core.cjs.native.js +2141 -0
  14. package/errors/errors.cjs.native.js +48 -0
  15. package/invariantErrorCodes.js +1 -1
  16. package/link/batch/batch.cjs.native.js +161 -0
  17. package/link/batch-http/batch-http.cjs.native.js +127 -0
  18. package/link/context/context.cjs.native.js +38 -0
  19. package/link/core/core.cjs.native.js +121 -0
  20. package/link/error/error.cjs.native.js +90 -0
  21. package/link/http/http.cjs.native.js +320 -0
  22. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  23. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  24. package/link/persisted-queries/index.d.ts +2 -1
  25. package/link/persisted-queries/index.d.ts.map +1 -1
  26. package/link/persisted-queries/index.js +26 -13
  27. package/link/persisted-queries/index.js.map +1 -1
  28. package/link/persisted-queries/persisted-queries.cjs +25 -12
  29. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  30. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  31. package/link/retry/retry.cjs.native.js +170 -0
  32. package/link/schema/schema.cjs.native.js +56 -0
  33. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  34. package/link/utils/utils.cjs.native.js +115 -0
  35. package/link/ws/ws.cjs.native.js +28 -0
  36. package/main.cjs.native.js +16 -0
  37. package/package.json +17 -18
  38. package/react/components/components.cjs.native.js +79 -0
  39. package/react/context/ApolloConsumer.js +2 -2
  40. package/react/context/ApolloProvider.js +2 -2
  41. package/react/context/context.cjs +4 -4
  42. package/react/context/context.cjs.map +1 -1
  43. package/react/context/context.cjs.native.js +67 -0
  44. package/react/hoc/hoc.cjs.native.js +325 -0
  45. package/react/hooks/hooks.cjs +151 -90
  46. package/react/hooks/hooks.cjs.map +1 -1
  47. package/react/hooks/hooks.cjs.native.js +604 -0
  48. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  49. package/react/hooks/useLazyQuery.js +7 -22
  50. package/react/hooks/useLazyQuery.js.map +1 -1
  51. package/react/hooks/useQuery.d.ts +5 -1
  52. package/react/hooks/useQuery.d.ts.map +1 -1
  53. package/react/hooks/useQuery.js +46 -39
  54. package/react/hooks/useQuery.js.map +1 -1
  55. package/react/hooks/useSubscription.d.ts.map +1 -1
  56. package/react/hooks/useSubscription.js +17 -7
  57. package/react/hooks/useSubscription.js.map +1 -1
  58. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  59. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  60. package/react/hooks/useSyncExternalStore.js +48 -0
  61. package/react/hooks/useSyncExternalStore.js.map +1 -0
  62. package/react/parser/parser.cjs.native.js +103 -0
  63. package/react/react.cjs.native.js +22 -0
  64. package/react/ssr/ssr.cjs.native.js +150 -0
  65. package/testing/core/core.cjs.native.js +288 -0
  66. package/testing/core/mocking/mockQueryManager.js +1 -1
  67. package/testing/core/mocking/mockWatchQuery.js +1 -1
  68. package/testing/core/wrap.js +1 -1
  69. package/testing/testing.cjs.native.js +58 -0
  70. package/utilities/common/canUse.d.ts +2 -0
  71. package/utilities/common/canUse.d.ts.map +1 -1
  72. package/utilities/common/canUse.js +6 -2
  73. package/utilities/common/canUse.js.map +1 -1
  74. package/utilities/common/mergeOptions.d.ts +1 -1
  75. package/utilities/common/mergeOptions.d.ts.map +1 -1
  76. package/utilities/common/mergeOptions.js +1 -1
  77. package/utilities/common/mergeOptions.js.map +1 -1
  78. package/utilities/globals/global.js +1 -2
  79. package/utilities/globals/globals.cjs.native.js +56 -0
  80. package/utilities/observables/Concast.d.ts.map +1 -1
  81. package/utilities/observables/Concast.js +5 -2
  82. package/utilities/observables/Concast.js.map +1 -1
  83. package/utilities/policies/pagination.d.ts.map +1 -1
  84. package/utilities/policies/pagination.js +9 -7
  85. package/utilities/policies/pagination.js.map +1 -1
  86. package/utilities/utilities.cjs +22 -12
  87. package/utilities/utilities.cjs.map +1 -1
  88. package/utilities/utilities.cjs.native.js +1284 -0
  89. package/version.js +1 -1
@@ -3,18 +3,31 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var globals = require('../../utilities/globals');
6
- var react = require('react');
6
+ var React = require('react');
7
7
  var context = require('../context');
8
8
  var tslib = require('tslib');
9
- var errors = require('../../errors');
10
- var index_js = require('use-sync-external-store/shim/index.js');
9
+ var utilities = require('../../utilities');
11
10
  var equality = require('@wry/equality');
12
11
  var core = require('../../core');
12
+ var errors = require('../../errors');
13
13
  var parser = require('../parser');
14
- var utilities = require('../../utilities');
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ for (var k in e) {
20
+ n[k] = e[k];
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
15
28
 
16
29
  function useApolloClient(override) {
17
- var context$1 = react.useContext(context.getApolloContext());
30
+ var context$1 = React.useContext(context.getApolloContext());
18
31
  var client = override || context$1.client;
19
32
  __DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
20
33
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
@@ -22,20 +35,65 @@ function useApolloClient(override) {
22
35
  return client;
23
36
  }
24
37
 
38
+ var didWarnUncachedGetSnapshot = false;
39
+ var uSESKey = "useSyncExternalStore";
40
+ var realHook = React__namespace[uSESKey];
41
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
42
+ var value = getSnapshot();
43
+ if (__DEV__ &&
44
+ !didWarnUncachedGetSnapshot &&
45
+ value !== getSnapshot()) {
46
+ didWarnUncachedGetSnapshot = true;
47
+ __DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
48
+ }
49
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
50
+ if (utilities.canUseLayoutEffect) {
51
+ React__namespace.useLayoutEffect(function () {
52
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
53
+ if (checkIfSnapshotChanged(inst)) {
54
+ forceUpdate({ inst: inst });
55
+ }
56
+ }, [subscribe, value, getSnapshot]);
57
+ }
58
+ else {
59
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
60
+ }
61
+ React__namespace.useEffect(function () {
62
+ if (checkIfSnapshotChanged(inst)) {
63
+ forceUpdate({ inst: inst });
64
+ }
65
+ return subscribe(function handleStoreChange() {
66
+ if (checkIfSnapshotChanged(inst)) {
67
+ forceUpdate({ inst: inst });
68
+ }
69
+ });
70
+ }, [subscribe]);
71
+ return value;
72
+ });
73
+ function checkIfSnapshotChanged(_a) {
74
+ var value = _a.value, getSnapshot = _a.getSnapshot;
75
+ try {
76
+ return value !== getSnapshot();
77
+ }
78
+ catch (_b) {
79
+ return true;
80
+ }
81
+ }
82
+
25
83
  var hasOwnProperty = Object.prototype.hasOwnProperty;
26
84
  function useQuery(query, options) {
27
85
  if (options === void 0) { options = Object.create(null); }
28
86
  return useInternalState(useApolloClient(options.client), query).useQuery(options);
29
87
  }
30
88
  function useInternalState(client, query) {
31
- var stateRef = react.useRef();
89
+ var stateRef = React.useRef();
32
90
  if (!stateRef.current ||
33
91
  client !== stateRef.current.client ||
34
92
  query !== stateRef.current.query) {
35
93
  stateRef.current = new InternalState(client, query);
36
94
  }
37
95
  var state = stateRef.current;
38
- var _a = react.useState(0); _a[0]; var setTick = _a[1];
96
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
39
97
  state.forceUpdate = function () {
40
98
  setTick(function (tick) { return tick + 1; });
41
99
  };
@@ -45,6 +103,8 @@ var InternalState = (function () {
45
103
  function InternalState(client, query) {
46
104
  this.client = client;
47
105
  this.query = query;
106
+ this.asyncResolveFns = new Set();
107
+ this.optionsToIgnoreOnce = new (utilities.canUseWeakSet ? WeakSet : Set)();
48
108
  this.ssrDisabledResult = utilities.maybeDeepFreeze({
49
109
  loading: true,
50
110
  data: void 0,
@@ -61,13 +121,22 @@ var InternalState = (function () {
61
121
  parser.verifyDocumentType(query, parser.DocumentType.Query);
62
122
  }
63
123
  InternalState.prototype.forceUpdate = function () {
124
+ __DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
125
+ };
126
+ InternalState.prototype.asyncUpdate = function () {
127
+ var _this = this;
128
+ return new Promise(function (resolve) {
129
+ _this.asyncResolveFns.add(resolve);
130
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
131
+ _this.forceUpdate();
132
+ });
64
133
  };
65
134
  InternalState.prototype.useQuery = function (options) {
66
135
  var _this = this;
67
- this.renderPromises = react.useContext(context.getApolloContext()).renderPromises;
136
+ this.renderPromises = React.useContext(context.getApolloContext()).renderPromises;
68
137
  this.useOptions(options);
69
138
  var obsQuery = this.useObservableQuery();
70
- var result = index_js.useSyncExternalStore(react.useCallback(function () {
139
+ var result = useSyncExternalStore(React.useCallback(function () {
71
140
  if (_this.renderPromises) {
72
141
  return function () { };
73
142
  }
@@ -113,17 +182,24 @@ var InternalState = (function () {
113
182
  obsQuery,
114
183
  this.renderPromises,
115
184
  this.client.disableNetworkFetches,
116
- ]), function () { return _this.getCurrentResult(); });
185
+ ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
117
186
  this.unsafeHandlePartialRefetch(result);
118
- return this.toQueryResult(result);
187
+ var queryResult = this.toQueryResult(result);
188
+ if (!queryResult.loading && this.asyncResolveFns.size) {
189
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
190
+ this.asyncResolveFns.clear();
191
+ }
192
+ return queryResult;
119
193
  };
120
194
  InternalState.prototype.useOptions = function (options) {
121
195
  var _a;
122
196
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
123
197
  var currentWatchQueryOptions = this.watchQueryOptions;
124
- if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
198
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
199
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
125
200
  this.watchQueryOptions = watchQueryOptions;
126
201
  if (currentWatchQueryOptions && this.observable) {
202
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
127
203
  this.observable.reobserve(watchQueryOptions);
128
204
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
129
205
  this.result = void 0;
@@ -132,7 +208,8 @@ var InternalState = (function () {
132
208
  this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
133
209
  this.onError = options.onError || InternalState.prototype.onError;
134
210
  if ((this.renderPromises || this.client.disableNetworkFetches) &&
135
- this.queryHookOptions.ssr === false) {
211
+ this.queryHookOptions.ssr === false &&
212
+ !this.queryHookOptions.skip) {
136
213
  this.result = this.ssrDisabledResult;
137
214
  }
138
215
  else if (this.queryHookOptions.skip ||
@@ -145,51 +222,38 @@ var InternalState = (function () {
145
222
  }
146
223
  };
147
224
  InternalState.prototype.createWatchQueryOptions = function (_a) {
225
+ var _b;
148
226
  if (_a === void 0) { _a = {}; }
149
- var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
150
- var toMerge = [];
151
- var globalDefaults = this.client.defaultOptions.watchQuery;
152
- if (globalDefaults)
153
- toMerge.push(globalDefaults);
154
- if (defaultOptions)
155
- toMerge.push(defaultOptions);
156
- var latestOptions = this.observable && this.observable.options;
157
- if (latestOptions && toMerge.length) {
158
- var defaults_1 = toMerge.reduce(core.mergeOptions, Object.create(null));
159
- toMerge.length = 1;
160
- toMerge[0] = defaults_1;
161
- Object.keys(defaults_1).forEach(function (defaultOptionName) {
162
- var currentOptionValue = latestOptions[defaultOptionName];
163
- if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
164
- !equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
165
- defaults_1[defaultOptionName] = defaultOptionName === "variables"
166
- ? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
167
- }
168
- });
169
- }
170
- toMerge.push(otherOptions);
171
- var merged = toMerge.reduce(core.mergeOptions, Object.create(null));
172
- var watchQueryOptions = Object.assign(merged, { query: this.query });
227
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
228
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
173
229
  if (this.renderPromises &&
174
230
  (watchQueryOptions.fetchPolicy === 'network-only' ||
175
231
  watchQueryOptions.fetchPolicy === 'cache-and-network')) {
176
232
  watchQueryOptions.fetchPolicy = 'cache-first';
177
233
  }
178
- else if (!watchQueryOptions.fetchPolicy) {
179
- watchQueryOptions.fetchPolicy = 'cache-first';
234
+ if (!watchQueryOptions.variables) {
235
+ watchQueryOptions.variables = {};
180
236
  }
181
237
  if (skip) {
182
- var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
238
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
183
239
  Object.assign(watchQueryOptions, {
184
240
  initialFetchPolicy: initialFetchPolicy,
185
241
  fetchPolicy: 'standby',
186
242
  });
187
243
  }
188
- if (!watchQueryOptions.variables) {
189
- watchQueryOptions.variables = {};
244
+ else if (!watchQueryOptions.fetchPolicy) {
245
+ watchQueryOptions.fetchPolicy =
246
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
247
+ this.getDefaultFetchPolicy();
190
248
  }
191
249
  return watchQueryOptions;
192
250
  };
251
+ InternalState.prototype.getDefaultFetchPolicy = function () {
252
+ var _a, _b;
253
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
254
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
255
+ "cache-first");
256
+ };
193
257
  InternalState.prototype.onCompleted = function (data) { };
194
258
  InternalState.prototype.onError = function (error) { };
195
259
  InternalState.prototype.useObservableQuery = function () {
@@ -197,8 +261,8 @@ var InternalState = (function () {
197
261
  this.renderPromises
198
262
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
199
263
  || this.observable
200
- || this.client.watchQuery(tslib.__assign({}, this.watchQueryOptions));
201
- this.obsQueryFields = react.useMemo(function () { return ({
264
+ || this.client.watchQuery(core.mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
265
+ this.obsQueryFields = React.useMemo(function () { return ({
202
266
  refetch: obsQuery.refetch.bind(obsQuery),
203
267
  reobserve: obsQuery.reobserve.bind(obsQuery),
204
268
  fetchMore: obsQuery.fetchMore.bind(obsQuery),
@@ -207,11 +271,11 @@ var InternalState = (function () {
207
271
  stopPolling: obsQuery.stopPolling.bind(obsQuery),
208
272
  subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
209
273
  }); }, [obsQuery]);
210
- if (this.renderPromises) {
274
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
275
+ this.queryHookOptions.skip);
276
+ if (this.renderPromises && ssrAllowed) {
211
277
  this.renderPromises.registerSSRObservable(obsQuery);
212
- var ssrAllowed = !(this.queryHookOptions.ssr === false ||
213
- this.queryHookOptions.skip);
214
- if (ssrAllowed && obsQuery.getCurrentResult().loading) {
278
+ if (obsQuery.getCurrentResult().loading) {
215
279
  this.renderPromises.addObservableQueryPromise(obsQuery);
216
280
  }
217
281
  }
@@ -279,17 +343,14 @@ var EAGER_METHODS = [
279
343
  ];
280
344
  function useLazyQuery(query, options) {
281
345
  var internalState = useInternalState(useApolloClient(options && options.client), query);
282
- var execOptionsRef = react.useRef();
283
- var defaultOptions = internalState.client.defaultOptions.watchQuery;
284
- var initialFetchPolicy = (options && options.fetchPolicy) ||
285
- (execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
286
- (defaultOptions && defaultOptions.fetchPolicy) ||
287
- "cache-first";
346
+ var execOptionsRef = React.useRef();
288
347
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
348
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
349
+ internalState.getDefaultFetchPolicy();
289
350
  var result = Object.assign(useQueryResult, {
290
351
  called: !!execOptionsRef.current,
291
352
  });
292
- var eagerMethods = react.useMemo(function () {
353
+ var eagerMethods = React.useMemo(function () {
293
354
  var eagerMethods = {};
294
355
  var _loop_1 = function (key) {
295
356
  var method = result[key];
@@ -308,23 +369,13 @@ function useLazyQuery(query, options) {
308
369
  return eagerMethods;
309
370
  }, []);
310
371
  Object.assign(result, eagerMethods);
311
- var execute = react.useCallback(function (executeOptions) {
312
- var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
372
+ var execute = React.useCallback(function (executeOptions) {
373
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
313
374
  fetchPolicy: initialFetchPolicy,
314
- }).then(function (apolloQueryResult) {
315
- apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
316
- if (apolloQueryResult.error ||
317
- utilities.isNonEmptyArray(apolloQueryResult.errors)) {
318
- var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
319
- if (errorPolicy === "none") {
320
- throw apolloQueryResult.error || new errors.ApolloError({
321
- graphQLErrors: apolloQueryResult.errors,
322
- });
323
- }
324
- }
325
- return internalState.toQueryResult(apolloQueryResult);
326
- }).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
327
- internalState.forceUpdate();
375
+ };
376
+ var promise = internalState
377
+ .asyncUpdate()
378
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
328
379
  promise.catch(function () { });
329
380
  return promise;
330
381
  }, []);
@@ -334,12 +385,12 @@ function useLazyQuery(query, options) {
334
385
  function useMutation(mutation, options) {
335
386
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
336
387
  parser.verifyDocumentType(mutation, parser.DocumentType.Mutation);
337
- var _a = react.useState({
388
+ var _a = React.useState({
338
389
  called: false,
339
390
  loading: false,
340
391
  client: client,
341
392
  }), result = _a[0], setResult = _a[1];
342
- var ref = react.useRef({
393
+ var ref = React.useRef({
343
394
  result: result,
344
395
  mutationId: 0,
345
396
  isMounted: true,
@@ -350,7 +401,7 @@ function useMutation(mutation, options) {
350
401
  {
351
402
  Object.assign(ref.current, { client: client, options: options, mutation: mutation });
352
403
  }
353
- var execute = react.useCallback(function (executeOptions) {
404
+ var execute = React.useCallback(function (executeOptions) {
354
405
  if (executeOptions === void 0) { executeOptions = {}; }
355
406
  var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
356
407
  var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
@@ -410,10 +461,10 @@ function useMutation(mutation, options) {
410
461
  throw error;
411
462
  });
412
463
  }, []);
413
- var reset = react.useCallback(function () {
464
+ var reset = React.useCallback(function () {
414
465
  setResult({ called: false, loading: false, client: client });
415
466
  }, []);
416
- react.useEffect(function () {
467
+ React.useEffect(function () {
417
468
  ref.current.isMounted = true;
418
469
  return function () {
419
470
  ref.current.isMounted = false;
@@ -425,13 +476,13 @@ function useMutation(mutation, options) {
425
476
  function useSubscription(subscription, options) {
426
477
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
427
478
  parser.verifyDocumentType(subscription, parser.DocumentType.Subscription);
428
- var _a = react.useState({
479
+ var _a = React.useState({
429
480
  loading: !(options === null || options === void 0 ? void 0 : options.skip),
430
481
  error: void 0,
431
482
  data: void 0,
432
483
  variables: options === null || options === void 0 ? void 0 : options.variables,
433
484
  }), result = _a[0], setResult = _a[1];
434
- var _b = react.useState(function () {
485
+ var _b = React.useState(function () {
435
486
  if (options === null || options === void 0 ? void 0 : options.skip) {
436
487
  return null;
437
488
  }
@@ -442,15 +493,21 @@ function useSubscription(subscription, options) {
442
493
  context: options === null || options === void 0 ? void 0 : options.context,
443
494
  });
444
495
  }), observable = _b[0], setObservable = _b[1];
445
- var ref = react.useRef({ client: client, subscription: subscription, options: options });
446
- react.useEffect(function () {
496
+ var canResetObservableRef = React.useRef(false);
497
+ React.useEffect(function () {
498
+ return function () {
499
+ canResetObservableRef.current = true;
500
+ };
501
+ }, []);
502
+ var ref = React.useRef({ client: client, subscription: subscription, options: options });
503
+ React.useEffect(function () {
447
504
  var _a, _b, _c, _d;
448
505
  var shouldResubscribe = options === null || options === void 0 ? void 0 : options.shouldResubscribe;
449
506
  if (typeof shouldResubscribe === 'function') {
450
507
  shouldResubscribe = !!shouldResubscribe(options);
451
508
  }
452
509
  if (options === null || options === void 0 ? void 0 : options.skip) {
453
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
510
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
454
511
  setResult({
455
512
  loading: false,
456
513
  data: void 0,
@@ -458,13 +515,16 @@ function useSubscription(subscription, options) {
458
515
  variables: options === null || options === void 0 ? void 0 : options.variables,
459
516
  });
460
517
  setObservable(null);
518
+ canResetObservableRef.current = false;
461
519
  }
462
520
  }
463
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
464
- subscription !== ref.current.subscription ||
465
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
466
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
467
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
521
+ else if ((shouldResubscribe !== false &&
522
+ (client !== ref.current.client ||
523
+ subscription !== ref.current.subscription ||
524
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
525
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
526
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
527
+ canResetObservableRef.current) {
468
528
  setResult({
469
529
  loading: true,
470
530
  data: void 0,
@@ -477,10 +537,11 @@ function useSubscription(subscription, options) {
477
537
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
478
538
  context: options === null || options === void 0 ? void 0 : options.context,
479
539
  }));
540
+ canResetObservableRef.current = false;
480
541
  }
481
542
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
482
- }, [client, subscription, options]);
483
- react.useEffect(function () {
543
+ }, [client, subscription, options, canResetObservableRef.current]);
544
+ React.useEffect(function () {
484
545
  if (!observable) {
485
546
  return;
486
547
  }
@@ -521,8 +582,8 @@ function useSubscription(subscription, options) {
521
582
 
522
583
  function useReactiveVar(rv) {
523
584
  var value = rv();
524
- var setValue = react.useState(value)[1];
525
- react.useEffect(function () {
585
+ var setValue = React.useState(value)[1];
586
+ React.useEffect(function () {
526
587
  var probablySameValue = rv();
527
588
  if (value !== probablySameValue) {
528
589
  setValue(probablySameValue);