diff --git a/packages/react-reconciler/src/__tests__/ReactCache-test.js b/packages/react-reconciler/src/__tests__/ReactCache-test.js index 6a20f738af8b3..804486721f9cf 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}) {