@@ -464,4 +464,62 @@ describe('ReactDOMFizzServer', () => {
464
464
expect ( output1 . result ) . not . toContain ( 'context never found' ) ;
465
465
expect ( output1 . result ) . toContain ( 'OK' ) ;
466
466
} ) ;
467
+
468
+ // @gate experimental
469
+ it ( 'should be able to pop context after suspending' , async ( ) => {
470
+ class DelayClient {
471
+ get ( ) {
472
+ if ( this . resolved ) return this . resolved ;
473
+ if ( this . pending ) return this . pending ;
474
+ return ( this . pending = new Promise ( resolve => {
475
+ setTimeout ( ( ) => {
476
+ delete this . pending ;
477
+ this . resolved = 'OK' ;
478
+ resolve ( ) ;
479
+ } , 500 ) ;
480
+ } ) ) ;
481
+ }
482
+ }
483
+
484
+ const DelayContext = React . createContext ( undefined ) ;
485
+ const Component = ( ) => {
486
+ const client = React . useContext ( DelayContext ) ;
487
+ if ( ! client ) {
488
+ return 'context not found.' ;
489
+ }
490
+ const result = client . get ( ) ;
491
+ if ( typeof result === 'string' ) {
492
+ return result ;
493
+ }
494
+ throw result ;
495
+ } ;
496
+
497
+ const client = new DelayClient ( ) ;
498
+ const { writable, output, completed} = getTestWritable ( ) ;
499
+ ReactDOMFizzServer . renderToPipeableStream (
500
+ < >
501
+ < DelayContext . Provider value = { client } >
502
+ < Suspense fallback = "loading" >
503
+ < Component />
504
+ </ Suspense >
505
+ </ DelayContext . Provider >
506
+ < DelayContext . Provider value = { client } >
507
+ < Suspense fallback = "loading" >
508
+ < Component />
509
+ </ Suspense >
510
+ </ DelayContext . Provider >
511
+ </ > ,
512
+ ) . pipe ( writable ) ;
513
+
514
+ jest . runAllTimers ( ) ;
515
+
516
+ expect ( output . error ) . toBe ( undefined ) ;
517
+ expect ( output . result ) . toContain ( 'loading' ) ;
518
+
519
+ await completed ;
520
+
521
+ expect ( output . error ) . toBe ( undefined ) ;
522
+ expect ( output . result ) . not . toContain ( 'context never found' ) ;
523
+ expect ( output . result ) . toContain ( 'OK' ) ;
524
+ } ) ;
467
525
} ) ;
0 commit comments