GeezerVison is showing github.com — Remove `didTimeout` check from work loop · react/react@3f8115c
File treeExpand file treeCollapse file tree Open diff view settings packages/react-reconciler/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +1-14Lines changed: 1 addition & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -754,7 +754,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) { | 754 | 754 |
| 755 | 755 | // This is the entry point for every concurrent task, i.e. anything that | 756 | 756 | // goes through Scheduler. | 757 | | -function performConcurrentWorkOnRoot(root, didTimeout) { | | 757 | +function performConcurrentWorkOnRoot(root) { | 758 | 758 | // Since we know we're in a React event, we can clear the current | 759 | 759 | // event time. The next update will compute a new event time. | 760 | 760 | currentEventTime = NoTimestamp; | @@ -794,19 +794,6 @@ function performConcurrentWorkOnRoot(root, didTimeout) { | 794 | 794 | return null; | 795 | 795 | } | 796 | 796 |
| 797 | | - // TODO: We only check `didTimeout` defensively, to account for a Scheduler | 798 | | - // bug where `shouldYield` sometimes returns `true` even if `didTimeout` is | 799 | | - // true, which leads to an infinite loop. Once the bug in Scheduler is | 800 | | - // fixed, we can remove this, since we track expiration ourselves. | 801 | | - if (didTimeout) { | 802 | | - // Something expired. Flush synchronously until there's no expired | 803 | | - // work left. | 804 | | - markRootExpired(root, lanes); | 805 | | - // This will schedule a synchronous callback. | 806 | | - ensureRootIsScheduled(root, now()); | 807 | | - return null; | 808 | | - } | 809 | | - | 810 | 797 | let exitStatus = renderRootConcurrent(root, lanes); | 811 | 798 |
| 812 | 799 | if ( | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.old.js +1-14Lines changed: 1 addition & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -741,7 +741,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) { | 741 | 741 |
| 742 | 742 | // This is the entry point for every concurrent task, i.e. anything that | 743 | 743 | // goes through Scheduler. | 744 | | -function performConcurrentWorkOnRoot(root, didTimeout) { | | 744 | +function performConcurrentWorkOnRoot(root) { | 745 | 745 | // Since we know we're in a React event, we can clear the current | 746 | 746 | // event time. The next update will compute a new event time. | 747 | 747 | currentEventTime = NoTimestamp; | @@ -781,19 +781,6 @@ function performConcurrentWorkOnRoot(root, didTimeout) { | 781 | 781 | return null; | 782 | 782 | } | 783 | 783 |
| 784 | | - // TODO: We only check `didTimeout` defensively, to account for a Scheduler | 785 | | - // bug where `shouldYield` sometimes returns `true` even if `didTimeout` is | 786 | | - // true, which leads to an infinite loop. Once the bug in Scheduler is | 787 | | - // fixed, we can remove this, since we track expiration ourselves. | 788 | | - if (didTimeout) { | 789 | | - // Something expired. Flush synchronously until there's no expired | 790 | | - // work left. | 791 | | - markRootExpired(root, lanes); | 792 | | - // This will schedule a synchronous callback. | 793 | | - ensureRootIsScheduled(root, now()); | 794 | | - return null; | 795 | | - } | 796 | | - | 797 | 784 | let exitStatus = renderRootConcurrent(root, lanes); | 798 | 785 |
| 799 | 786 | if ( | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -446,8 +446,6 @@ describe( | 446 | 446 | React = require('react'); | 447 | 447 | ReactNoop = require('react-noop-renderer'); | 448 | 448 | Scheduler = require('scheduler'); | 449 | | - | 450 | | - React = require('react'); | 451 | 449 | }); | 452 | 450 |
| 453 | 451 | afterEach(() => { | @@ -531,6 +529,14 @@ describe( | 531 | 529 |
| 532 | 530 | // Expire the task | 533 | 531 | Scheduler.unstable_advanceTime(10000); | | 532 | + // Scheduling a new update is a trick to force the expiration to kick | | 533 | + // in. We don't check if a update has been starved at the beginning of | | 534 | + // working on it, since there's no point — we're already working on it. | | 535 | + // We only check before yielding to the main thread (to avoid starvation | | 536 | + // by other main thread work) or when receiving an update (to avoid | | 537 | + // starvation by incoming updates). | | 538 | + ReactNoop.render(<App />); | | 539 | + | 534 | 540 | // Because the render expired, React should finish the tree without | 535 | 541 | // consulting `shouldYield` again | 536 | 542 | expect(Scheduler).toFlushExpired(['B', 'C']); | |
|