Skip to content

Commit b86baa1

Browse files
authored
Add back lost cache test (#24317)
1 parent a9add2f commit b86baa1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/react-reconciler/src/__tests__/ReactCache-test.js

+47
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,53 @@ describe('ReactCache', () => {
238238
expect(root).toMatchRenderedOutput('Bye');
239239
});
240240

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+
241288
// @gate experimental || www
242289
test('multiple new Cache boundaries in the same update share the same, fresh cache', async () => {
243290
function App({showMore}) {

0 commit comments

Comments
 (0)