Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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