@@ -1680,31 +1680,38 @@ describe('ReactDOMFizzServer', () => {
16801680
16811681 // @gate experimental
16821682 it ( 'calls getServerSnapshot instead of getSnapshot' , async ( ) => {
1683+ const ref = React . createRef ( ) ;
1684+
16831685 function getServerSnapshot ( ) {
16841686 return 'server' ;
16851687 }
1688+
16861689 function getClientSnapshot ( ) {
16871690 return 'client' ;
16881691 }
1692+
16891693 function subscribe ( ) {
16901694 return ( ) => { } ;
16911695 }
1696+
16921697 function Child ( { text} ) {
16931698 Scheduler . unstable_yieldValue ( text ) ;
16941699 return text ;
16951700 }
1701+
16961702 function App ( ) {
16971703 const value = useSyncExternalStore (
16981704 subscribe ,
16991705 getClientSnapshot ,
17001706 getServerSnapshot ,
17011707 ) ;
17021708 return (
1703- < div >
1709+ < div ref = { ref } >
17041710 < Child text = { value } />
17051711 </ div >
17061712 ) ;
17071713 }
1714+
17081715 const loggedErrors = [ ] ;
17091716 await act ( async ( ) => {
17101717 const { pipe} = ReactDOMFizzServer . renderToPipeableStream (
@@ -1723,14 +1730,29 @@ describe('ReactDOMFizzServer', () => {
17231730
17241731 ReactDOM . hydrateRoot ( container , < App /> ) ;
17251732
1726- expect ( ( ) => {
1727- // The first paint switches to client rendering due to mismatch
1733+ if ( gate ( flags => flags . enableClientRenderFallbackOnHydrationMismatch ) ) {
1734+ expect ( ( ) => {
1735+ // The first paint switches to client rendering due to mismatch
1736+ expect ( Scheduler ) . toFlushUntilNextPaint ( [ 'client' ] ) ;
1737+ } ) . toErrorDev (
1738+ 'Warning: An error occurred during hydration. The server HTML was replaced with client content' ,
1739+ { withoutStack : true } ,
1740+ ) ;
1741+ expect ( getVisibleChildren ( container ) ) . toEqual ( < div > client</ div > ) ;
1742+ } else {
1743+ const serverRenderedDiv = container . getElementsByTagName ( 'div' ) [ 0 ] ;
1744+ // The first paint uses the server snapshot
1745+ expect ( Scheduler ) . toFlushUntilNextPaint ( [ 'server' ] ) ;
1746+ expect ( getVisibleChildren ( container ) ) . toEqual ( < div > server</ div > ) ;
1747+ // Hydration succeeded
1748+ expect ( ref . current ) . toEqual ( serverRenderedDiv ) ;
1749+
1750+ // Asynchronously we detect that the store has changed on the client,
1751+ // and patch up the inconsistency
17281752 expect ( Scheduler ) . toFlushUntilNextPaint ( [ 'client' ] ) ;
1729- } ) . toErrorDev (
1730- 'Warning: An error occurred during hydration. The server HTML was replaced with client content' ,
1731- { withoutStack : true } ,
1732- ) ;
1733- expect ( getVisibleChildren ( container ) ) . toEqual ( < div > client</ div > ) ;
1753+ expect ( getVisibleChildren ( container ) ) . toEqual ( < div > client</ div > ) ;
1754+ expect ( ref . current ) . toEqual ( serverRenderedDiv ) ;
1755+ }
17341756 } ) ;
17351757
17361758 // The selector implementation uses the lazy ref initialization pattern
@@ -1790,15 +1812,31 @@ describe('ReactDOMFizzServer', () => {
17901812
17911813 ReactDOM . hydrateRoot ( container , < App /> ) ;
17921814
1793- // The first paint uses the client due to mismatch forcing client render
1794- expect ( ( ) => {
1795- // The first paint switches to client rendering due to mismatch
1815+ if ( gate ( flags => flags . enableClientRenderFallbackOnHydrationMismatch ) ) {
1816+ // The first paint uses the client due to mismatch forcing client render
1817+ expect ( ( ) => {
1818+ // The first paint switches to client rendering due to mismatch
1819+ expect ( Scheduler ) . toFlushUntilNextPaint ( [ 'client' ] ) ;
1820+ } ) . toErrorDev (
1821+ 'Warning: An error occurred during hydration. The server HTML was replaced with client content' ,
1822+ { withoutStack : true } ,
1823+ ) ;
1824+ expect ( getVisibleChildren ( container ) ) . toEqual ( < div > client</ div > ) ;
1825+ } else {
1826+ const serverRenderedDiv = container . getElementsByTagName ( 'div' ) [ 0 ] ;
1827+
1828+ // The first paint uses the server snapshot
1829+ expect ( Scheduler ) . toFlushUntilNextPaint ( [ 'server' ] ) ;
1830+ expect ( getVisibleChildren ( container ) ) . toEqual ( < div > server</ div > ) ;
1831+ // Hydration succeeded
1832+ expect ( ref . current ) . toEqual ( serverRenderedDiv ) ;
1833+
1834+ // Asynchronously we detect that the store has changed on the client,
1835+ // and patch up the inconsistency
17961836 expect ( Scheduler ) . toFlushUntilNextPaint ( [ 'client' ] ) ;
1797- } ) . toErrorDev (
1798- 'Warning: An error occurred during hydration. The server HTML was replaced with client content' ,
1799- { withoutStack : true } ,
1800- ) ;
1801- expect ( getVisibleChildren ( container ) ) . toEqual ( < div > client</ div > ) ;
1837+ expect ( getVisibleChildren ( container ) ) . toEqual ( < div > client</ div > ) ;
1838+ expect ( ref . current ) . toEqual ( serverRenderedDiv ) ;
1839+ }
18021840 } ) ;
18031841
18041842 // @gate experimental
0 commit comments