@@ -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