@@ -21,6 +21,7 @@ let useSyncExternalStore;
2121let useSyncExternalStoreExtra ;
2222let PropTypes ;
2323let textCache ;
24+ let window ;
2425let document ;
2526let writable ;
2627let CSPnonce = null ;
@@ -56,6 +57,7 @@ describe('ReactDOMFizzServer', () => {
5657 runScripts : 'dangerously' ,
5758 } ,
5859 ) ;
60+ window = jsdom . window ;
5961 document = jsdom . window . document ;
6062 container = document . getElementById ( 'container' ) ;
6163
@@ -338,11 +340,18 @@ describe('ReactDOMFizzServer', () => {
338340 ) ;
339341 }
340342
343+ let bootstrapped = false ;
344+ window . __INIT__ = function ( ) {
345+ bootstrapped = true ;
346+ // Attempt to hydrate the content.
347+ ReactDOM . hydrateRoot ( container , < App isClient = { true } /> ) ;
348+ } ;
349+
341350 await act ( async ( ) => {
342351 const { pipe} = ReactDOMFizzServer . renderToPipeableStream (
343352 < App isClient = { false } /> ,
344-
345353 {
354+ bootstrapScriptContent : '__INIT__();' ,
346355 onError ( x ) {
347356 loggedErrors . push ( x ) ;
348357 } ,
@@ -351,10 +360,8 @@ describe('ReactDOMFizzServer', () => {
351360 pipe ( writable ) ;
352361 } ) ;
353362 expect ( loggedErrors ) . toEqual ( [ ] ) ;
363+ expect ( bootstrapped ) . toBe ( true ) ;
354364
355- // Attempt to hydrate the content.
356- const root = ReactDOM . createRoot ( container , { hydrate : true } ) ;
357- root . render ( < App isClient = { true } /> ) ;
358365 Scheduler . unstable_flushAll ( ) ;
359366
360367 // We're still loading because we're waiting for the server to stream more content.
@@ -507,17 +514,27 @@ describe('ReactDOMFizzServer', () => {
507514 ) ;
508515 }
509516
517+ let bootstrapped = false ;
518+ window . __INIT__ = function ( ) {
519+ bootstrapped = true ;
520+ // Attempt to hydrate the content.
521+ ReactDOM . hydrateRoot ( container , < App /> ) ;
522+ } ;
523+
510524 await act ( async ( ) => {
511- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> ) ;
525+ const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> , {
526+ bootstrapScriptContent : '__INIT__();' ,
527+ } ) ;
512528 pipe ( writable ) ;
513529 } ) ;
514530
515531 // We're still showing a fallback.
516532 expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Loading...</ div > ) ;
517533
534+ // We already bootstrapped.
535+ expect ( bootstrapped ) . toBe ( true ) ;
536+
518537 // Attempt to hydrate the content.
519- const root = ReactDOM . createRoot ( container , { hydrate : true } ) ;
520- root . render ( < App /> ) ;
521538 Scheduler . unstable_flushAll ( ) ;
522539
523540 // We're still loading because we're waiting for the server to stream more content.
0 commit comments