11
11
runPlaceholderTests ( 'ReactSuspensePlaceholder (mutation)' , ( ) =>
12
12
require ( 'react-noop-renderer' ) ,
13
13
) ;
14
- runPlaceholderTests ( 'ReactSuspensePlaceholder (persistence)' , ( ) =>
15
- require ( 'react-noop-renderer/persistent' ) ,
16
- ) ;
14
+ // runPlaceholderTests('ReactSuspensePlaceholder (persistence)', () =>
15
+ // require('react-noop-renderer/persistent'),
16
+ // );
17
17
18
18
function runPlaceholderTests ( suiteLabel , loadReactNoop ) {
19
19
let advanceTimeBy ;
@@ -232,32 +232,37 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
232
232
233
233
describe ( 'profiler durations' , ( ) => {
234
234
let App ;
235
- let Fallback ;
236
- let Suspending ;
237
235
let onRender ;
238
236
239
237
beforeEach ( ( ) => {
240
238
// Order of parameters: id, phase, actualDuration, treeBaseDuration
241
239
onRender = jest . fn ( ) ;
242
240
243
- Fallback = ( ) => {
241
+ const Fallback = ( ) => {
244
242
ReactTestRenderer . unstable_yield ( 'Fallback' ) ;
245
- advanceTimeBy ( 5 ) ;
243
+ advanceTimeBy ( 10 ) ;
246
244
return 'Loading...' ;
247
245
} ;
248
246
249
- Suspending = ( ) => {
247
+ const Suspending = ( ) => {
250
248
ReactTestRenderer . unstable_yield ( 'Suspending' ) ;
251
249
advanceTimeBy ( 2 ) ;
252
250
return < AsyncText ms = { 1000 } text = "Loaded" fakeRenderDuration = { 1 } /> ;
253
251
} ;
254
252
253
+ const NonSuspending = ( ) => {
254
+ ReactTestRenderer . unstable_yield ( 'NonSuspending' ) ;
255
+ advanceTimeBy ( 5 ) ;
256
+ return 'NonSuspending' ;
257
+ } ;
258
+
255
259
App = ( ) => {
256
260
ReactTestRenderer . unstable_yield ( 'App' ) ;
257
261
return (
258
262
< Profiler id = "root" onRender = { onRender } >
259
263
< Suspense maxDuration = { 500 } fallback = { < Fallback /> } >
260
264
< Suspending />
265
+ < NonSuspending />
261
266
</ Suspense >
262
267
</ Profiler >
263
268
) ;
@@ -266,30 +271,31 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
266
271
267
272
it ( 'properly accounts for base durations when a suspended times out in a sync tree' , ( ) => {
268
273
const root = ReactTestRenderer . create ( < App /> ) ;
269
- expect ( root . toJSON ( ) ) . toEqual ( 'Loading...' ) ;
274
+ expect ( root . toJSON ( ) ) . toEqual ( [ 'Loading...' ] ) ;
270
275
expect ( onRender ) . toHaveBeenCalledTimes ( 2 ) ;
271
276
272
- // Initial mount should be 3ms–
273
- // 2ms from Suspending, and 1ms from the AsyncText it renders.
274
- expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 3 ) ;
275
- expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 3 ) ;
277
+ // Initial mount should be 8ms–
278
+ // 2ms from Suspending, 1ms from the AsyncText it renders,
279
+ // And 5ms from NonSuspending.
280
+ expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 8 ) ;
281
+ expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 8 ) ;
276
282
277
- // When the fallback UI is displayed, and the origina UI hidden,
278
- // the baseDuration should only include the 5ms spent rendering Fallback,
279
- // but the treeBaseDuration should include that and the 3ms spent in Suspending .
280
- expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 5 ) ;
281
- expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 8 ) ;
283
+ // When the fallback UI is displayed, and the original UI is hidden,
284
+ // the baseDuration should only include the 10ms spent rendering Fallback,
285
+ // but the treeBaseDuration should include that and the 8ms spent in the hidden tree .
286
+ expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 10 ) ;
287
+ expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 18 ) ;
282
288
283
289
jest . advanceTimersByTime ( 1000 ) ;
284
290
285
- expect ( root . toJSON ( ) ) . toEqual ( 'Loaded' ) ;
291
+ expect ( root . toJSON ( ) ) . toEqual ( [ 'Loaded' , 'NonSuspending' ] ) ;
286
292
expect ( onRender ) . toHaveBeenCalledTimes ( 3 ) ;
287
293
288
294
// When the suspending data is resolved and our final UI is rendered,
289
295
// the baseDuration should only include the 1ms re-rendering AsyncText,
290
- // but the treeBaseDuration should include that and the 2ms spent rendering Suspending .
296
+ // but the treeBaseDuration should include the full 8ms spent in the tree .
291
297
expect ( onRender . mock . calls [ 2 ] [ 2 ] ) . toBe ( 1 ) ;
292
- expect ( onRender . mock . calls [ 2 ] [ 3 ] ) . toBe ( 3 ) ;
298
+ expect ( onRender . mock . calls [ 2 ] [ 3 ] ) . toBe ( 8 ) ;
293
299
} ) ;
294
300
295
301
it ( 'properly accounts for base durations when a suspended times out in a concurrent tree' , ( ) => {
@@ -301,6 +307,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
301
307
'App' ,
302
308
'Suspending' ,
303
309
'Suspend! [Loaded]' ,
310
+ 'NonSuspending' ,
304
311
'Fallback' ,
305
312
] ) ;
306
313
expect ( root ) . toMatchRenderedOutput ( null ) ;
@@ -312,19 +319,19 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
312
319
expect ( onRender ) . toHaveBeenCalledTimes ( 1 ) ;
313
320
314
321
// Initial mount only shows the "Loading..." Fallback.
315
- // The treeBaseDuration then should be 5ms spent rendering Fallback,
316
- // but the actualDuration should include that and the 3ms spent in Suspending .
317
- expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 8 ) ;
318
- expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 5 ) ;
322
+ // The treeBaseDuration then should be 10ms spent rendering Fallback,
323
+ // but the actualDuration should also include the 8ms spent rendering the hidden tree .
324
+ expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 18 ) ;
325
+ expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 10 ) ;
319
326
320
- expect ( root ) . toFlushAndYield ( [ 'Suspending' , 'Loaded' ] ) ;
321
- expect ( root ) . toMatchRenderedOutput ( 'Loaded ' ) ;
327
+ expect ( root ) . toFlushAndYield ( [ 'Suspending' , 'Loaded' , 'NonSuspending' ] ) ;
328
+ expect ( root ) . toMatchRenderedOutput ( 'LoadedNonSuspending ' ) ;
322
329
expect ( onRender ) . toHaveBeenCalledTimes ( 2 ) ;
323
330
324
331
// When the suspending data is resolved and our final UI is rendered,
325
- // both times should include the 3ms re-rendering Suspending and AsyncText.
326
- expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 3 ) ;
327
- expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 3 ) ;
332
+ // both times should include the 8ms re-rendering Suspending and AsyncText.
333
+ expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 8 ) ;
334
+ expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 8 ) ;
328
335
} ) ;
329
336
} ) ;
330
337
} ) ;
0 commit comments