@@ -320,4 +320,84 @@ describe('ReactDOMFizzServer', () => {
320
320
</ div > ,
321
321
) ;
322
322
} ) ;
323
+
324
+ // @gate experimental
325
+ it ( 'should allow for two containers to be written to the same document' , async ( ) => {
326
+ // We create two passthrough streams for each container to write into.
327
+ // Notably we don't implement a end() call for these. Because we don't want to
328
+ // close the underlying stream just because one of the streams is done. Instead
329
+ // we manually close when both are done.
330
+ const writableA = new Stream . Writable ( ) ;
331
+ writableA . _write = ( chunk , encoding , next ) => {
332
+ writable . write ( chunk , encoding , next ) ;
333
+ } ;
334
+ const writableB = new Stream . Writable ( ) ;
335
+ writableB . _write = ( chunk , encoding , next ) => {
336
+ writable . write ( chunk , encoding , next ) ;
337
+ } ;
338
+
339
+ writable . write ( '<div id="container-A">' ) ;
340
+ await act ( async ( ) => {
341
+ const { startWriting} = ReactDOMFizzServer . pipeToNodeWritable (
342
+ < Suspense fallback = { < Text text = "Loading A..." /> } >
343
+ < Text text = "This will show A: " />
344
+ < div >
345
+ < AsyncText text = "A" />
346
+ </ div >
347
+ </ Suspense > ,
348
+ writableA ,
349
+ { identifierPrefix : 'A_' } ,
350
+ ) ;
351
+ startWriting ( ) ;
352
+ } ) ;
353
+ writable . write ( '</div>' ) ;
354
+
355
+ writable . write ( '<div id="container-B">' ) ;
356
+ await act ( async ( ) => {
357
+ const { startWriting} = ReactDOMFizzServer . pipeToNodeWritable (
358
+ < Suspense fallback = { < Text text = "Loading B..." /> } >
359
+ < Text text = "This will show B: " />
360
+ < div >
361
+ < AsyncText text = "B" />
362
+ </ div >
363
+ </ Suspense > ,
364
+ writableB ,
365
+ { identifierPrefix : 'B_' } ,
366
+ ) ;
367
+ startWriting ( ) ;
368
+ } ) ;
369
+ writable . write ( '</div>' ) ;
370
+
371
+ expect ( getVisibleChildren ( container ) ) . toEqual ( [
372
+ < div id = "container-A" > Loading A...</ div > ,
373
+ < div id = "container-B" > Loading B...</ div > ,
374
+ ] ) ;
375
+
376
+ await act ( async ( ) => {
377
+ resolveText ( 'B' ) ;
378
+ } ) ;
379
+
380
+ expect ( getVisibleChildren ( container ) ) . toEqual ( [
381
+ < div id = "container-A" > Loading A...</ div > ,
382
+ < div id = "container-B" >
383
+ This will show B: < div > B</ div >
384
+ </ div > ,
385
+ ] ) ;
386
+
387
+ await act ( async ( ) => {
388
+ resolveText ( 'A' ) ;
389
+ } ) ;
390
+
391
+ // We're done writing both streams now.
392
+ writable . end ( ) ;
393
+
394
+ expect ( getVisibleChildren ( container ) ) . toEqual ( [
395
+ < div id = "container-A" >
396
+ This will show A: < div > A</ div >
397
+ </ div > ,
398
+ < div id = "container-B" >
399
+ This will show B: < div > B</ div >
400
+ </ div > ,
401
+ ] ) ;
402
+ } ) ;
323
403
} ) ;
0 commit comments