Add back lost cache test (#24317)
Ricky committed
Apr 8, 2022 at 15:34 UTC
b86baa1cb7b0838169eb762873d53442b9075c94
1 file changed
+47
packages/react-reconciler/src/__tests__/ReactCache-test.js
+47
@@ -238,6 +238,53 @@ describe('ReactCache', () => {
238
expect(root).toMatchRenderedOutput('Bye');
239
});
240
241
+ // @gate experimental || www
242
+ test('multiple new Cache boundaries in the same mount share the same, fresh root cache', async () => {
243
+ function App() {
244
+ return (
245
+ <>
246
+ <Cache>
247
+ <Suspense fallback={<Text text="Loading..." />}>
248
+ <AsyncText text="A" />
249
+ </Suspense>
250
+ </Cache>
251
+ <Cache>
252
+ <Suspense fallback={<Text text="Loading..." />}>
253
+ <AsyncText text="A" />
254
+ </Suspense>
255
+ </Cache>
256
+ </>
257
+ );
258
+ }
259
+
260
+ const root = ReactNoop.createRoot();
261
+ await act(async () => {
262
+ root.render(<App showMore={false} />);
263
+ });
264
+
265
+ // Even though there are two new <Cache /> trees, they should share the same
266
+ // data cache. So there should be only a single cache miss for A.
267
+ expect(Scheduler).toHaveYielded([
268
+ 'Cache miss! [A]',
269
+ 'Loading...',
270
+ 'Loading...',
271
+ ]);
272
+ expect(root).toMatchRenderedOutput('Loading...Loading...');
273
+
274
+ await act(async () => {
275
+ resolveMostRecentTextCache('A');
276
+ });
277
+ expect(Scheduler).toHaveYielded(['A', 'A']);
278
+ expect(root).toMatchRenderedOutput('AA');
279
+
280
+ await act(async () => {
281
+ root.render('Bye');
282
+ });
283
+ // no cleanup: cache is still retained at the root
284
+ expect(Scheduler).toHaveYielded([]);
285
+ expect(root).toMatchRenderedOutput('Bye');
286
+ });
287
+
288
// @gate experimental || www
289
test('multiple new Cache boundaries in the same update share the same, fresh cache', async () => {
290
function App({showMore}) {