@@ -1953,4 +1953,66 @@ describe('ReactDOMServerSelectiveHydration', () => {
19531953 ] ) ;
19541954 } ) ;
19551955 } ) ;
1956+
1957+ it ( 'regression test: can unwind context on selective hydration interruption for sync updates' , async ( ) => {
1958+ const Context = React . createContext ( 'DefaultContext' ) ;
1959+
1960+ function ContextReader ( props ) {
1961+ const value = React . useContext ( Context ) ;
1962+ Scheduler . unstable_yieldValue ( value ) ;
1963+ return null ;
1964+ }
1965+
1966+ function Child ( { text} ) {
1967+ Scheduler . unstable_yieldValue ( text ) ;
1968+ return < span > { text } </ span > ;
1969+ }
1970+ const ChildWithBoundary = React . memo ( function ( { text} ) {
1971+ return (
1972+ < Suspense fallback = "Loading..." >
1973+ < Child text = { text } />
1974+ </ Suspense >
1975+ ) ;
1976+ } ) ;
1977+
1978+ function App ( { a} ) {
1979+ Scheduler . unstable_yieldValue ( 'App' ) ;
1980+ React . useEffect ( ( ) => {
1981+ Scheduler . unstable_yieldValue ( 'Commit' ) ;
1982+ } ) ;
1983+ return (
1984+ < >
1985+ < Context . Provider value = "SiblingContext" >
1986+ < ChildWithBoundary text = { a } />
1987+ </ Context . Provider >
1988+ < ContextReader />
1989+ </ >
1990+ ) ;
1991+ }
1992+ const finalHTML = ReactDOMServer . renderToString ( < App a = "A" /> ) ;
1993+ expect ( Scheduler ) . toHaveYielded ( [ 'App' , 'A' , 'DefaultContext' ] ) ;
1994+ const container = document . createElement ( 'div' ) ;
1995+ container . innerHTML = finalHTML ;
1996+
1997+ await act ( async ( ) => {
1998+ const root = ReactDOMClient . hydrateRoot ( container , < App a = "A" /> ) ;
1999+ expect ( Scheduler ) . toFlushAndYieldThrough ( [
2000+ 'App' ,
2001+ 'DefaultContext' ,
2002+ 'Commit' ,
2003+ ] ) ;
2004+
2005+ ReactDOM . flushSync ( ( ) => {
2006+ root . render ( < App a = "AA" /> ) ;
2007+ } ) ;
2008+ expect ( Scheduler ) . toHaveYielded ( [
2009+ 'App' ,
2010+ 'A' ,
2011+ 'App' ,
2012+ 'AA' ,
2013+ 'DefaultContext' ,
2014+ 'Commit' ,
2015+ ] ) ;
2016+ } ) ;
2017+ } ) ;
19562018} ) ;
0 commit comments