@@ -104,7 +104,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
104
104
function Foo ( ) {
105
105
ReactNoop . yield ( 'Foo' ) ;
106
106
return (
107
- < Suspense >
107
+ < Suspense fallback = { < Text text = "Loading..." /> } >
108
108
< Bar >
109
109
< AsyncText text = "A" ms = { 100 } />
110
110
< Text text = "B" />
@@ -121,6 +121,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
121
121
'Suspend! [A]' ,
122
122
// But we keep rendering the siblings
123
123
'B' ,
124
+ 'Loading...' ,
124
125
] ) ;
125
126
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
126
127
@@ -193,15 +194,21 @@ describe('ReactSuspenseWithNoopRenderer', () => {
193
194
194
195
it ( 'continues rendering siblings after suspending' , async ( ) => {
195
196
ReactNoop . render (
196
- < Suspense >
197
+ < Suspense fallback = { < Text text = "Loading..." /> } >
197
198
< Text text = "A" />
198
199
< AsyncText text = "B" />
199
200
< Text text = "C" />
200
201
< Text text = "D" />
201
202
</ Suspense > ,
202
203
) ;
203
204
// B suspends. Continue rendering the remaining siblings.
204
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'A' , 'Suspend! [B]' , 'C' , 'D' ] ) ;
205
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [
206
+ 'A' ,
207
+ 'Suspend! [B]' ,
208
+ 'C' ,
209
+ 'D' ,
210
+ 'Loading...' ,
211
+ ] ) ;
205
212
// Did not commit yet.
206
213
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
207
214
@@ -243,7 +250,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
243
250
const errorBoundary = React . createRef ( ) ;
244
251
function App ( ) {
245
252
return (
246
- < Suspense >
253
+ < Suspense fallback = { < Text text = "Loading..." /> } >
247
254
< ErrorBoundary ref = { errorBoundary } >
248
255
< AsyncText text = "Result" ms = { 1000 } />
249
256
</ ErrorBoundary >
@@ -252,7 +259,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
252
259
}
253
260
254
261
ReactNoop . render ( < App /> ) ;
255
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [Result]' ] ) ;
262
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [Result]' , 'Loading...' ] ) ;
256
263
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
257
264
258
265
textResourceShouldFail = true ;
@@ -278,7 +285,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
278
285
errorBoundary . current . reset ( ) ;
279
286
cache . invalidate ( ) ;
280
287
281
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [Result]' ] ) ;
288
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [Result]' , 'Loading...' ] ) ;
282
289
ReactNoop . expire ( 1000 ) ;
283
290
await advanceTimers ( 1000 ) ;
284
291
expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Promise resolved [Result]' , 'Result' ] ) ;
@@ -356,7 +363,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
356
363
it ( 'can update at a higher priority while in a suspended state' , async ( ) => {
357
364
function App ( props ) {
358
365
return (
359
- < Suspense >
366
+ < Suspense fallback = { < Text text = "Loading..." /> } >
360
367
< Text text = { props . highPri } />
361
368
< AsyncText text = { props . lowPri } />
362
369
</ Suspense >
@@ -376,6 +383,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
376
383
'A' ,
377
384
// Suspends
378
385
'Suspend! [2]' ,
386
+ 'Loading...' ,
379
387
] ) ;
380
388
381
389
// While we're still waiting for the low-pri update to complete, update the
@@ -395,21 +403,21 @@ describe('ReactSuspenseWithNoopRenderer', () => {
395
403
it ( 'keeps working on lower priority work after being pinged' , async ( ) => {
396
404
function App ( props ) {
397
405
return (
398
- < Suspense >
406
+ < Suspense fallback = { < Text text = "Loading..." /> } >
399
407
< AsyncText text = "A" />
400
408
{ props . showB && < Text text = "B" /> }
401
409
</ Suspense >
402
410
) ;
403
411
}
404
412
405
413
ReactNoop . render ( < App showB = { false } /> ) ;
406
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [A]' ] ) ;
414
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [A]' , 'Loading...' ] ) ;
407
415
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
408
416
409
417
// Advance React's virtual time by enough to fall into a new async bucket.
410
418
ReactNoop . expire ( 1200 ) ;
411
419
ReactNoop . render ( < App showB = { true } /> ) ;
412
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [A]' , 'B' ] ) ;
420
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [A]' , 'B' , 'Loading...' ] ) ;
413
421
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
414
422
415
423
await advanceTimers ( 0 ) ;
@@ -676,13 +684,17 @@ describe('ReactSuspenseWithNoopRenderer', () => {
676
684
677
685
it ( 'a Suspense component correctly handles more than one suspended child' , async ( ) => {
678
686
ReactNoop . render (
679
- < Suspense maxDuration = { 0 } >
687
+ < Suspense maxDuration = { 0 } fallback = { < Text text = "Loading..." /> } >
680
688
< AsyncText text = "A" ms = { 100 } />
681
689
< AsyncText text = "B" ms = { 100 } />
682
690
</ Suspense > ,
683
691
) ;
684
- expect ( ReactNoop . expire ( 10000 ) ) . toEqual ( [ 'Suspend! [A]' , 'Suspend! [B]' ] ) ;
685
- expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
692
+ expect ( ReactNoop . expire ( 10000 ) ) . toEqual ( [
693
+ 'Suspend! [A]' ,
694
+ 'Suspend! [B]' ,
695
+ 'Loading...' ,
696
+ ] ) ;
697
+ expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 'Loading...' ) ] ) ;
686
698
687
699
await advanceTimers ( 100 ) ;
688
700
@@ -722,7 +734,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
722
734
it ( 'starts working on an update even if its priority falls between two suspended levels' , async ( ) => {
723
735
function App ( props ) {
724
736
return (
725
- < Suspense maxDuration = { 10000 } >
737
+ < Suspense fallback = { < Text text = "Loading..." /> } maxDuration = { 10000 } >
726
738
{ props . text === 'C' ? (
727
739
< Text text = "C" />
728
740
) : (
@@ -735,7 +747,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
735
747
// Schedule an update
736
748
ReactNoop . render ( < App text = "A" /> ) ;
737
749
// The update should suspend.
738
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [A]' ] ) ;
750
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [A]' , 'Loading...' ] ) ;
739
751
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
740
752
741
753
// Advance time until right before it expires. This number may need to
@@ -748,7 +760,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
748
760
// Schedule another low priority update.
749
761
ReactNoop . render ( < App text = "B" /> ) ;
750
762
// This update should also suspend.
751
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [B]' ] ) ;
763
+ expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Suspend! [B]' , 'Loading...' ] ) ;
752
764
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ ] ) ;
753
765
754
766
// Schedule a high priority update. Its expiration time will fall between
0 commit comments