2355
);
2356
2357
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
2358
- Scheduler.unstable_advanceTime(1000);
2359
- await advanceTimers(1000);
2360
- // Even after a second, we have still not yet flushed the loading state.
2358
+ Scheduler.unstable_advanceTime(100000);
2359
+ await advanceTimers(100000);
2360
+ // Even after lots of time has passed, we have still not yet flushed the
2361
+ // loading state.
2362
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2362
- Scheduler.unstable_advanceTime(1100);
2363
- await advanceTimers(1100);
2364
- // After the timeout, we do show the loading state.
2365
- expect(ReactNoop.getChildren()).toEqual([
2366
- hiddenSpan('A'),
2367
- span('Loading...'),
2368
- ]);
2363
// Later we load the data.
2364
Scheduler.unstable_advanceTime(3000);
2365
await advanceTimers(3000);
2379
}
2380
return (
2381
<Suspense fallback={<Text text="Loading..." />}>
2388
- <AsyncText text={page} ms={5000} />
2382
+ <AsyncText text={page} />
2383
</Suspense>
2384
);
2385
}
2402
});
2403
2404
// Later we load the data.
2411
- Scheduler.unstable_advanceTime(5000);
2412
- await advanceTimers(5000);
2405
+ await resolveText('A');
2406
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
2407
expect(Scheduler).toFlushAndYield(['A']);
2408
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2415
);
2416
2417
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
2425
- Scheduler.unstable_advanceTime(1000);
2426
- await advanceTimers(1000);
2427
- // Even after a second, we have still not yet flushed the loading state.
2418
+ Scheduler.unstable_advanceTime(100000);
2419
+ await advanceTimers(100000);
2420
+ // Even after lots of time has passed, we have still not yet flushed the
2421
+ // loading state.
2422
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2429
- Scheduler.unstable_advanceTime(1100);
2430
- await advanceTimers(1100);
2431
- // After the timeout, we do show the loading state.
2432
- expect(ReactNoop.getChildren()).toEqual([
2433
- hiddenSpan('A'),
2434
- span('Loading...'),
2435
- ]);
2423
});
2424
// Later we load the data.
2438
- Scheduler.unstable_advanceTime(3000);
2439
- await advanceTimers(3000);
2425
+ await resolveText('B');
2426
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
2427
expect(Scheduler).toFlushAndYield(['B']);
2428
expect(ReactNoop.getChildren()).toEqual([span('B')]);
2441
}
2442
return (
2443
<Suspense fallback={<Text text="Loading..." />}>
2458
- <AsyncText text={page} ms={5000} />
2444
+ <AsyncText text={page} />
2445
</Suspense>
2446
);
2447
}
2465
});
2466
2467
// Later we load the data.
2482
- Scheduler.unstable_advanceTime(5000);
2483
- await advanceTimers(5000);
2468
+ await resolveText('A');
2469
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
2470
expect(Scheduler).toFlushAndYield(['A']);
2471
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2478
);
2479
2480
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
2496
- Scheduler.unstable_advanceTime(1000);
2497
- await advanceTimers(1000);
2498
- // Even after a second, we have still not yet flushed the loading state.
2481
+ Scheduler.unstable_advanceTime(100000);
2482
+ await advanceTimers(100000);
2483
+ // Even after lots of time has passed, we have still not yet flushed the
2484
+ // loading state.
2485
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2500
- Scheduler.unstable_advanceTime(1100);
2501
- await advanceTimers(1100);
2502
- // After the timeout, we do show the loading state.
2503
- expect(ReactNoop.getChildren()).toEqual([
2504
- hiddenSpan('A'),
2505
- span('Loading...'),
2506
- ]);
2486
});
2487
// Later we load the data.
2509
- Scheduler.unstable_advanceTime(3000);
2510
- await advanceTimers(3000);
2488
+ await resolveText('B');
2489
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
2490
expect(Scheduler).toFlushAndYield(['B']);
2491
expect(ReactNoop.getChildren()).toEqual([span('B')]);
2498
function App({page}) {
2499
return (
2500
<Suspense fallback={<Text text="Loading..." />}>
2523
- <AsyncText text={page} ms={5000} />
2501
+ <AsyncText text={page} />
2502
</Suspense>
2503
);
2504
}
2513
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
2514
2515
// Later we load the data.
2538
- Scheduler.unstable_advanceTime(5000);
2539
- await advanceTimers(5000);
2516
+ await resolveText('A');
2517
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
2518
expect(Scheduler).toFlushAndYield(['A']);
2519
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2529
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2530
2531
// Later we load the data.
2555
- Scheduler.unstable_advanceTime(3000);
2556
- await advanceTimers(3000);
2532
+ await resolveText('B');
2533
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
2534
expect(Scheduler).toFlushAndYield(['B']);
2535
expect(ReactNoop.getChildren()).toEqual([span('B')]);
2538
React.unstable_startTransition(() => ReactNoop.render(<App page="C" />));
2539
expect(Scheduler).toFlushAndYield(['Suspend! [C]', 'Loading...']);
2540
2565
- // Advance past the current (effectively) infinite timeout.
2566
- // This is enforcing temporary behavior until it's truly infinite.
2541
+ // Even after lots of time has passed, we have still not yet flushed the
2542
+ // loading state.
2543
Scheduler.unstable_advanceTime(100000);
2544
await advanceTimers(100000);
2569
- expect(ReactNoop.getChildren()).toEqual([
2570
- hiddenSpan('B'),
2571
- span('Loading...'),
2572
- ]);
2545
+ expect(ReactNoop.getChildren()).toEqual([span('B')]);
2546
});
2547
2548
// @gate experimental
2556
}
2557
return (
2558
<Suspense fallback={<Text text="Loading..." />}>
2586
- <AsyncText text={page} ms={5000} />
2559
+ <AsyncText text={page} />
2560
</Suspense>
2561
);
2562
}
2576
});
2577
2578
// Later we load the data.
2606
- Scheduler.unstable_advanceTime(5000);
2607
- await advanceTimers(5000);
2579
+ await resolveText('A');
2580
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
2581
expect(Scheduler).toFlushAndYield(['A']);
2582
expect(ReactNoop.getChildren()).toEqual([span('A')]);
2595
});
2596
2597
// Later we load the data.
2626
- Scheduler.unstable_advanceTime(3000);
2627
- await advanceTimers(3000);
2598
+ await resolveText('B');
2599
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
2600
expect(Scheduler).toFlushAndYield(['B']);
2601
expect(ReactNoop.getChildren()).toEqual([span('B')]);
2606
2607
expect(Scheduler).toFlushAndYield(['Suspend! [C]', 'Loading...']);
2608
2638
- // Advance past the current effectively infinite timeout.
2639
- // This is enforcing temporary behavior until it's truly infinite.
2609
+ // Even after lots of time has passed, we have still not yet flushed the
2610
+ // loading state.
2611
Scheduler.unstable_advanceTime(100000);
2612
await advanceTimers(100000);
2642
- expect(ReactNoop.getChildren()).toEqual([
2643
- hiddenSpan('B'),
2644
- span('Loading...'),
2645
- ]);
2613
+ expect(ReactNoop.getChildren()).toEqual([span('B')]);
2614
});
2615
});
2616
2679
2680
expect(Scheduler).toFlushAndYield(['Suspend! [C]', 'Loading...']);
2681
2714
- // Advance past the current effectively infinite timeout.
2715
- // This is enforcing temporary behavior until it's truly infinite.
2682
+ // Even after lots of time has passed, we have still not yet flushed the
2683
+ // loading state.
2684
Scheduler.unstable_advanceTime(100000);
2685
await advanceTimers(100000);
2718
- expect(ReactNoop.getChildren()).toEqual([
2719
- hiddenSpan('B'),
2720
- span('Loading...'),
2721
- ]);
2686
+ expect(ReactNoop.getChildren()).toEqual([span('B')]);
2687
});
2688
});
2689
});
2750
);
2751
expect(Scheduler).toFlushAndYield(['B', 'Suspend! [C]', 'Loading...']);
2752
expect(ReactNoop.getChildren()).toEqual([span('B')]);
2788
- Scheduler.unstable_advanceTime(1200);
2789
- await advanceTimers(1200);
2790
- // Even after a second, we have still not yet flushed the loading state.
2791
- expect(ReactNoop.getChildren()).toEqual([span('B')]);
2753
+ // Event after a large amount of time, we never show a loading state.
2754
Scheduler.unstable_advanceTime(60000);
2755
await advanceTimers(60000);
2794
- // After the timeout we show the loading state.
2795
- expect(ReactNoop.getChildren()).toEqual([
2796
- hiddenSpan('B'),
2797
- span('Loading...'),
2798
- ]);
2756
+ expect(ReactNoop.getChildren()).toEqual([span('B')]);
2757
});
2758
2759
// @gate experimental
2802
- it('withSuspenseConfig timeout applies when we use an updated avoided boundary', async () => {
2760
+ it('withSuspenseConfig delay applies when we use an updated avoided boundary', async () => {
2761
function App({page}) {
2762
return (
2763
<Suspense fallback={<Text text="Loading..." />}>
2765
<Suspense
2766
fallback={<Text text={'Loading ' + page + '...'} />}
2767
unstable_avoidThisFallback={true}>
2810
- <AsyncText text={page} ms={3000} />
2768
+ <AsyncText text={page} />
2769
</Suspense>
2770
</Suspense>
2771
);
2774
// Initial render.
2775
ReactNoop.render(<App page="A" />);
2776
expect(Scheduler).toFlushAndYield(['Hi!', 'Suspend! [A]', 'Loading...']);
2819
- Scheduler.unstable_advanceTime(3000);
2820
- await advanceTimers(3000);
2777
+ await resolveText('A');
2778
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
2779
expect(Scheduler).toFlushAndYield(['Hi!', 'A']);
2780
expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
2794
expect(Scheduler).toFlushAndYield([]);
2795
// We should still be suspended here because this loading state should be avoided.
2796
expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
2840
- Scheduler.unstable_advanceTime(1500);
2841
- await advanceTimers(1500);
2797
+ await resolveText('B');
2798
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
2843
- expect(ReactNoop.getChildren()).toEqual([
2844
- span('Hi!'),
2845
- hiddenSpan('A'),
2846
- span('Loading B...'),
2847
- ]);
2799
+ expect(Scheduler).toFlushAndYield(['Hi!', 'B']);
2800
+ expect(ReactNoop).toMatchRenderedOutput(
2801
+ <>
2802
+ <span prop="Hi!" />
2803
+ <span prop="B" />
2804
+ </>,
2805
+ );
2806
});
2807
2808
// @gate experimental
2851
- it('withSuspenseConfig timeout applies when we use a newly created avoided boundary', async () => {
2809
+ it('withSuspenseConfig delay applies when we use a newly created avoided boundary', async () => {
2810
function App({page}) {
2811
return (
2812
<Suspense fallback={<Text text="Loading..." />}>
2817
<Suspense
2818
fallback={<Text text={'Loading ' + page + '...'} />}
2819
unstable_avoidThisFallback={true}>
2862
- <AsyncText text={page} ms={3000} />
2820
+ <AsyncText text={page} />
2821
</Suspense>
2822
)}
2823
</Suspense>
2843
await advanceTimers(1800);
2844
expect(Scheduler).toFlushAndYield([]);
2845
// We should still be suspended here because this loading state should be avoided.
2888
- expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
2889
- Scheduler.unstable_advanceTime(1500);
2890
- await advanceTimers(1500);
2846
+ expect(ReactNoop).toMatchRenderedOutput(
2847
+ <>
2848
+ <span prop="Hi!" />
2849
+ <span prop="A" />
2850
+ </>,
2851
+ );
2852
+ await resolveText('B');
2853
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
2892
- expect(ReactNoop.getChildren()).toEqual([
2893
- span('Hi!'),
2894
- span('Loading B...'),
2895
- ]);
2854
+ expect(Scheduler).toFlushAndYield(['Hi!', 'B']);
2855
+ expect(ReactNoop).toMatchRenderedOutput(
2856
+ <>
2857
+ <span prop="Hi!" />
2858
+ <span prop="B" />
2859
+ </>,
2860
+ );
2861
});
2862
2863
// @gate experimental
3899
</>,
3900
);
3901
3937
- // Commit the placeholder
3938
- Scheduler.unstable_advanceTime(20000);
3939
- await advanceTimers(20000);
3940
-
3941
- expect(root).toMatchRenderedOutput(
3942
- <>
3943
- <span hidden={true} prop="A1" />
3944
- <span prop="Loading..." />
3945
- <span hidden={true} prop="B" />
3946
- <span prop="Loading..." />
3947
- </>,
3948
- );
3902
+ await resolveText('A2');
3903
+ await resolveText('B2');
3904
});
3905
+ expect(Scheduler).toHaveYielded([
3906
+ 'Promise resolved [A2]',
3907
+ 'Promise resolved [B2]',
3908
+ 'A2',
3909
+ 'B2',
3910
+ ]);
3911
+ expect(root).toMatchRenderedOutput(
3912
+ <>
3913
+ <span prop="A2" />
3914
+ <span prop="B2" />
3915
+ </>,
3916
+ );
3917
});
3918
3919
// Regression: https://github.com/facebook/react/issues/18486
3997
// Neither is resolved yet.
3998
'Pending...',
3999
'',
4033
- 'Pending...',
4034
- 'Suspend! [a]',
4035
- 'Loading...',
4000
'Suspend! [b]',
4001
'Loading...',
4002
]);
4014
await resolveText('a');
4015
4016
expect(Scheduler).toHaveYielded(['Promise resolved [a]']);
4053
- expect(Scheduler).toFlushAndYield([
4054
- 'Pending...',
4055
- 'a',
4056
- 'Suspend! [b]',
4057
- 'Loading...',
4058
- ]);
4017
+ expect(Scheduler).toFlushAndYield(['Suspend! [b]', 'Loading...']);
4018
expect(root).toMatchRenderedOutput(
4019
<>
4020
<span prop="Pending..." />
4062
- <span prop="a" />
4021
+ <span prop="" />
4022
</>,
4023
);
4024