@@ -1772,4 +1772,71 @@ describe('ReactDOMServerSelectiveHydration', () => {
1772
1772
1773
1773
document . body . removeChild ( container ) ;
1774
1774
} ) ;
1775
+
1776
+ it ( 'regression test: can unwind context on selective hydration interruption' , async ( ) => {
1777
+ const Context = React . createContext ( 'DefaultContext' ) ;
1778
+
1779
+ function ContextReader ( props ) {
1780
+ const value = React . useContext ( Context ) ;
1781
+ Scheduler . unstable_yieldValue ( value ) ;
1782
+ return null ;
1783
+ }
1784
+
1785
+ function Child ( { text} ) {
1786
+ Scheduler . unstable_yieldValue ( text ) ;
1787
+ return < span > { text } </ span > ;
1788
+ }
1789
+ const ChildWithBoundary = React . memo ( function ( { text} ) {
1790
+ return (
1791
+ < Suspense fallback = "Loading..." >
1792
+ < Child text = { text } />
1793
+ </ Suspense >
1794
+ ) ;
1795
+ } ) ;
1796
+
1797
+ function App ( { a} ) {
1798
+ Scheduler . unstable_yieldValue ( 'App' ) ;
1799
+ React . useEffect ( ( ) => {
1800
+ Scheduler . unstable_yieldValue ( 'Commit' ) ;
1801
+ } ) ;
1802
+ return (
1803
+ < >
1804
+ < Context . Provider value = "SiblingContext" >
1805
+ < ChildWithBoundary text = { a } />
1806
+ </ Context . Provider >
1807
+ < ContextReader />
1808
+ </ >
1809
+ ) ;
1810
+ }
1811
+ const finalHTML = ReactDOMServer . renderToString ( < App a = "A" /> ) ;
1812
+ expect ( Scheduler ) . toHaveYielded ( [ 'App' , 'A' , 'DefaultContext' ] ) ;
1813
+ const container = document . createElement ( 'div' ) ;
1814
+ container . innerHTML = finalHTML ;
1815
+ document . body . appendChild ( container ) ;
1816
+
1817
+ const spanA = container . getElementsByTagName ( 'span' ) [ 0 ] ;
1818
+
1819
+ await act ( async ( ) => {
1820
+ const root = ReactDOMClient . hydrateRoot ( container , < App a = "A" /> ) ;
1821
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [
1822
+ 'App' ,
1823
+ 'DefaultContext' ,
1824
+ 'Commit' ,
1825
+ ] ) ;
1826
+
1827
+ TODO_scheduleIdleDOMSchedulerTask ( ( ) => {
1828
+ root . render ( < App a = "AA" /> ) ;
1829
+ } ) ;
1830
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'App' , 'AA' , 'DefaultContext' ] ) ;
1831
+
1832
+ dispatchClickEvent ( spanA ) ;
1833
+ expect ( Scheduler ) . toHaveYielded ( [ 'A' ] ) ;
1834
+ expect ( Scheduler ) . toFlushAndYield ( [
1835
+ 'App' ,
1836
+ 'AA' ,
1837
+ 'DefaultContext' ,
1838
+ 'Commit' ,
1839
+ ] ) ;
1840
+ } ) ;
1841
+ } ) ;
1775
1842
} ) ;
0 commit comments