@khanacademy/wonder-blocks-data 8.0.0 → 8.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 +6 -0
- package/dist/es/index.js +1 -1
- package/dist/index.js +7 -1
- package/package.json +1 -1
- package/src/util/__tests__/ssr-cache.test.js +58 -0
- package/src/util/ssr-cache.js +10 -3
package/CHANGELOG.md
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -201,7 +201,7 @@ class SsrCache {
|
|
|
201
201
|
return (_cache$DefaultScope = cache[DefaultScope$2]) != null ? _cache$DefaultScope : {};
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
this._ssrOnlyCache = Server.isServerSide() ? ssrOnlyCache || new SerializableInMemoryCache() : undefined;
|
|
204
|
+
this._ssrOnlyCache = process.env.NODE_ENV === "test" || Server.isServerSide() ? ssrOnlyCache || new SerializableInMemoryCache() : undefined;
|
|
205
205
|
this._hydrationCache = hydrationCache || new SerializableInMemoryCache();
|
|
206
206
|
}
|
|
207
207
|
|
package/dist/index.js
CHANGED
|
@@ -658,7 +658,13 @@ class SsrCache {
|
|
|
658
658
|
return (_cache$DefaultScope = cache[DefaultScope]) != null ? _cache$DefaultScope : {};
|
|
659
659
|
};
|
|
660
660
|
|
|
661
|
-
|
|
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;
|
|
662
668
|
this._hydrationCache = hydrationCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
|
|
663
669
|
}
|
|
664
670
|
|
package/package.json
CHANGED
|
@@ -16,6 +16,64 @@ describe("../ssr-cache.js", () => {
|
|
|
16
16
|
jest.restoreAllMocks();
|
|
17
17
|
});
|
|
18
18
|
|
|
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
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
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;
|
|
36
|
+
|
|
37
|
+
// Act
|
|
38
|
+
const cache = new SsrCache();
|
|
39
|
+
|
|
40
|
+
// Assert
|
|
41
|
+
expect(cache._ssrOnlyCache).toBeUndefined();
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
it("should default the ssr-only cache to a cache instance when client-side in test", () => {
|
|
46
|
+
// Arrange
|
|
47
|
+
jest.spyOn(Server, "isServerSide").mockReturnValue(false);
|
|
48
|
+
process.env.NODE_ENV = "test";
|
|
49
|
+
|
|
50
|
+
// Act
|
|
51
|
+
const cache = new SsrCache();
|
|
52
|
+
|
|
53
|
+
// Assert
|
|
54
|
+
expect(cache._ssrOnlyCache).toBeInstanceOf(
|
|
55
|
+
SerializableInMemoryCache,
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
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;
|
|
65
|
+
|
|
66
|
+
// Act
|
|
67
|
+
const cache = new SsrCache();
|
|
68
|
+
|
|
69
|
+
// Assert
|
|
70
|
+
expect(cache._ssrOnlyCache).toBeInstanceOf(
|
|
71
|
+
SerializableInMemoryCache,
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
19
77
|
describe("@Default", () => {
|
|
20
78
|
it("should return an instance of SsrCache", () => {
|
|
21
79
|
// Arrange
|
package/src/util/ssr-cache.js
CHANGED
|
@@ -32,9 +32,16 @@ export class SsrCache {
|
|
|
32
32
|
hydrationCache: ?SerializableInMemoryCache = null,
|
|
33
33
|
ssrOnlyCache: ?SerializableInMemoryCache = null,
|
|
34
34
|
) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// The default instance gets made on first reference and if that happens
|
|
36
|
+
// before server-side mode is turned on, the Default instance would
|
|
37
|
+
// never have an SSR-only cache instance, which would then mean that if
|
|
38
|
+
// server-side mode got turned on, it wouldn't work right.
|
|
39
|
+
// This should only be an issue of surprise during testing, so, let's
|
|
40
|
+
// always have an instance in that circumstance.
|
|
41
|
+
this._ssrOnlyCache =
|
|
42
|
+
process.env.NODE_ENV === "test" || Server.isServerSide()
|
|
43
|
+
? ssrOnlyCache || new SerializableInMemoryCache()
|
|
44
|
+
: undefined;
|
|
38
45
|
this._hydrationCache =
|
|
39
46
|
hydrationCache || new SerializableInMemoryCache();
|
|
40
47
|
}
|