@@ -663,6 +663,53 @@ describe('ReactSuspense', () => {
663
663
expect ( root ) . toMatchRenderedOutput ( 'new value' ) ;
664
664
} ) ;
665
665
666
+ // @gate enableSuspenseLayoutEffectSemantics
667
+ fit ( 're-fires layout effects when re-showing Suspense' , ( ) => {
668
+ function TextWithLayout ( props ) {
669
+ Scheduler . unstable_yieldValue ( props . text ) ;
670
+ React . useLayoutEffect ( ( ) => {
671
+ Scheduler . unstable_yieldValue ( 'create layout' ) ;
672
+ return ( ) => {
673
+ Scheduler . unstable_yieldValue ( 'destroy layout' ) ;
674
+ } ;
675
+ } , [ ] ) ;
676
+ return props . text ;
677
+ }
678
+
679
+ let _setShow ;
680
+ function App ( props ) {
681
+ const [ show , setShow ] = React . useState ( false ) ;
682
+ _setShow = setShow ;
683
+ return (
684
+ < Suspense fallback = { < Text text = "Loading..." /> } >
685
+ < TextWithLayout text = "Child 1" />
686
+ { show && < AsyncText ms = { 1000 } text = "Child 2" /> }
687
+ </ Suspense >
688
+ ) ;
689
+ }
690
+
691
+ const root = ReactTestRenderer . create ( < App /> , {
692
+ unstable_isConcurrent : true ,
693
+ } ) ;
694
+
695
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Child 1' , 'create layout' ] ) ;
696
+ expect ( root ) . toMatchRenderedOutput ( 'Child 1' ) ;
697
+
698
+ ReactTestRenderer . act ( ( ) => {
699
+ _setShow ( true ) ;
700
+ } ) ;
701
+ expect ( Scheduler ) . toHaveYielded ( [
702
+ 'Child 1' ,
703
+ 'Suspend! [Child 2]' ,
704
+ 'Loading...' ,
705
+ 'destroy layout' ,
706
+ ] ) ;
707
+ jest . advanceTimersByTime ( 1000 ) ;
708
+ expect ( Scheduler ) . toHaveYielded ( [ 'Promise resolved [Child 2]' ] ) ;
709
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Child 1' , 'Child 2' , 'create layout' ] ) ;
710
+ expect ( root ) . toMatchRenderedOutput ( [ 'Child 1' , 'Child 2' ] . join ( '' ) ) ;
711
+ } ) ;
712
+
666
713
describe ( 'outside concurrent mode' , ( ) => {
667
714
it ( 'a mounted class component can suspend without losing state' , ( ) => {
668
715
class TextWithLifecycle extends React . Component {
0 commit comments