@apollo/client 3.9.9 → 3.9.10

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 (37) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/apollo-client.cjs +33 -13
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +8 -6
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +8 -6
  8. package/cache/inmemory/readFromStore.js +8 -6
  9. package/cache/inmemory/readFromStore.js.map +1 -1
  10. package/core/core.cjs +1 -1
  11. package/core/core.cjs.map +1 -1
  12. package/core/core.cjs.native.js +1 -1
  13. package/dev/dev.cjs +1 -1
  14. package/dev/dev.cjs.map +1 -1
  15. package/dev/dev.cjs.native.js +1 -1
  16. package/package.json +16 -16
  17. package/react/hooks/hooks.cjs +17 -1
  18. package/react/hooks/hooks.cjs.map +1 -1
  19. package/react/hooks/hooks.cjs.native.js +17 -1
  20. package/react/hooks/useBackgroundQuery.js +13 -0
  21. package/react/hooks/useBackgroundQuery.js.map +1 -1
  22. package/react/hooks/useReadQuery.js +10 -1
  23. package/react/hooks/useReadQuery.js.map +1 -1
  24. package/react/hooks/useSuspenseQuery.js +27 -0
  25. package/react/hooks/useSuspenseQuery.js.map +1 -1
  26. package/react/internal/cache/QueryReference.js +3 -6
  27. package/react/internal/cache/QueryReference.js.map +1 -1
  28. package/react/internal/cache/SuspenseCache.d.ts +1 -0
  29. package/react/internal/cache/SuspenseCache.js +4 -0
  30. package/react/internal/cache/SuspenseCache.js.map +1 -1
  31. package/react/internal/internal.cjs +7 -5
  32. package/react/internal/internal.cjs.map +1 -1
  33. package/react/internal/internal.cjs.native.js +7 -5
  34. package/utilities/globals/globals.cjs +1 -1
  35. package/utilities/globals/globals.cjs.map +1 -1
  36. package/utilities/globals/globals.cjs.native.js +1 -1
  37. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.9.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#11738](https://github.com/apollographql/apollo-client/pull/11738) [`b1a5eb8`](https://github.com/apollographql/apollo-client/commit/b1a5eb80cae8bdf2e9d8627f1eab65e088c43438) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix an issue where rerendering `useBackgroundQuery` after the `queryRef` had been disposed, either via the auto dispose timeout or by unmounting `useReadQuery`, would cause the `queryRef` to be recreated potentially resulting in another network request.
8
+
9
+ - [#11738](https://github.com/apollographql/apollo-client/pull/11738) [`b1a5eb8`](https://github.com/apollographql/apollo-client/commit/b1a5eb80cae8bdf2e9d8627f1eab65e088c43438) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Allow queryRefs to be disposed of synchronously when a suspense hook unmounts. This prevents some situations where using a suspense hook with the same query/variables as the disposed queryRef accidentally used the disposed queryRef rather than creating a new instance.
10
+
11
+ - [#11670](https://github.com/apollographql/apollo-client/pull/11670) [`cc5c03b`](https://github.com/apollographql/apollo-client/commit/cc5c03b2690f452483d83eecb68611a23055d99e) Thanks [@phryneas](https://github.com/phryneas)! - Bail out of `executeSubSelectedArray` calls if the array has 0 elements.
12
+
3
13
  ## 3.9.9
4
14
 
5
15
  ### Patch Changes
package/apollo-client.cjs CHANGED
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
33
 
34
- var version = "3.9.9";
34
+ var version = "3.9.10";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -3318,12 +3318,14 @@ var StoreReader = (function () {
3318
3318
  }
3319
3319
  }
3320
3320
  else if (isArray(fieldValue)) {
3321
- fieldValue = handleMissing(_this.executeSubSelectedArray({
3322
- field: selection,
3323
- array: fieldValue,
3324
- enclosingRef: enclosingRef,
3325
- context: context,
3326
- }), resultName);
3321
+ if (fieldValue.length > 0) {
3322
+ fieldValue = handleMissing(_this.executeSubSelectedArray({
3323
+ field: selection,
3324
+ array: fieldValue,
3325
+ enclosingRef: enclosingRef,
3326
+ context: context,
3327
+ }), resultName);
3328
+ }
3327
3329
  }
3328
3330
  else if (!selection.selectionSet) {
3329
3331
  if (context.canonizeResults) {
@@ -8183,11 +8185,9 @@ var InternalQueryReference = (function () {
8183
8185
  }
8184
8186
  disposed = true;
8185
8187
  _this.references--;
8186
- setTimeout(function () {
8187
- if (!_this.references) {
8188
- _this.dispose();
8189
- }
8190
- });
8188
+ if (!_this.references) {
8189
+ _this.dispose();
8190
+ }
8191
8191
  };
8192
8192
  };
8193
8193
  InternalQueryReference.prototype.softRetain = function () {
@@ -8355,6 +8355,10 @@ var SuspenseCache = (function () {
8355
8355
  }
8356
8356
  return ref.current;
8357
8357
  };
8358
+ SuspenseCache.prototype.add = function (cacheKey, queryRef) {
8359
+ var ref = this.queryRefs.lookupArray(cacheKey);
8360
+ ref.current = queryRef;
8361
+ };
8358
8362
  return SuspenseCache;
8359
8363
  }());
8360
8364
 
@@ -8409,6 +8413,12 @@ function _useSuspenseQuery(query, options) {
8409
8413
  dispose();
8410
8414
  };
8411
8415
  }, [queryRef]);
8416
+ React__namespace.useEffect(function () {
8417
+ if (queryRef.disposed) {
8418
+ suspenseCache.add(cacheKey, queryRef);
8419
+ queryRef.reinitialize();
8420
+ }
8421
+ });
8412
8422
  var skipResult = React__namespace.useMemo(function () {
8413
8423
  var error = toApolloError(queryRef.result);
8414
8424
  return {
@@ -8516,6 +8526,11 @@ function _useBackgroundQuery(query, options) {
8516
8526
  var promise = queryRef.applyOptions(watchQueryOptions);
8517
8527
  updateWrappedQueryRef(wrappedQueryRef, promise);
8518
8528
  }
8529
+ React__namespace.useEffect(function () {
8530
+ if (queryRef.disposed) {
8531
+ suspenseCache.add(cacheKey, queryRef);
8532
+ }
8533
+ });
8519
8534
  var fetchMore = React__namespace.useCallback(function (options) {
8520
8535
  var promise = queryRef.fetchMore(options);
8521
8536
  setWrappedQueryRef(wrapQueryRef(queryRef));
@@ -8618,7 +8633,12 @@ function _useReadQuery(queryRef) {
8618
8633
  internalQueryRef.reinitialize();
8619
8634
  updateWrappedQueryRef(queryRef, internalQueryRef.promise);
8620
8635
  }
8621
- React__namespace.useEffect(function () { return internalQueryRef.retain(); }, [internalQueryRef]);
8636
+ React__namespace.useEffect(function () {
8637
+ if (internalQueryRef.disposed) {
8638
+ internalQueryRef.reinitialize();
8639
+ }
8640
+ return internalQueryRef.retain();
8641
+ }, [internalQueryRef]);
8622
8642
  var promise = useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
8623
8643
  return internalQueryRef.listen(function (promise) {
8624
8644
  updateWrappedQueryRef(queryRef, promise);