()
| 13795 | } |
| 13796 | |
| 13797 | function findHighestPriorityRoot() { |
| 13798 | var highestPriorityWork = NoWork; |
| 13799 | var highestPriorityRoot = null; |
| 13800 | if (lastScheduledRoot !== null) { |
| 13801 | var previousScheduledRoot = lastScheduledRoot; |
| 13802 | var root = firstScheduledRoot; |
| 13803 | while (root !== null) { |
| 13804 | var remainingExpirationTime = root.remainingExpirationTime; |
| 13805 | if (remainingExpirationTime === NoWork) { |
| 13806 | // This root no longer has work. Remove it from the scheduler. |
| 13807 | |
| 13808 | // TODO: This check is redudant, but Flow is confused by the branch |
| 13809 | // below where we set lastScheduledRoot to null, even though we break |
| 13810 | // from the loop right after. |
| 13811 | !(previousScheduledRoot !== null && lastScheduledRoot !== null) ? invariant(false, 'Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue.') : void 0; |
| 13812 | if (root === root.nextScheduledRoot) { |
| 13813 | // This is the only root in the list. |
| 13814 | root.nextScheduledRoot = null; |
| 13815 | firstScheduledRoot = lastScheduledRoot = null; |
| 13816 | break; |
| 13817 | } else if (root === firstScheduledRoot) { |
| 13818 | // This is the first root in the list. |
| 13819 | var next = root.nextScheduledRoot; |
| 13820 | firstScheduledRoot = next; |
| 13821 | lastScheduledRoot.nextScheduledRoot = next; |
| 13822 | root.nextScheduledRoot = null; |
| 13823 | } else if (root === lastScheduledRoot) { |
| 13824 | // This is the last root in the list. |
| 13825 | lastScheduledRoot = previousScheduledRoot; |
| 13826 | lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; |
| 13827 | root.nextScheduledRoot = null; |
| 13828 | break; |
| 13829 | } else { |
| 13830 | previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; |
| 13831 | root.nextScheduledRoot = null; |
| 13832 | } |
| 13833 | root = previousScheduledRoot.nextScheduledRoot; |
| 13834 | } else { |
| 13835 | if (highestPriorityWork === NoWork || remainingExpirationTime < highestPriorityWork) { |
| 13836 | // Update the priority, if it's higher |
| 13837 | highestPriorityWork = remainingExpirationTime; |
| 13838 | highestPriorityRoot = root; |
| 13839 | } |
| 13840 | if (root === lastScheduledRoot) { |
| 13841 | break; |
| 13842 | } |
| 13843 | previousScheduledRoot = root; |
| 13844 | root = root.nextScheduledRoot; |
| 13845 | } |
| 13846 | } |
| 13847 | } |
| 13848 | |
| 13849 | // If the next root is the same as the previous root, this is a nested |
| 13850 | // update. To prevent an infinite loop, increment the nested update count. |
| 13851 | var previousFlushedRoot = nextFlushedRoot; |
| 13852 | if (previousFlushedRoot !== null && previousFlushedRoot === highestPriorityRoot && highestPriorityWork === Sync) { |
| 13853 | nestedUpdateCount++; |
| 13854 | } else { |
no test coverage detected