@@ -2222,7 +2222,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
2222
2222
Scheduler . unstable_runWithPriority ( Scheduler . unstable_IdlePriority , ( ) =>
2223
2223
ReactNoop . render ( < Foo renderContent = { 2 } /> ) ,
2224
2224
) ;
2225
- expect ( Scheduler ) . toFlushAndYield ( [ 'Suspend! [A]' , 'Loading A...' ] ) ;
2225
+ // We won't even work on Idle priority.
2226
+ expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
2226
2227
2227
2228
// We're still suspended.
2228
2229
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
@@ -2789,4 +2790,116 @@ describe('ReactSuspenseWithNoopRenderer', () => {
2789
2790
2790
2791
expect ( root ) . toMatchRenderedOutput ( < span prop = "Foo" /> ) ;
2791
2792
} ) ;
2793
+
2794
+ it ( 'should not render hidden content while suspended on higher pri' , async ( ) => {
2795
+ function Offscreen ( ) {
2796
+ Scheduler . unstable_yieldValue ( 'Offscreen' ) ;
2797
+ return 'Offscreen' ;
2798
+ }
2799
+ function App ( { showContent} ) {
2800
+ React . useLayoutEffect ( ( ) => {
2801
+ Scheduler . unstable_yieldValue ( 'Commit' ) ;
2802
+ } ) ;
2803
+ return (
2804
+ < >
2805
+ < div hidden = { true } >
2806
+ < Offscreen />
2807
+ </ div >
2808
+ < Suspense fallback = { < Text text = "Loading..." /> } >
2809
+ { showContent ? < AsyncText text = "A" ms = { 2000 } /> : null }
2810
+ </ Suspense >
2811
+ </ >
2812
+ ) ;
2813
+ }
2814
+
2815
+ // Initial render.
2816
+ ReactNoop . render ( < App showContent = { false } /> ) ;
2817
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'Commit' ] ) ;
2818
+ expect ( ReactNoop ) . toMatchRenderedOutput ( < div hidden = { true } /> ) ;
2819
+
2820
+ // Start transition.
2821
+ React . unstable_withSuspenseConfig (
2822
+ ( ) => {
2823
+ ReactNoop . render ( < App showContent = { true } /> ) ;
2824
+ } ,
2825
+ { timeoutMs : 2000 } ,
2826
+ ) ;
2827
+
2828
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Suspend! [A]' , 'Loading...' ] ) ;
2829
+ Scheduler . unstable_advanceTime ( 2000 ) ;
2830
+ await advanceTimers ( 2000 ) ;
2831
+ expect ( Scheduler ) . toHaveYielded ( [ 'Promise resolved [A]' ] ) ;
2832
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'A' , 'Commit' ] ) ;
2833
+ expect ( ReactNoop ) . toMatchRenderedOutput (
2834
+ < >
2835
+ < div hidden = { true } />
2836
+ < span prop = "A" />
2837
+ </ > ,
2838
+ ) ;
2839
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Offscreen' ] ) ;
2840
+ expect ( ReactNoop ) . toMatchRenderedOutput (
2841
+ < >
2842
+ < div hidden = { true } > Offscreen</ div >
2843
+ < span prop = "A" />
2844
+ </ > ,
2845
+ ) ;
2846
+ } ) ;
2847
+
2848
+ it ( 'should be able to unblock higher pri content before suspended hidden' , async ( ) => {
2849
+ function Offscreen ( ) {
2850
+ Scheduler . unstable_yieldValue ( 'Offscreen' ) ;
2851
+ return 'Offscreen' ;
2852
+ }
2853
+ function App ( { showContent} ) {
2854
+ React . useLayoutEffect ( ( ) => {
2855
+ Scheduler . unstable_yieldValue ( 'Commit' ) ;
2856
+ } ) ;
2857
+ return (
2858
+ < Suspense fallback = { < Text text = "Loading..." /> } >
2859
+ < div hidden = { true } >
2860
+ < AsyncText text = "A" ms = { 2000 } />
2861
+ < Offscreen />
2862
+ </ div >
2863
+ { showContent ? < AsyncText text = "A" ms = { 2000 } /> : null }
2864
+ </ Suspense >
2865
+ ) ;
2866
+ }
2867
+
2868
+ // Initial render.
2869
+ ReactNoop . render ( < App showContent = { false } /> ) ;
2870
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'Commit' ] ) ;
2871
+ expect ( ReactNoop ) . toMatchRenderedOutput ( < div hidden = { true } /> ) ;
2872
+
2873
+ // Partially render through the hidden content.
2874
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'Suspend! [A]' ] ) ;
2875
+
2876
+ // Start transition.
2877
+ React . unstable_withSuspenseConfig (
2878
+ ( ) => {
2879
+ ReactNoop . render ( < App showContent = { true } /> ) ;
2880
+ } ,
2881
+ { timeoutMs : 5000 } ,
2882
+ ) ;
2883
+
2884
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Suspend! [A]' , 'Loading...' ] ) ;
2885
+ Scheduler . unstable_advanceTime ( 2000 ) ;
2886
+ await advanceTimers ( 2000 ) ;
2887
+ expect ( Scheduler ) . toHaveYielded ( [ 'Promise resolved [A]' ] ) ;
2888
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'A' , 'Commit' ] ) ;
2889
+ expect ( ReactNoop ) . toMatchRenderedOutput (
2890
+ < >
2891
+ < div hidden = { true } />
2892
+ < span prop = "A" />
2893
+ </ > ,
2894
+ ) ;
2895
+ expect ( Scheduler ) . toFlushAndYield ( [ 'A' , 'Offscreen' ] ) ;
2896
+ expect ( ReactNoop ) . toMatchRenderedOutput (
2897
+ < >
2898
+ < div hidden = { true } >
2899
+ < span prop = "A" /> Offscreen
2900
+ </ div >
2901
+ < span prop = "A" />
2902
+ </ > ,
2903
+ ) ;
2904
+ } ) ;
2792
2905
} ) ;
0 commit comments