@khanacademy/wonder-blocks-data 8.0.1 → 8.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @khanacademy/wonder-blocks-data
2
2
 
3
+ ## 8.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - dc2e00f4: Do not fetch if FetchPolicy is CacheBeforeNetwork and there is already a cached value, even if the requestId changes
8
+
9
+ ## 8.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 5f4a4297: Make dependency on `flow-enums-runtime` explicit
14
+ - 2b96fd59: Change flow-enums-runtime to be peer dependencies
15
+ - Updated dependencies [5f4a4297]
16
+ - Updated dependencies [2b96fd59]
17
+ - @khanacademy/wonder-blocks-core@4.3.2
18
+
19
+ ## 8.0.2
20
+
21
+ ### Patch Changes
22
+
23
+ - 580141ed: Always initialize SSR-only cache
24
+
3
25
  ## 8.0.1
4
26
 
5
27
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -172,11 +172,10 @@ class SsrCache {
172
172
  };
173
173
 
174
174
  this.getEntry = id => {
175
- var _this$_ssrOnlyCache$g, _this$_ssrOnlyCache;
175
+ const ssrEntry = Server.isServerSide() ? this._ssrOnlyCache.get(DefaultScope$2, id) : null;
176
+ const internalEntry = ssrEntry != null ? ssrEntry : this._hydrationCache.get(DefaultScope$2, id);
176
177
 
177
- const internalEntry = (_this$_ssrOnlyCache$g = (_this$_ssrOnlyCache = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache.get(DefaultScope$2, id)) != null ? _this$_ssrOnlyCache$g : this._hydrationCache.get(DefaultScope$2, id);
178
-
179
- if (this._ssrOnlyCache == null && internalEntry != null) {
178
+ if (!Server.isServerSide() && internalEntry != null) {
180
179
  this._hydrationCache.purge(DefaultScope$2, id);
181
180
  }
182
181
 
@@ -184,13 +183,11 @@ class SsrCache {
184
183
  };
185
184
 
186
185
  this.purgeData = predicate => {
187
- var _this$_ssrOnlyCache2;
188
-
189
186
  const realPredicate = predicate ? (_, key, cachedEntry) => predicate(key, cachedEntry) : undefined;
190
187
 
191
188
  this._hydrationCache.purgeAll(realPredicate);
192
189
 
193
- (_this$_ssrOnlyCache2 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache2.purgeAll(realPredicate);
190
+ this._ssrOnlyCache.purgeAll(realPredicate);
194
191
  };
195
192
 
196
193
  this.cloneHydratableData = () => {
@@ -201,7 +198,7 @@ class SsrCache {
201
198
  return (_cache$DefaultScope = cache[DefaultScope$2]) != null ? _cache$DefaultScope : {};
202
199
  };
203
200
 
204
- this._ssrOnlyCache = process.env.NODE_ENV === "test" || Server.isServerSide() ? ssrOnlyCache || new SerializableInMemoryCache() : undefined;
201
+ this._ssrOnlyCache = ssrOnlyCache || new SerializableInMemoryCache();
205
202
  this._hydrationCache = hydrationCache || new SerializableInMemoryCache();
206
203
  }
207
204
 
@@ -212,9 +209,7 @@ class SsrCache {
212
209
  if (hydrate) {
213
210
  this._hydrationCache.set(DefaultScope$2, id, frozenEntry);
214
211
  } else {
215
- var _this$_ssrOnlyCache3;
216
-
217
- (_this$_ssrOnlyCache3 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache3.set(DefaultScope$2, id, frozenEntry);
212
+ this._ssrOnlyCache.set(DefaultScope$2, id, frozenEntry);
218
213
  }
219
214
  }
220
215
 
@@ -590,7 +585,6 @@ const useCachedEffect = (requestId, handler, options = {}) => {
590
585
 
591
586
  return fetchFn;
592
587
  }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]);
593
- const requestIdRef = React.useRef(requestId);
594
588
  const shouldFetch = React.useMemo(() => {
595
589
  if (hardSkip) {
596
590
  return false;
@@ -601,14 +595,13 @@ const useCachedEffect = (requestId, handler, options = {}) => {
601
595
  return false;
602
596
 
603
597
  case FetchPolicy.CacheBeforeNetwork:
604
- return mostRecentResult == null || requestId !== requestIdRef.current;
598
+ return mostRecentResult == null;
605
599
 
606
600
  case FetchPolicy.CacheAndNetwork:
607
601
  case FetchPolicy.NetworkOnly:
608
602
  return networkResultRef.current == null;
609
603
  }
610
- }, [requestId, mostRecentResult, fetchPolicy, hardSkip]);
611
- requestIdRef.current = requestId;
604
+ }, [mostRecentResult, fetchPolicy, hardSkip]);
612
605
  React.useEffect(() => {
613
606
  if (!shouldFetch) {
614
607
  return;
package/dist/index.js CHANGED
@@ -165,21 +165,20 @@ module.exports = require("react");
165
165
 
166
166
  /***/ }),
167
167
  /* 2 */
168
+ /***/ (function(module, exports) {
169
+
170
+ module.exports = require("@khanacademy/wonder-blocks-core");
171
+
172
+ /***/ }),
173
+ /* 3 */
168
174
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
169
175
 
170
176
  "use strict";
171
177
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FetchPolicy; });
172
- // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
173
- // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
174
-
175
- /* eslint-disable no-undef */
176
-
177
178
  /**
178
179
  * Defines the various fetch policies that can be applied to requests.
179
180
  */
180
181
  const FetchPolicy = __webpack_require__(22).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
181
- /* eslint-enable no-undef */
182
-
183
182
  /**
184
183
  * Define what can be cached.
185
184
  *
@@ -187,12 +186,6 @@ const FetchPolicy = __webpack_require__(22).Mirrored(["CacheBeforeNetwork", "Cac
187
186
  * and functions are not allowed.
188
187
  */
189
188
 
190
- /***/ }),
191
- /* 3 */
192
- /***/ (function(module, exports) {
193
-
194
- module.exports = require("@khanacademy/wonder-blocks-core");
195
-
196
189
  /***/ }),
197
190
  /* 4 */
198
191
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
@@ -556,7 +549,7 @@ class RequestTracker {
556
549
 
557
550
  "use strict";
558
551
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SsrCache; });
559
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
552
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
560
553
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
561
554
  /* harmony import */ var _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13);
562
555
 
@@ -608,14 +601,14 @@ class SsrCache {
608
601
  };
609
602
 
610
603
  this.getEntry = id => {
611
- var _this$_ssrOnlyCache$g, _this$_ssrOnlyCache;
612
-
613
604
  // Get the cached entry for this value.
614
- // We first look in the ssr cache and then the hydration cache.
615
- const internalEntry = (_this$_ssrOnlyCache$g = (_this$_ssrOnlyCache = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache.get(DefaultScope, id)) != null ? _this$_ssrOnlyCache$g : this._hydrationCache.get(DefaultScope, id); // If we are not server-side and we hydrated something, let's clear
605
+ // We first look in the ssr cache, if we need to.
606
+ const ssrEntry = _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() ? this._ssrOnlyCache.get(DefaultScope, id) : null; // Now we defer to the SSR value, and fallback to the hydration cache.
607
+
608
+ const internalEntry = ssrEntry != null ? ssrEntry : this._hydrationCache.get(DefaultScope, id); // If we are not server-side and we hydrated something, let's clear
616
609
  // that from the hydration cache to save memory.
617
610
 
618
- if (this._ssrOnlyCache == null && internalEntry != null) {
611
+ if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() && internalEntry != null) {
619
612
  // We now delete this from our hydration cache as we don't need it.
620
613
  // This does mean that if another handler of the same type but
621
614
  // without some sort of linked cache won't get the value, but
@@ -632,8 +625,6 @@ class SsrCache {
632
625
  };
633
626
 
634
627
  this.purgeData = predicate => {
635
- var _this$_ssrOnlyCache2;
636
-
637
628
  const realPredicate = predicate ? // We know what we're putting into the cache so let's assume it
638
629
  // conforms.
639
630
  // $FlowIgnore[incompatible-call]
@@ -641,7 +632,7 @@ class SsrCache {
641
632
 
642
633
  this._hydrationCache.purgeAll(realPredicate);
643
634
 
644
- (_this$_ssrOnlyCache2 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache2.purgeAll(realPredicate);
635
+ this._ssrOnlyCache.purgeAll(realPredicate);
645
636
  };
646
637
 
647
638
  this.cloneHydratableData = () => {
@@ -658,13 +649,7 @@ class SsrCache {
658
649
  return (_cache$DefaultScope = cache[DefaultScope]) != null ? _cache$DefaultScope : {};
659
650
  };
660
651
 
661
- // The default instance gets made on first reference and if that happens
662
- // before server-side mode is turned on, the Default instance would
663
- // never have an SSR-only cache instance, which would then mean that if
664
- // server-side mode got turned on, it wouldn't work right.
665
- // This should only be an issue of surprise during testing, so, let's
666
- // always have an instance in that circumstance.
667
- this._ssrOnlyCache = false || _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() ? ssrOnlyCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]() : undefined;
652
+ this._ssrOnlyCache = ssrOnlyCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
668
653
  this._hydrationCache = hydrationCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
669
654
  }
670
655
 
@@ -677,12 +662,10 @@ class SsrCache {
677
662
  if (hydrate) {
678
663
  this._hydrationCache.set(DefaultScope, id, frozenEntry);
679
664
  } else {
680
- var _this$_ssrOnlyCache3;
681
-
682
665
  // Usually, when server-side, this cache will always be present.
683
666
  // We do fake server-side in our doc example though, when it
684
667
  // won't be.
685
- (_this$_ssrOnlyCache3 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache3.set(DefaultScope, id, frozenEntry);
668
+ this._ssrOnlyCache.set(DefaultScope, id, frozenEntry);
686
669
  }
687
670
  }
688
671
 
@@ -927,7 +910,7 @@ class ScopedInMemoryCache {
927
910
  /* harmony import */ var _use_server_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(16);
928
911
  /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5);
929
912
  /* harmony import */ var _use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(17);
930
- /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2);
913
+ /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(3);
931
914
 
932
915
 
933
916
 
@@ -1129,7 +1112,7 @@ const purgeHydrationCache = predicate => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_
1129
1112
 
1130
1113
  "use strict";
1131
1114
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useServerEffect; });
1132
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
1115
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1133
1116
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1134
1117
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
1135
1118
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
@@ -1194,14 +1177,14 @@ const useServerEffect = (requestId, handler, options = {}) => {
1194
1177
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useCachedEffect; });
1195
1178
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1196
1179
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1197
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
1180
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1198
1181
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
1199
1182
  /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(0);
1200
1183
  /* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
1201
1184
  /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
1202
1185
  /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(5);
1203
1186
  /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(19);
1204
- /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(2);
1187
+ /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(3);
1205
1188
 
1206
1189
 
1207
1190
 
@@ -1353,10 +1336,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1353
1336
  // really make sense - the same requestId should be handled the same as
1354
1337
  // each other.
1355
1338
  // eslint-disable-next-line react-hooks/exhaustive-deps
1356
- }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // We need to trigger a re-render when the request ID changes as that
1357
- // indicates its a different request.
1358
-
1359
- const requestIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](requestId); // Calculate if we want to fetch the result or not.
1339
+ }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // Calculate if we want to fetch the result or not.
1360
1340
  // If this is true, we will do a new fetch, cancelling the previous fetch
1361
1341
  // if there is one inflight.
1362
1342
 
@@ -1373,9 +1353,8 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1373
1353
  return false;
1374
1354
 
1375
1355
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork:
1376
- // If we don't have a cached value or this is a new requestId,
1377
- // then we need to fetch.
1378
- return mostRecentResult == null || requestId !== requestIdRef.current;
1356
+ // If we don't have a cached value then we need to fetch.
1357
+ return mostRecentResult == null;
1379
1358
 
1380
1359
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheAndNetwork:
1381
1360
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly:
@@ -1383,9 +1362,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1383
1362
  // result, then we need to fetch one.
1384
1363
  return networkResultRef.current == null;
1385
1364
  }
1386
- }, [requestId, mostRecentResult, fetchPolicy, hardSkip]); // Let's make sure our ref is set to the most recent requestId.
1387
-
1388
- requestIdRef.current = requestId;
1365
+ }, [mostRecentResult, fetchPolicy, hardSkip]);
1389
1366
  react__WEBPACK_IMPORTED_MODULE_0__["useEffect"](() => {
1390
1367
  if (!shouldFetch) {
1391
1368
  return;
@@ -1590,125 +1567,9 @@ const mergeGqlContext = (defaultContext, overrides) => {
1590
1567
 
1591
1568
  /***/ }),
1592
1569
  /* 22 */
1593
- /***/ (function(module, exports, __webpack_require__) {
1594
-
1595
- "use strict";
1596
- /**
1597
- * Copyright (c) Facebook, Inc. and its affiliates.
1598
- *
1599
- * This source code is licensed under the MIT license found in the
1600
- * LICENSE file in the root directory of this source tree.
1601
- */
1602
-
1603
-
1604
-
1605
- // Below we want to use `hasOwnProperty` on an object that doesn't have
1606
- // `Object.prototype` in its proto chain, so we must extract it here.
1607
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1608
-
1609
- // Map from an enum object to a reverse map of its values to names
1610
- var reverseMapCache = typeof WeakMap === 'function' ? new WeakMap() : new Map();
1611
-
1612
- // Computes the reverse mapping of the enum object: from value to name.
1613
- // Flow Enum values are unique (enforced by the parser), so this is a
1614
- // one to one mapping.
1615
- function getReverseMap(enumObject) {
1616
- var reverseMap = reverseMapCache.get(enumObject);
1617
- if (reverseMap !== undefined) {
1618
- return reverseMap;
1619
- }
1620
- // We aren't using `Object.values` because that gets enumerable
1621
- // properties, and our properties aren't enumerable.
1622
- var newReverseMap = new Map();
1623
- Object.getOwnPropertyNames(enumObject).forEach(function (name) {
1624
- newReverseMap.set(enumObject[name], name);
1625
- });
1626
- reverseMapCache.set(enumObject, newReverseMap);
1627
- return newReverseMap;
1628
- }
1629
-
1630
- var EnumPrototype = Object.freeze(
1631
- Object.defineProperties(Object.create(null), {
1632
- isValid: {
1633
- value: function (x) {
1634
- return getReverseMap(this).has(x);
1635
- },
1636
- },
1637
- cast: {
1638
- value: function (x) {
1639
- return this.isValid(x) ? x : undefined;
1640
- },
1641
- },
1642
- members: {
1643
- value: function () {
1644
- return getReverseMap(this).keys();
1645
- },
1646
- },
1647
- getName: {
1648
- value: function (value) {
1649
- return getReverseMap(this).get(value);
1650
- }
1651
- }
1652
- })
1653
- );
1654
-
1655
- // `members` is an object mapping name to value.
1656
- function Enum(members) {
1657
- var o = Object.create(EnumPrototype);
1658
- for (var k in members) {
1659
- if (hasOwnProperty.call(members, k)) {
1660
- // Create non-enumerable properties.
1661
- Object.defineProperty(o, k, {value: members[k]});
1662
- }
1663
- }
1664
- return Object.freeze(o);
1665
- }
1666
-
1667
- // Mirrored enum (string enum with no member initializers).
1668
- // Optimized implementation, taking advantage of the fact that
1669
- // keys and values are identical.
1670
- var EnumMirroredPrototype = Object.freeze(
1671
- Object.defineProperties(Object.create(null), {
1672
- isValid: {
1673
- value: function (x) {
1674
- if (typeof x === 'string') {
1675
- return hasOwnProperty.call(this, x);
1676
- }
1677
- return false;
1678
- },
1679
- },
1680
- cast: {
1681
- value: EnumPrototype.cast,
1682
- },
1683
- members: {
1684
- value: function () {
1685
- // We aren't using `Object.values` because that gets enumerable
1686
- // properties, and our properties aren't enumerable.
1687
- return Object.getOwnPropertyNames(this).values();
1688
- },
1689
- },
1690
- getName: {
1691
- value: function (value) {
1692
- return value;
1693
- }
1694
- }
1695
- })
1696
- );
1697
-
1698
- // `members` is an array of names (which, are also the values).
1699
- Enum.Mirrored = function EnumMirrored(members) {
1700
- var o = Object.create(EnumMirroredPrototype);
1701
- for (var i = 0, len = members.length; i < len; ++i) {
1702
- // Value is same as key. Also, non-enumerable.
1703
- Object.defineProperty(o, members[i], {value: members[i]});
1704
- }
1705
- return Object.freeze(o);
1706
- };
1707
-
1708
- Object.freeze(Enum.Mirrored);
1709
-
1710
- module.exports = Object.freeze(Enum);
1570
+ /***/ (function(module, exports) {
1711
1571
 
1572
+ module.exports = require("flow-enums-runtime");
1712
1573
 
1713
1574
  /***/ }),
1714
1575
  /* 23 */
@@ -1718,7 +1579,7 @@ module.exports = Object.freeze(Enum);
1718
1579
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return fetchTrackedRequests; });
1719
1580
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return hasTrackedRequestsToBeFetched; });
1720
1581
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return abortInflightRequests; });
1721
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
1582
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1722
1583
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1723
1584
  /* harmony import */ var _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
1724
1585
  /* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
@@ -1818,7 +1679,7 @@ const purgeCaches = () => {
1818
1679
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return TrackData; });
1819
1680
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1820
1681
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1821
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
1682
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1822
1683
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
1823
1684
  /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1824
1685
 
@@ -2272,7 +2133,7 @@ const getGqlDataFromResponse = async response => {
2272
2133
 
2273
2134
  "use strict";
2274
2135
  __webpack_require__.r(__webpack_exports__);
2275
- /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
2136
+ /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
2276
2137
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FetchPolicy", function() { return _util_types_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
2277
2138
 
2278
2139
  /* harmony import */ var _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-data",
3
- "version": "8.0.1",
3
+ "version": "8.0.4",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,11 +13,12 @@
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
15
15
  "dependencies": {
16
- "@babel/runtime": "^7.16.3",
17
- "@khanacademy/wonder-blocks-core": "^4.3.1"
16
+ "@babel/runtime": "^7.18.6",
17
+ "@khanacademy/wonder-blocks-core": "^4.3.2"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@khanacademy/wonder-stuff-core": "^0.1.2",
21
+ "flow-enums-runtime": "^0.0.6",
21
22
  "react": "16.14.0"
22
23
  },
23
24
  "devDependencies": {
@@ -232,10 +232,6 @@ export const useCachedEffect = <TData: ValidCacheData>(
232
232
  fetchPolicy,
233
233
  ]);
234
234
 
235
- // We need to trigger a re-render when the request ID changes as that
236
- // indicates its a different request.
237
- const requestIdRef = React.useRef(requestId);
238
-
239
235
  // Calculate if we want to fetch the result or not.
240
236
  // If this is true, we will do a new fetch, cancelling the previous fetch
241
237
  // if there is one inflight.
@@ -252,12 +248,8 @@ export const useCachedEffect = <TData: ValidCacheData>(
252
248
  return false;
253
249
 
254
250
  case FetchPolicy.CacheBeforeNetwork:
255
- // If we don't have a cached value or this is a new requestId,
256
- // then we need to fetch.
257
- return (
258
- mostRecentResult == null ||
259
- requestId !== requestIdRef.current
260
- );
251
+ // If we don't have a cached value then we need to fetch.
252
+ return mostRecentResult == null;
261
253
 
262
254
  case FetchPolicy.CacheAndNetwork:
263
255
  case FetchPolicy.NetworkOnly:
@@ -265,10 +257,7 @@ export const useCachedEffect = <TData: ValidCacheData>(
265
257
  // result, then we need to fetch one.
266
258
  return networkResultRef.current == null;
267
259
  }
268
- }, [requestId, mostRecentResult, fetchPolicy, hardSkip]);
269
-
270
- // Let's make sure our ref is set to the most recent requestId.
271
- requestIdRef.current = requestId;
260
+ }, [mostRecentResult, fetchPolicy, hardSkip]);
272
261
 
273
262
  React.useEffect(() => {
274
263
  if (!shouldFetch) {
@@ -16,9 +16,6 @@ import type {Result, ValidCacheData} from "../util/types.js";
16
16
  * Policies to define how a hydratable effect should behave client-side.
17
17
  */
18
18
  export enum WhenClientSide {
19
- // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
20
- // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
21
- /* eslint-disable no-undef */
22
19
  /**
23
20
  * The result from executing the effect server-side will not be hydrated.
24
21
  * The effect will always be executed client-side.
@@ -52,7 +49,6 @@ export enum WhenClientSide {
52
49
  * hydrated result status.
53
50
  */
54
51
  AlwaysExecute,
55
- /* eslint-enable no-undef */
56
52
  }
57
53
 
58
54
  type HydratableEffectOptions<TData: ValidCacheData> = {|
@@ -17,61 +17,51 @@ describe("../ssr-cache.js", () => {
17
17
  });
18
18
 
19
19
  describe("#constructor", () => {
20
- const NODE_ENV = process.env.NODE_ENV;
21
-
22
- afterEach(() => {
23
- if (NODE_ENV == null) {
24
- delete process.env.NODE_ENV;
25
- } else {
26
- process.env.NODE_ENV = NODE_ENV;
27
- }
20
+ it("should default the ssr-only cache to a cache instance", () => {
21
+ // Arrange
22
+
23
+ // Act
24
+ const cache = new SsrCache();
25
+
26
+ // Assert
27
+ expect(cache._ssrOnlyCache).toBeInstanceOf(
28
+ SerializableInMemoryCache,
29
+ );
28
30
  });
29
31
 
30
- it.each(["development", "production"])(
31
- "should default the ssr-only cache to a undefined when client-side in %s",
32
- (nodeEnv) => {
33
- // Arrange
34
- jest.spyOn(Server, "isServerSide").mockReturnValue(false);
35
- process.env.NODE_ENV = nodeEnv;
32
+ it("should set the hydration cache to the passed instance if there is one", () => {
33
+ // Arrange
34
+ const passedInstance = new SerializableInMemoryCache();
36
35
 
37
- // Act
38
- const cache = new SsrCache();
36
+ // Act
37
+ const cache = new SsrCache(null, passedInstance);
39
38
 
40
- // Assert
41
- expect(cache._ssrOnlyCache).toBeUndefined();
42
- },
43
- );
39
+ // Assert
40
+ expect(cache._ssrOnlyCache).toBe(passedInstance);
41
+ });
44
42
 
45
- it("should default the ssr-only cache to a cache instance when client-side in test", () => {
43
+ it("should default the hydration cache to a cache instance", () => {
46
44
  // Arrange
47
- jest.spyOn(Server, "isServerSide").mockReturnValue(false);
48
- process.env.NODE_ENV = "test";
49
45
 
50
46
  // Act
51
47
  const cache = new SsrCache();
52
48
 
53
49
  // Assert
54
- expect(cache._ssrOnlyCache).toBeInstanceOf(
50
+ expect(cache._hydrationCache).toBeInstanceOf(
55
51
  SerializableInMemoryCache,
56
52
  );
57
53
  });
58
54
 
59
- it.each(["development", "production"])(
60
- "should default the ssr-only cache to a cache instance when server-side in %s",
61
- (nodeEnv) => {
62
- // Arrange
63
- jest.spyOn(Server, "isServerSide").mockReturnValue(true);
64
- process.env.NODE_ENV = nodeEnv;
55
+ it("should set the hydration cache to the passed instance if there is one", () => {
56
+ // Arrange
57
+ const passedInstance = new SerializableInMemoryCache();
65
58
 
66
- // Act
67
- const cache = new SsrCache();
59
+ // Act
60
+ const cache = new SsrCache(passedInstance);
68
61
 
69
- // Assert
70
- expect(cache._ssrOnlyCache).toBeInstanceOf(
71
- SerializableInMemoryCache,
72
- );
73
- },
74
- );
62
+ // Assert
63
+ expect(cache._hydrationCache).toBe(passedInstance);
64
+ });
75
65
  });
76
66
 
77
67
  describe("@Default", () => {