@@ -1451,6 +1451,60 @@ describe('ReactSuspenseWithNoopRenderer', () => {
14511451 expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 'A' ) , span ( 'B' ) ] ) ;
14521452 } ) ;
14531453
1454+ it ( 'does suspend if a fallback has been shown for a short time' , async ( ) => {
1455+ function Foo ( ) {
1456+ Scheduler . yieldValue ( 'Foo' ) ;
1457+ return (
1458+ < Suspense fallback = { < Text text = "Loading..." /> } >
1459+ < AsyncText text = "A" ms = { 200 } />
1460+ < Suspense fallback = { < Text text = "Loading more..." /> } >
1461+ < AsyncText text = "B" ms = { 450 } />
1462+ </ Suspense >
1463+ </ Suspense >
1464+ ) ;
1465+ }
1466+
1467+ ReactNoop . render ( < Foo /> ) ;
1468+ // Start rendering
1469+ expect ( Scheduler ) . toFlushAndYield ( [
1470+ 'Foo' ,
1471+ // A suspends
1472+ 'Suspend! [A]' ,
1473+ // B suspends
1474+ 'Suspend! [B]' ,
1475+ 'Loading more...' ,
1476+ 'Loading...' ,
1477+ ] ) ;
1478+ expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 'Loading...' ) ] ) ;
1479+
1480+ // Wait a short time.
1481+ Scheduler . advanceTime ( 250 ) ;
1482+ await advanceTimers ( 250 ) ;
1483+ expect ( Scheduler ) . toHaveYielded ( [ 'Promise resolved [A]' ] ) ;
1484+
1485+ // Retry with the new content.
1486+ expect ( Scheduler ) . toFlushAndYield ( [
1487+ 'A' ,
1488+ // B still suspends
1489+ 'Suspend! [B]' ,
1490+ 'Loading more...' ,
1491+ ] ) ;
1492+ // Because we've already been waiting for so long we can
1493+ // wait a bit longer. Still nothing...
1494+ expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 'Loading...' ) ] ) ;
1495+
1496+ Scheduler . advanceTime ( 200 ) ;
1497+ await advanceTimers ( 200 ) ;
1498+
1499+ // Before we commit another Promise resolves.
1500+ expect ( Scheduler ) . toHaveYielded ( [ 'Promise resolved [B]' ] ) ;
1501+ // We're still showing the first loading state.
1502+ expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 'Loading...' ) ] ) ;
1503+ // Restart and render the complete content.
1504+ expect ( Scheduler ) . toFlushAndYield ( [ 'A' , 'B' ] ) ;
1505+ expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 'A' ) , span ( 'B' ) ] ) ;
1506+ } ) ;
1507+
14541508 it ( 'does not suspend for very long after a higher priority update' , async ( ) => {
14551509 function Foo ( { renderContent} ) {
14561510 Scheduler . yieldValue ( 'Foo' ) ;
0 commit comments