@@ -238,6 +238,53 @@ describe('ReactCache', () => {
238
238
expect ( root ) . toMatchRenderedOutput ( 'Bye' ) ;
239
239
} ) ;
240
240
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
+
241
288
// @gate experimental || www
242
289
test ( 'multiple new Cache boundaries in the same update share the same, fresh cache' , async ( ) => {
243
290
function App ( { showMore} ) {
0 commit comments