From b86baa1cb7b0838169eb762873d53442b9075c94 Mon Sep 17 00:00:00 2001 From: Ricky Date: Fri, 8 Apr 2022 15:34:41 -0400 Subject: [PATCH] Add back lost cache test (#24317) --- .../src/__tests__/ReactCache-test.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/packages/react-reconciler/src/__tests__/ReactCache-test.js b/packages/react-reconciler/src/__tests__/ReactCache-test.js index 6a20f738af8b..804486721f9c 100644 --- a/packages/react-reconciler/src/__tests__/ReactCache-test.js +++ b/packages/react-reconciler/src/__tests__/ReactCache-test.js @@ -238,6 +238,53 @@ describe('ReactCache', () => { expect(root).toMatchRenderedOutput('Bye'); }); + // @gate experimental || www + test('multiple new Cache boundaries in the same mount share the same, fresh root cache', async () => { + function App() { + return ( + <> + + }> + + + + + }> + + + + + ); + } + + const root = ReactNoop.createRoot(); + await act(async () => { + root.render(); + }); + + // Even though there are two new trees, they should share the same + // data cache. So there should be only a single cache miss for A. + expect(Scheduler).toHaveYielded([ + 'Cache miss! [A]', + 'Loading...', + 'Loading...', + ]); + expect(root).toMatchRenderedOutput('Loading...Loading...'); + + await act(async () => { + resolveMostRecentTextCache('A'); + }); + expect(Scheduler).toHaveYielded(['A', 'A']); + expect(root).toMatchRenderedOutput('AA'); + + await act(async () => { + root.render('Bye'); + }); + // no cleanup: cache is still retained at the root + expect(Scheduler).toHaveYielded([]); + expect(root).toMatchRenderedOutput('Bye'); + }); + // @gate experimental || www test('multiple new Cache boundaries in the same update share the same, fresh cache', async () => { function App({showMore}) {