@@ -21,6 +21,7 @@ let useSyncExternalStore;
21
21
let useSyncExternalStoreExtra ;
22
22
let PropTypes ;
23
23
let textCache ;
24
+ let window ;
24
25
let document ;
25
26
let writable ;
26
27
let CSPnonce = null ;
@@ -56,6 +57,7 @@ describe('ReactDOMFizzServer', () => {
56
57
runScripts : 'dangerously' ,
57
58
} ,
58
59
) ;
60
+ window = jsdom . window ;
59
61
document = jsdom . window . document ;
60
62
container = document . getElementById ( 'container' ) ;
61
63
@@ -338,11 +340,18 @@ describe('ReactDOMFizzServer', () => {
338
340
) ;
339
341
}
340
342
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
+
341
350
await act ( async ( ) => {
342
351
const { pipe} = ReactDOMFizzServer . renderToPipeableStream (
343
352
< App isClient = { false } /> ,
344
-
345
353
{
354
+ bootstrapScriptContent : '__INIT__();' ,
346
355
onError ( x ) {
347
356
loggedErrors . push ( x ) ;
348
357
} ,
@@ -351,10 +360,8 @@ describe('ReactDOMFizzServer', () => {
351
360
pipe ( writable ) ;
352
361
} ) ;
353
362
expect ( loggedErrors ) . toEqual ( [ ] ) ;
363
+ expect ( bootstrapped ) . toBe ( true ) ;
354
364
355
- // Attempt to hydrate the content.
356
- const root = ReactDOM . createRoot ( container , { hydrate : true } ) ;
357
- root . render ( < App isClient = { true } /> ) ;
358
365
Scheduler . unstable_flushAll ( ) ;
359
366
360
367
// We're still loading because we're waiting for the server to stream more content.
@@ -507,17 +514,27 @@ describe('ReactDOMFizzServer', () => {
507
514
) ;
508
515
}
509
516
517
+ let bootstrapped = false ;
518
+ window . __INIT__ = function ( ) {
519
+ bootstrapped = true ;
520
+ // Attempt to hydrate the content.
521
+ ReactDOM . hydrateRoot ( container , < App /> ) ;
522
+ } ;
523
+
510
524
await act ( async ( ) => {
511
- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> ) ;
525
+ const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> , {
526
+ bootstrapScriptContent : '__INIT__();' ,
527
+ } ) ;
512
528
pipe ( writable ) ;
513
529
} ) ;
514
530
515
531
// We're still showing a fallback.
516
532
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Loading...</ div > ) ;
517
533
534
+ // We already bootstrapped.
535
+ expect ( bootstrapped ) . toBe ( true ) ;
536
+
518
537
// Attempt to hydrate the content.
519
- const root = ReactDOM . createRoot ( container , { hydrate : true } ) ;
520
- root . render ( < App /> ) ;
521
538
Scheduler . unstable_flushAll ( ) ;
522
539
523
540
// We're still loading because we're waiting for the server to stream more content.
0 commit comments