Skip to content

Commit

Permalink
Add back lost cache test (#24317)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii authored Apr 8, 2022
1 parent a9add2f commit b86baa1
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/react-reconciler/src/__tests__/ReactCache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<Cache>
<Suspense fallback={<Text text="Loading..." />}>
<AsyncText text="A" />
</Suspense>
</Cache>
<Cache>
<Suspense fallback={<Text text="Loading..." />}>
<AsyncText text="A" />
</Suspense>
</Cache>
</>
);
}

const root = ReactNoop.createRoot();
await act(async () => {
root.render(<App showMore={false} />);
});

// Even though there are two new <Cache /> 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}) {
Expand Down

0 comments on commit b86baa1

Please sign in to comment.