|
10 | 10 | 'use strict'; |
11 | 11 |
|
12 | 12 | const React = require('react'); |
| 13 | +const Fragment = React.Fragment; |
13 | 14 | let ReactFeatureFlags = require('shared/ReactFeatureFlags'); |
14 | 15 |
|
15 | 16 | let ReactDOM; |
@@ -659,4 +660,55 @@ describe('ReactDOMFiberAsync', () => { |
659 | 660 | expect(formSubmitted).toBe(true); |
660 | 661 | }); |
661 | 662 | }); |
| 663 | + |
| 664 | + describe('Disable yielding', () => { |
| 665 | + beforeEach(() => { |
| 666 | + jest.resetModules(); |
| 667 | + ReactFeatureFlags = require('shared/ReactFeatureFlags'); |
| 668 | + ReactFeatureFlags.disableYielding = true; |
| 669 | + ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; |
| 670 | + ReactDOM = require('react-dom'); |
| 671 | + Scheduler = require('scheduler'); |
| 672 | + }); |
| 673 | + |
| 674 | + it('wont yield during a render if yielding is disabled', () => { |
| 675 | + class A extends React.Component { |
| 676 | + render() { |
| 677 | + Scheduler.yieldValue('A'); |
| 678 | + return <div>{this.props.children}</div>; |
| 679 | + } |
| 680 | + } |
| 681 | + |
| 682 | + class B extends React.Component { |
| 683 | + render() { |
| 684 | + Scheduler.yieldValue('B'); |
| 685 | + return <div>{this.props.children}</div>; |
| 686 | + } |
| 687 | + } |
| 688 | + |
| 689 | + class C extends React.Component { |
| 690 | + render() { |
| 691 | + Scheduler.yieldValue('C'); |
| 692 | + return <div>{this.props.children}</div>; |
| 693 | + } |
| 694 | + } |
| 695 | + |
| 696 | + let root = ReactDOM.unstable_createRoot(container); |
| 697 | + |
| 698 | + root.render( |
| 699 | + <Fragment> |
| 700 | + <A /> |
| 701 | + <B /> |
| 702 | + <C /> |
| 703 | + </Fragment>, |
| 704 | + ); |
| 705 | + |
| 706 | + expect(Scheduler).toHaveYielded([]); |
| 707 | + |
| 708 | + Scheduler.unstable_flushNumberOfYields(2); |
| 709 | + // Even though we just flushed two yields, we should have rendered |
| 710 | + // everything without yielding when the flag is on. |
| 711 | + expect(Scheduler).toHaveYielded(['A', 'B', 'C']); |
| 712 | + }); |
| 713 | + }); |
662 | 714 | }); |
0 commit comments