Skip to content

Commit 2b8b3fc

Browse files
committed
Test synchronously rerendering should not render more rows
1 parent 1593a1f commit 2b8b3fc

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

Diff for: packages/react-reconciler/src/__tests__/ReactSuspenseList-test.js

+141
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,147 @@ describe('ReactSuspenseList', () => {
25562556
);
25572557
});
25582558

2559+
// @gate experimental
2560+
it('should be able to progressively show CPU expensive rows with two pass rendering', async () => {
2561+
function TwoPass({text}) {
2562+
const [pass, setPass] = React.useState(0);
2563+
React.useLayoutEffect(() => {
2564+
Scheduler.unstable_yieldValue('Mount ' + text);
2565+
setPass(1);
2566+
}, []);
2567+
return <Text text={pass === 0 ? 'First Pass ' + text : text} />;
2568+
}
2569+
2570+
function Sleep({time, children}) {
2571+
Scheduler.unstable_advanceTime(time);
2572+
return children;
2573+
}
2574+
2575+
function App() {
2576+
Scheduler.unstable_yieldValue('App');
2577+
return (
2578+
<SuspenseList revealOrder="forwards" tail="hidden">
2579+
<Suspense fallback={<Text text="Loading A" />}>
2580+
<Sleep time={600}>
2581+
<TwoPass text="A" />
2582+
</Sleep>
2583+
</Suspense>
2584+
<Suspense fallback={<Text text="Loading B" />}>
2585+
<Sleep time={600}>
2586+
<TwoPass text="B" />
2587+
</Sleep>
2588+
</Suspense>
2589+
<Sleep time={600}>
2590+
<Text text="C" />
2591+
</Sleep>
2592+
</SuspenseList>
2593+
);
2594+
}
2595+
2596+
ReactNoop.render(<App />);
2597+
2598+
expect(Scheduler).toFlushAndYieldThrough([
2599+
'App',
2600+
'First Pass A',
2601+
'Mount A',
2602+
'A',
2603+
]);
2604+
expect(ReactNoop).toMatchRenderedOutput(<span>A</span>);
2605+
2606+
expect(Scheduler).toFlushAndYieldThrough(['First Pass B', 'Mount B', 'B']);
2607+
expect(ReactNoop).toMatchRenderedOutput(
2608+
<>
2609+
<span>A</span>
2610+
<span>B</span>
2611+
</>,
2612+
);
2613+
2614+
expect(Scheduler).toFlushAndYield(['C']);
2615+
expect(ReactNoop).toMatchRenderedOutput(
2616+
<>
2617+
<span>A</span>
2618+
<span>B</span>
2619+
<span>C</span>
2620+
</>,
2621+
);
2622+
});
2623+
2624+
// @gate experimental
2625+
it('should be able to progressively show rows with two pass rendering and visible', async () => {
2626+
function TwoPass({text}) {
2627+
const [pass, setPass] = React.useState(0);
2628+
React.useLayoutEffect(() => {
2629+
Scheduler.unstable_yieldValue('Mount ' + text);
2630+
setPass(1);
2631+
}, []);
2632+
return <Text text={pass === 0 ? 'First Pass ' + text : text} />;
2633+
}
2634+
2635+
function Sleep({time, children}) {
2636+
Scheduler.unstable_advanceTime(time);
2637+
return children;
2638+
}
2639+
2640+
function App() {
2641+
Scheduler.unstable_yieldValue('App');
2642+
return (
2643+
<SuspenseList revealOrder="forwards">
2644+
<Suspense fallback={<Text text="Loading A" />}>
2645+
<Sleep time={600}>
2646+
<TwoPass text="A" />
2647+
</Sleep>
2648+
</Suspense>
2649+
<Suspense fallback={<Text text="Loading B" />}>
2650+
<Sleep time={600}>
2651+
<TwoPass text="B" />
2652+
</Sleep>
2653+
</Suspense>
2654+
<Suspense fallback={<Text text="Loading C" />}>
2655+
<Sleep time={600}>
2656+
<Text text="C" />
2657+
</Sleep>
2658+
</Suspense>
2659+
</SuspenseList>
2660+
);
2661+
}
2662+
2663+
ReactNoop.render(<App />);
2664+
2665+
expect(Scheduler).toFlushAndYieldThrough([
2666+
'App',
2667+
'First Pass A',
2668+
'Loading B',
2669+
'Loading C',
2670+
'Mount A',
2671+
'A',
2672+
]);
2673+
expect(ReactNoop).toMatchRenderedOutput(
2674+
<>
2675+
<span>A</span>
2676+
<span>Loading B</span>
2677+
<span>Loading C</span>
2678+
</>,
2679+
);
2680+
2681+
expect(Scheduler).toFlushAndYieldThrough(['First Pass B', 'Mount B', 'B']);
2682+
expect(ReactNoop).toMatchRenderedOutput(
2683+
<>
2684+
<span>A</span>
2685+
<span>B</span>
2686+
<span>Loading C</span>
2687+
</>,
2688+
);
2689+
2690+
expect(Scheduler).toFlushAndYield(['C']);
2691+
expect(ReactNoop).toMatchRenderedOutput(
2692+
<>
2693+
<span>A</span>
2694+
<span>B</span>
2695+
<span>C</span>
2696+
</>,
2697+
);
2698+
});
2699+
25592700
// @gate experimental && enableProfilerTimer
25602701
it('counts the actual duration when profiling a SuspenseList', async () => {
25612702
// Order of parameters: id, phase, actualDuration, treeBaseDuration

0 commit comments

Comments
 (0)