@khanacademy/wonder-blocks-data 6.0.0 → 6.0.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/CHANGELOG.md
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -1022,10 +1022,17 @@ const useHydratableEffect = (requestId, handler, options = {}) => {
|
|
|
1022
1022
|
}
|
|
1023
1023
|
|
|
1024
1024
|
return null;
|
|
1025
|
-
} // There is no reason for this to change after the first render
|
|
1025
|
+
} // There is no reason for this to change after the first render,
|
|
1026
|
+
// you might think, but the function closes around serverResult and if
|
|
1027
|
+
// the requestId changes, it still returns the hydrate result of the
|
|
1028
|
+
// first render of the previous requestId. This then means that the
|
|
1029
|
+
// hydrate result is still the same, and the effect is not re-executed
|
|
1030
|
+
// because the cache gets incorrectly defaulted.
|
|
1031
|
+
// However, we don't want to bother doing anything with this on
|
|
1032
|
+
// client behavior changing since that truly is irrelevant.
|
|
1026
1033
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1027
1034
|
|
|
1028
|
-
}, []); // Instead of using state, which would be local to just this hook instance,
|
|
1035
|
+
}, [serverResult]); // Instead of using state, which would be local to just this hook instance,
|
|
1029
1036
|
// we use a shared in-memory cache.
|
|
1030
1037
|
|
|
1031
1038
|
useSharedCache(requestId, // The key of the cached item
|
package/dist/index.js
CHANGED
|
@@ -952,10 +952,17 @@ const useHydratableEffect = (requestId, handler, options = {}) => {
|
|
|
952
952
|
}
|
|
953
953
|
|
|
954
954
|
return null;
|
|
955
|
-
} // There is no reason for this to change after the first render
|
|
955
|
+
} // There is no reason for this to change after the first render,
|
|
956
|
+
// you might think, but the function closes around serverResult and if
|
|
957
|
+
// the requestId changes, it still returns the hydrate result of the
|
|
958
|
+
// first render of the previous requestId. This then means that the
|
|
959
|
+
// hydrate result is still the same, and the effect is not re-executed
|
|
960
|
+
// because the cache gets incorrectly defaulted.
|
|
961
|
+
// However, we don't want to bother doing anything with this on
|
|
962
|
+
// client behavior changing since that truly is irrelevant.
|
|
956
963
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
957
964
|
|
|
958
|
-
}, []); // Instead of using state, which would be local to just this hook instance,
|
|
965
|
+
}, [serverResult]); // Instead of using state, which would be local to just this hook instance,
|
|
959
966
|
// we use a shared in-memory cache.
|
|
960
967
|
|
|
961
968
|
Object(_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_3__[/* useSharedCache */ "b"])(requestId, // The key of the cached item
|
package/legacy-docs.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Documentation for Wonder Blocks Data is now in Storybook.
|
|
2
2
|
|
|
3
|
-
Either run `yarn start:storybook` locally, or visit the the stories for the `
|
|
3
|
+
Either run `yarn start:storybook` locally, or visit the the stories for the `main` branch on [Chromatic](https://main--5e1bf4b385e3fb0020b7073c.chromatic.com).
|
package/package.json
CHANGED
|
@@ -413,6 +413,26 @@ describe("#useHydratableEffect", () => {
|
|
|
413
413
|
expect(fakeHandler).toHaveBeenCalledTimes(2);
|
|
414
414
|
});
|
|
415
415
|
|
|
416
|
+
it("should default shared cache to hydrate value for new requestId", async () => {
|
|
417
|
+
// Arrange
|
|
418
|
+
const fakeHandler = jest.fn().mockResolvedValue("data");
|
|
419
|
+
jest.spyOn(UseServerEffect, "useServerEffect")
|
|
420
|
+
.mockReturnValueOnce(Status.success("BADDATA"))
|
|
421
|
+
.mockReturnValue(null);
|
|
422
|
+
|
|
423
|
+
// Act
|
|
424
|
+
const {rerender, result} = clientRenderHook(
|
|
425
|
+
({requestId}) => useHydratableEffect(requestId, fakeHandler),
|
|
426
|
+
{
|
|
427
|
+
initialProps: {requestId: "ID"},
|
|
428
|
+
},
|
|
429
|
+
);
|
|
430
|
+
rerender({requestId: "ID2"});
|
|
431
|
+
|
|
432
|
+
// Assert
|
|
433
|
+
expect(result.current).toStrictEqual(Status.loading());
|
|
434
|
+
});
|
|
435
|
+
|
|
416
436
|
it("should update shared cache with result when request is fulfilled", async () => {
|
|
417
437
|
// Arrange
|
|
418
438
|
const setCacheFn = jest.fn();
|
|
@@ -178,9 +178,16 @@ export const useHydratableEffect = <TData: ValidCacheData>(
|
|
|
178
178
|
}
|
|
179
179
|
return null;
|
|
180
180
|
}
|
|
181
|
-
// There is no reason for this to change after the first render
|
|
181
|
+
// There is no reason for this to change after the first render,
|
|
182
|
+
// you might think, but the function closes around serverResult and if
|
|
183
|
+
// the requestId changes, it still returns the hydrate result of the
|
|
184
|
+
// first render of the previous requestId. This then means that the
|
|
185
|
+
// hydrate result is still the same, and the effect is not re-executed
|
|
186
|
+
// because the cache gets incorrectly defaulted.
|
|
187
|
+
// However, we don't want to bother doing anything with this on
|
|
188
|
+
// client behavior changing since that truly is irrelevant.
|
|
182
189
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
183
|
-
}, []);
|
|
190
|
+
}, [serverResult]);
|
|
184
191
|
|
|
185
192
|
// Instead of using state, which would be local to just this hook instance,
|
|
186
193
|
// we use a shared in-memory cache.
|