GeezerVison is showing github.com — Cleanup tests using runWithPriority. (#20958) · react/react@60182d6
File treeExpand file treeCollapse file tree Open diff view settings react-reconciler/src/__tests__
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,11 @@ let Suspense; | 18 | 18 | let SuspenseList; | 19 | 19 | let act; | 20 | 20 |
| | 21 | +// Copied from ReactFiberLanes. Don't do this! | | 22 | +// This is hard coded directly to avoid needing to import, and | | 23 | +// we'll remove this as we replace runWithPriority with React APIs. | | 24 | +export const IdleLanePriority = 2; | | 25 | + | 21 | 26 | function dispatchMouseEvent(to, from) { | 22 | 27 | if (!to) { | 23 | 28 | to = null; | @@ -623,7 +628,7 @@ describe('ReactDOMServerPartialHydration', () => { | 623 | 628 | expect(span.textContent).toBe('Hello'); | 624 | 629 |
| 625 | 630 | // Schedule an update at idle priority | 626 | | - Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => { | | 631 | + ReactDOM.unstable_runWithPriority(IdleLanePriority, () => { | 627 | 632 | root.render(<App text="Hi" className="hi" />); | 628 | 633 | }); | 629 | 634 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,11 @@ let Scheduler; | 19 | 19 | let Suspense; | 20 | 20 | let act; | 21 | 21 |
| | 22 | +// Copied from ReactFiberLanes. Don't do this! | | 23 | +// This is hard coded directly to avoid needing to import, and | | 24 | +// we'll remove this as we replace runWithPriority with React APIs. | | 25 | +export const IdleLanePriority = 2; | | 26 | + | 22 | 27 | function dispatchMouseHoverEvent(to, from) { | 23 | 28 | if (!to) { | 24 | 29 | to = null; | @@ -96,7 +101,7 @@ function dispatchClickEvent(target) { | 96 | 101 | // and there's no native DOM event that maps to idle priority, so this is a | 97 | 102 | // temporary workaround. Need something like ReactDOM.unstable_IdleUpdates. | 98 | 103 | function TODO_scheduleIdleDOMSchedulerTask(fn) { | 99 | | - Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => { | | 104 | + ReactDOM.unstable_runWithPriority(IdleLanePriority, () => { | 100 | 105 | const prevEvent = window.event; | 101 | 106 | window.event = {type: 'message'}; | 102 | 107 | try { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactExpiration-test.js +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -550,11 +550,7 @@ describe('ReactExpiration', () => { | 550 | 550 | function App() { | 551 | 551 | const [highPri, setHighPri] = useState(0); | 552 | 552 | const [normalPri, setNormalPri] = useState(0); | 553 | | - updateHighPri = () => | 554 | | - Scheduler.unstable_runWithPriority( | 555 | | - Scheduler.unstable_UserBlockingPriority, | 556 | | - () => setHighPri(n => n + 1), | 557 | | - ); | | 553 | + updateHighPri = () => ReactNoop.flushSync(() => setHighPri(n => n + 1)); | 558 | 554 | updateNormalPri = () => setNormalPri(n => n + 1); | 559 | 555 | return ( | 560 | 556 | <> | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js +1-4Lines changed: 1 addition & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3166,10 +3166,7 @@ describe('ReactHooksWithNoopRenderer', () => { | 3166 | 3166 | ]); | 3167 | 3167 |
| 3168 | 3168 | await act(async () => { | 3169 | | - Scheduler.unstable_runWithPriority( | 3170 | | - Scheduler.unstable_UserBlockingPriority, | 3171 | | - transition, | 3172 | | - ); | | 3169 | + transition(); | 3173 | 3170 |
| 3174 | 3171 | expect(Scheduler).toFlushAndYield([ | 3175 | 3172 | 'Before... Pending: true', | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js +4-28Lines changed: 4 additions & 28 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -530,14 +530,8 @@ describe('ReactIncrementalUpdates', () => { | 530 | 530 | Scheduler.unstable_yieldValue('Committed: ' + log); | 531 | 531 | if (log === 'B') { | 532 | 532 | // Right after B commits, schedule additional updates. | 533 | | - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority. | 534 | 533 | ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () => | 535 | | - Scheduler.unstable_runWithPriority( | 536 | | - Scheduler.unstable_UserBlockingPriority, | 537 | | - () => { | 538 | | - pushToLog('C'); | 539 | | - }, | 540 | | - ), | | 534 | + pushToLog('C'), | 541 | 535 | ); | 542 | 536 | setLog(prevLog => prevLog + 'D'); | 543 | 537 | } | @@ -556,14 +550,8 @@ describe('ReactIncrementalUpdates', () => { | 556 | 550 | await ReactNoop.act(async () => { | 557 | 551 | pushToLog('A'); | 558 | 552 |
| 559 | | - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority. | 560 | 553 | ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () => | 561 | | - Scheduler.unstable_runWithPriority( | 562 | | - Scheduler.unstable_UserBlockingPriority, | 563 | | - () => { | 564 | | - pushToLog('B'); | 565 | | - }, | 566 | | - ), | | 554 | + pushToLog('B'), | 567 | 555 | ); | 568 | 556 | }); | 569 | 557 | expect(Scheduler).toHaveYielded([ | @@ -595,14 +583,8 @@ describe('ReactIncrementalUpdates', () => { | 595 | 583 | Scheduler.unstable_yieldValue('Committed: ' + this.state.log); | 596 | 584 | if (this.state.log === 'B') { | 597 | 585 | // Right after B commits, schedule additional updates. | 598 | | - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority. | 599 | 586 | ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () => | 600 | | - Scheduler.unstable_runWithPriority( | 601 | | - Scheduler.unstable_UserBlockingPriority, | 602 | | - () => { | 603 | | - this.pushToLog('C'); | 604 | | - }, | 605 | | - ), | | 587 | + this.pushToLog('C'), | 606 | 588 | ); | 607 | 589 | this.pushToLog('D'); | 608 | 590 | } | @@ -622,14 +604,8 @@ describe('ReactIncrementalUpdates', () => { | 622 | 604 |
| 623 | 605 | await ReactNoop.act(async () => { | 624 | 606 | pushToLog('A'); | 625 | | - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority. | 626 | 607 | ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () => | 627 | | - Scheduler.unstable_runWithPriority( | 628 | | - Scheduler.unstable_UserBlockingPriority, | 629 | | - () => { | 630 | | - pushToLog('B'); | 631 | | - }, | 632 | | - ), | | 608 | + pushToLog('B'), | 633 | 609 | ); | 634 | 610 | }); | 635 | 611 | expect(Scheduler).toHaveYielded([ | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js +4-16Lines changed: 4 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1929,10 +1929,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { | 1929 | 1929 |
| 1930 | 1930 | // TODO: assert toErrorDev() when the warning is implemented again. | 1931 | 1931 | ReactNoop.act(() => { | 1932 | | - Scheduler.unstable_runWithPriority( | 1933 | | - Scheduler.unstable_UserBlockingPriority, | 1934 | | - () => _setShow(true), | 1935 | | - ); | | 1932 | + ReactNoop.flushSync(() => _setShow(true)); | 1936 | 1933 | }); | 1937 | 1934 | }); | 1938 | 1935 |
| @@ -1959,10 +1956,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { | 1959 | 1956 |
| 1960 | 1957 | // TODO: assert toErrorDev() when the warning is implemented again. | 1961 | 1958 | ReactNoop.act(() => { | 1962 | | - Scheduler.unstable_runWithPriority( | 1963 | | - Scheduler.unstable_UserBlockingPriority, | 1964 | | - () => show(), | 1965 | | - ); | | 1959 | + ReactNoop.flushSync(() => show()); | 1966 | 1960 | }); | 1967 | 1961 | }); | 1968 | 1962 |
| @@ -1991,10 +1985,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { | 1991 | 1985 | expect(ReactNoop).toMatchRenderedOutput('Loading...'); | 1992 | 1986 |
| 1993 | 1987 | ReactNoop.act(() => { | 1994 | | - Scheduler.unstable_runWithPriority( | 1995 | | - Scheduler.unstable_UserBlockingPriority, | 1996 | | - () => showB(), | 1997 | | - ); | | 1988 | + ReactNoop.flushSync(() => showB()); | 1998 | 1989 | }); | 1999 | 1990 |
| 2000 | 1991 | expect(Scheduler).toHaveYielded(['Suspend! [A]', 'Suspend! [B]']); | @@ -2025,10 +2016,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { | 2025 | 2016 |
| 2026 | 2017 | // TODO: assert toErrorDev() when the warning is implemented again. | 2027 | 2018 | ReactNoop.act(() => { | 2028 | | - Scheduler.unstable_runWithPriority( | 2029 | | - Scheduler.unstable_UserBlockingPriority, | 2030 | | - () => _setShow(true), | 2031 | | - ); | | 2019 | + ReactNoop.flushSync(() => _setShow(true)); | 2032 | 2020 | }); | 2033 | 2021 | }, | 2034 | 2022 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/useMutableSource-test.internal.js +10-19Lines changed: 10 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1476,13 +1476,10 @@ describe('useMutableSource', () => { | 1476 | 1476 | // read during render will happen to match the latest value. But it should | 1477 | 1477 | // still entangle the updates to prevent the previous update (a1) from | 1478 | 1478 | // rendering by itself. | 1479 | | - Scheduler.unstable_runWithPriority( | 1480 | | - Scheduler.unstable_IdlePriority, | 1481 | | - () => { | 1482 | | - mutateA('a0'); | 1483 | | - mutateB('b0'); | 1484 | | - }, | 1485 | | - ); | | 1479 | + React.unstable_startTransition(() => { | | 1480 | + mutateA('a0'); | | 1481 | + mutateB('b0'); | | 1482 | + }); | 1486 | 1483 | // Finish the current render | 1487 | 1484 | expect(Scheduler).toFlushUntilNextPaint(['c']); | 1488 | 1485 | // a0 will re-render because of the mutation update. But it should show | @@ -1601,12 +1598,9 @@ describe('useMutableSource', () => { | 1601 | 1598 | // Mutate the config. This is at lower priority so that 1) to make sure | 1602 | 1599 | // it doesn't happen to get batched with the in-progress render, and 2) | 1603 | 1600 | // so it doesn't interrupt the in-progress render. | 1604 | | - Scheduler.unstable_runWithPriority( | 1605 | | - Scheduler.unstable_IdlePriority, | 1606 | | - () => { | 1607 | | - source.valueB = '3'; | 1608 | | - }, | 1609 | | - ); | | 1601 | + React.unstable_startTransition(() => { | | 1602 | + source.valueB = '3'; | | 1603 | + }); | 1610 | 1604 |
| 1611 | 1605 | expect(Scheduler).toFlushAndYieldThrough([ | 1612 | 1606 | // The partial render completes | @@ -1698,12 +1692,9 @@ describe('useMutableSource', () => { | 1698 | 1692 | expect(source.listenerCount).toBe(1); | 1699 | 1693 |
| 1700 | 1694 | // Mutate -> schedule update for ComponentA | 1701 | | - Scheduler.unstable_runWithPriority( | 1702 | | - Scheduler.unstable_IdlePriority, | 1703 | | - () => { | 1704 | | - source.value = 'two'; | 1705 | | - }, | 1706 | | - ); | | 1695 | + React.unstable_startTransition(() => { | | 1696 | + source.value = 'two'; | | 1697 | + }); | 1707 | 1698 |
| 1708 | 1699 | // Commit ComponentB -> notice the change and schedule an update for ComponentB | 1709 | 1700 | expect(Scheduler).toFlushAndYield(['a:two', 'b:two']); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactDOMTracing-test.internal.js +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -246,12 +246,8 @@ describe('ReactDOMTracing', () => { | 246 | 246 | Scheduler.unstable_yieldValue('Child:update'); | 247 | 247 | } else { | 248 | 248 | Scheduler.unstable_yieldValue('Child:mount'); | 249 | | - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority. | 250 | 249 | ReactDOM.unstable_runWithPriority(IdleLanePriority, () => | 251 | | - Scheduler.unstable_runWithPriority( | 252 | | - Scheduler.unstable_IdlePriority, | 253 | | - () => setDidMount(true), | 254 | | - ), | | 250 | + setDidMount(true), | 255 | 251 | ); | 256 | 252 | } | 257 | 253 | }, [didMount]); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactProfiler-test.internal.js +7-9Lines changed: 7 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -748,6 +748,7 @@ describe('Profiler', () => { | 748 | 748 | expect(onRender.mock.calls[2][1]).toBe('update'); | 749 | 749 | }); | 750 | 750 |
| | 751 | + // @gate experimental | 751 | 752 | it('is properly distinguish updates and nested-updates when there is more than sync remaining work', () => { | 752 | 753 | loadModules({ | 753 | 754 | enableSchedulerTracing, | @@ -767,15 +768,12 @@ describe('Profiler', () => { | 767 | 768 | const onRender = jest.fn(); | 768 | 769 |
| 769 | 770 | // Schedule low-priority work. | 770 | | - Scheduler.unstable_runWithPriority( | 771 | | - Scheduler.unstable_LowPriority, | 772 | | - () => { | 773 | | - ReactNoop.render( | 774 | | - <React.Profiler id="root" onRender={onRender}> | 775 | | - <Component /> | 776 | | - </React.Profiler>, | 777 | | - ); | 778 | | - }, | | 771 | + React.unstable_startTransition(() => | | 772 | + ReactNoop.render( | | 773 | + <React.Profiler id="root" onRender={onRender}> | | 774 | + <Component /> | | 775 | + </React.Profiler>, | | 776 | + ), | 779 | 777 | ); | 780 | 778 |
| 781 | 779 | // Flush sync work with a nested update | |
|