()
| 13657 | } |
| 13658 | |
| 13659 | function findHighestPriorityRoot() { |
| 13660 | var highestPriorityWork = NoWork; |
| 13661 | var highestPriorityRoot = null; |
| 13662 | if (lastScheduledRoot !== null) { |
| 13663 | var previousScheduledRoot = lastScheduledRoot; |
| 13664 | var root = firstScheduledRoot; |
| 13665 | while (root !== null) { |
| 13666 | var remainingExpirationTime = root.remainingExpirationTime; |
| 13667 | if (remainingExpirationTime === NoWork) { |
| 13668 | // This root no longer has work. Remove it from the scheduler. |
| 13669 | |
| 13670 | // TODO: This check is redudant, but Flow is confused by the branch |
| 13671 | // below where we set lastScheduledRoot to null, even though we break |
| 13672 | // from the loop right after. |
| 13673 | !(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; |
| 13674 | if (root === root.nextScheduledRoot) { |
| 13675 | // This is the only root in the list. |
| 13676 | root.nextScheduledRoot = null; |
| 13677 | firstScheduledRoot = lastScheduledRoot = null; |
| 13678 | break; |
| 13679 | } else if (root === firstScheduledRoot) { |
| 13680 | // This is the first root in the list. |
| 13681 | var next = root.nextScheduledRoot; |
| 13682 | firstScheduledRoot = next; |
| 13683 | lastScheduledRoot.nextScheduledRoot = next; |
| 13684 | root.nextScheduledRoot = null; |
| 13685 | } else if (root === lastScheduledRoot) { |
| 13686 | // This is the last root in the list. |
| 13687 | lastScheduledRoot = previousScheduledRoot; |
| 13688 | lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; |
| 13689 | root.nextScheduledRoot = null; |
| 13690 | break; |
| 13691 | } else { |
| 13692 | previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; |
| 13693 | root.nextScheduledRoot = null; |
| 13694 | } |
| 13695 | root = previousScheduledRoot.nextScheduledRoot; |
| 13696 | } else { |
| 13697 | if (highestPriorityWork === NoWork || remainingExpirationTime < highestPriorityWork) { |
| 13698 | // Update the priority, if it's higher |
| 13699 | highestPriorityWork = remainingExpirationTime; |
| 13700 | highestPriorityRoot = root; |
| 13701 | } |
| 13702 | if (root === lastScheduledRoot) { |
| 13703 | break; |
| 13704 | } |
| 13705 | previousScheduledRoot = root; |
| 13706 | root = root.nextScheduledRoot; |
| 13707 | } |
| 13708 | } |
| 13709 | } |
| 13710 | |
| 13711 | // If the next root is the same as the previous root, this is a nested |
| 13712 | // update. To prevent an infinite loop, increment the nested update count. |
| 13713 | var previousFlushedRoot = nextFlushedRoot; |
| 13714 | if (previousFlushedRoot !== null && previousFlushedRoot === highestPriorityRoot && highestPriorityWork === Sync) { |
| 13715 | nestedUpdateCount++; |
| 13716 | } else { |
no test coverage detected