@@ -1523,4 +1523,63 @@ describe('ReactSuspense', () => {
1523
1523
expect ( root ) . toMatchRenderedOutput ( 'new value' ) ;
1524
1524
} ) ;
1525
1525
} ) ;
1526
+
1527
+ it ( 'updates context consumer within child of suspended suspense component when context updates' , ( ) => {
1528
+ const { createContext, useState} = React ;
1529
+
1530
+ const ValueContext = createContext ( null ) ;
1531
+
1532
+ const promiseThatNeverResolves = new Promise ( ( ) => { } ) ;
1533
+ function Child ( ) {
1534
+ return (
1535
+ < ValueContext . Consumer >
1536
+ { value => {
1537
+ Scheduler . unstable_yieldValue ( `Received context value [${ value } ]` ) ;
1538
+ if ( value === 'default' ) return < Text text = "default" /> ;
1539
+ throw promiseThatNeverResolves ;
1540
+ } }
1541
+ </ ValueContext . Consumer >
1542
+ ) ;
1543
+ }
1544
+
1545
+ let setValue ;
1546
+ function Wrapper ( { children} ) {
1547
+ const [ value , _setValue ] = useState ( 'default' ) ;
1548
+ setValue = _setValue ;
1549
+ return (
1550
+ < ValueContext . Provider value = { value } > { children } </ ValueContext . Provider >
1551
+ ) ;
1552
+ }
1553
+
1554
+ function App ( ) {
1555
+ return (
1556
+ < Wrapper >
1557
+ < Suspense fallback = { < Text text = "Loading..." /> } >
1558
+ < Child />
1559
+ </ Suspense >
1560
+ </ Wrapper >
1561
+ ) ;
1562
+ }
1563
+
1564
+ const root = ReactTestRenderer . create ( < App /> ) ;
1565
+ expect ( Scheduler ) . toHaveYielded ( [
1566
+ 'Received context value [default]' ,
1567
+ 'default' ,
1568
+ ] ) ;
1569
+ expect ( root ) . toMatchRenderedOutput ( 'default' ) ;
1570
+
1571
+ act ( ( ) => setValue ( 'new value' ) ) ;
1572
+ expect ( Scheduler ) . toHaveYielded ( [
1573
+ 'Received context value [new value]' ,
1574
+ 'Loading...' ,
1575
+ ] ) ;
1576
+ expect ( root ) . toMatchRenderedOutput ( 'Loading...' ) ;
1577
+
1578
+ act ( ( ) => setValue ( 'default' ) ) ;
1579
+ expect ( Scheduler ) . toHaveYielded ( [
1580
+ 'Received context value [default]' ,
1581
+ 'default' ,
1582
+ ] ) ;
1583
+ expect ( root ) . toMatchRenderedOutput ( 'default' ) ;
1584
+ } ) ;
1526
1585
} ) ;
0 commit comments