@@ -1778,5 +1778,57 @@ describe('ReactSuspense', () => {
1778
1778
expect ( Scheduler ) . toFlushExpired ( [ 'new value' ] ) ;
1779
1779
expect ( root ) . toMatchRenderedOutput ( 'new value' ) ;
1780
1780
} ) ;
1781
+
1782
+ it ( 'updates context consumer within child of suspended suspense component when context updates' , ( ) => {
1783
+ const { createContext, useState} = React ;
1784
+
1785
+ const ValueContext = createContext ( null ) ;
1786
+
1787
+ const promiseThatNeverResolves = new Promise ( ( ) => { } ) ;
1788
+ function Child ( ) {
1789
+ return (
1790
+ < ValueContext . Consumer >
1791
+ { value => {
1792
+ Scheduler . unstable_yieldValue ( `Received context value [${ value } ]` ) ;
1793
+ if ( value === 'default' ) return < Text text = "default" /> ;
1794
+ throw promiseThatNeverResolves ;
1795
+ } }
1796
+ </ ValueContext . Consumer >
1797
+ ) ;
1798
+ }
1799
+
1800
+ let setValue ;
1801
+ function Wrapper ( { children} ) {
1802
+ const [ value , _setValue ] = useState ( 'default' ) ;
1803
+ setValue = _setValue ;
1804
+ return (
1805
+ < ValueContext . Provider value = { value } >
1806
+ { children }
1807
+ </ ValueContext . Provider >
1808
+ ) ;
1809
+ }
1810
+
1811
+ function App ( ) {
1812
+ return (
1813
+ < Wrapper >
1814
+ < Suspense fallback = { < Text text = "Loading..." /> } >
1815
+ < Child />
1816
+ </ Suspense >
1817
+ </ Wrapper >
1818
+ ) ;
1819
+ }
1820
+
1821
+ const root = ReactTestRenderer . create ( < App /> ) ;
1822
+ expect ( Scheduler ) . toHaveYielded ( [ 'Received context value [default]' , 'default' ] ) ;
1823
+ expect ( root ) . toMatchRenderedOutput ( 'default' ) ;
1824
+
1825
+ act ( ( ) => setValue ( 'new value' ) ) ;
1826
+ expect ( Scheduler ) . toHaveYielded ( [ 'Received context value [new value]' , 'Loading...' ] ) ;
1827
+ expect ( root ) . toMatchRenderedOutput ( 'Loading...' ) ;
1828
+
1829
+ act ( ( ) => setValue ( 'default' ) ) ;
1830
+ expect ( Scheduler ) . toHaveYielded ( [ 'Received context value [default]' , 'default' ] ) ;
1831
+ expect ( root ) . toMatchRenderedOutput ( 'default' ) ;
1832
+ } ) ;
1781
1833
} ) ;
1782
1834
} ) ;
0 commit comments