@khanacademy/wonder-blocks-data 8.0.3 → 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,11 @@
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
+
3
9
  ## 8.0.3
4
10
 
5
11
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -585,7 +585,6 @@ const useCachedEffect = (requestId, handler, options = {}) => {
585
585
 
586
586
  return fetchFn;
587
587
  }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]);
588
- const requestIdRef = React.useRef(requestId);
589
588
  const shouldFetch = React.useMemo(() => {
590
589
  if (hardSkip) {
591
590
  return false;
@@ -596,14 +595,13 @@ const useCachedEffect = (requestId, handler, options = {}) => {
596
595
  return false;
597
596
 
598
597
  case FetchPolicy.CacheBeforeNetwork:
599
- return mostRecentResult == null || requestId !== requestIdRef.current;
598
+ return mostRecentResult == null;
600
599
 
601
600
  case FetchPolicy.CacheAndNetwork:
602
601
  case FetchPolicy.NetworkOnly:
603
602
  return networkResultRef.current == null;
604
603
  }
605
- }, [requestId, mostRecentResult, fetchPolicy, hardSkip]);
606
- requestIdRef.current = requestId;
604
+ }, [mostRecentResult, fetchPolicy, hardSkip]);
607
605
  React.useEffect(() => {
608
606
  if (!shouldFetch) {
609
607
  return;
package/dist/index.js CHANGED
@@ -175,17 +175,10 @@ module.exports = require("@khanacademy/wonder-blocks-core");
175
175
 
176
176
  "use strict";
177
177
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FetchPolicy; });
178
- // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
179
- // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
180
-
181
- /* eslint-disable no-undef */
182
-
183
178
  /**
184
179
  * Defines the various fetch policies that can be applied to requests.
185
180
  */
186
181
  const FetchPolicy = __webpack_require__(22).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
187
- /* eslint-enable no-undef */
188
-
189
182
  /**
190
183
  * Define what can be cached.
191
184
  *
@@ -1343,10 +1336,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1343
1336
  // really make sense - the same requestId should be handled the same as
1344
1337
  // each other.
1345
1338
  // eslint-disable-next-line react-hooks/exhaustive-deps
1346
- }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // We need to trigger a re-render when the request ID changes as that
1347
- // indicates its a different request.
1348
-
1349
- 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.
1350
1340
  // If this is true, we will do a new fetch, cancelling the previous fetch
1351
1341
  // if there is one inflight.
1352
1342
 
@@ -1363,9 +1353,8 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1363
1353
  return false;
1364
1354
 
1365
1355
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork:
1366
- // If we don't have a cached value or this is a new requestId,
1367
- // then we need to fetch.
1368
- return mostRecentResult == null || requestId !== requestIdRef.current;
1356
+ // If we don't have a cached value then we need to fetch.
1357
+ return mostRecentResult == null;
1369
1358
 
1370
1359
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheAndNetwork:
1371
1360
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly:
@@ -1373,9 +1362,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1373
1362
  // result, then we need to fetch one.
1374
1363
  return networkResultRef.current == null;
1375
1364
  }
1376
- }, [requestId, mostRecentResult, fetchPolicy, hardSkip]); // Let's make sure our ref is set to the most recent requestId.
1377
-
1378
- requestIdRef.current = requestId;
1365
+ }, [mostRecentResult, fetchPolicy, hardSkip]);
1379
1366
  react__WEBPACK_IMPORTED_MODULE_0__["useEffect"](() => {
1380
1367
  if (!shouldFetch) {
1381
1368
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-data",
3
- "version": "8.0.3",
3
+ "version": "8.0.4",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,7 +13,7 @@
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
15
15
  "dependencies": {
16
- "@babel/runtime": "^7.16.3",
16
+ "@babel/runtime": "^7.18.6",
17
17
  "@khanacademy/wonder-blocks-core": "^4.3.2"
18
18
  },
19
19
  "peerDependencies": {
@@ -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> = {|
package/src/util/types.js CHANGED
@@ -1,9 +1,6 @@
1
1
  // @flow
2
2
  import type {Metadata} from "@khanacademy/wonder-stuff-core";
3
3
 
4
- // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
5
- // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
6
- /* eslint-disable no-undef */
7
4
  /**
8
5
  * Defines the various fetch policies that can be applied to requests.
9
6
  */
@@ -30,7 +27,6 @@ export enum FetchPolicy {
30
27
  */
31
28
  NetworkOnly,
32
29
  }
33
- /* eslint-enable no-undef */
34
30
 
35
31
  /**
36
32
  * Define what can be cached.