()
| 13908 | } |
| 13909 | |
| 13910 | function findHighestPriorityRoot() { |
| 13911 | var highestPriorityWork = NoWork; |
| 13912 | var highestPriorityRoot = null; |
| 13913 | if (lastScheduledRoot !== null) { |
| 13914 | var previousScheduledRoot = lastScheduledRoot; |
| 13915 | var root = firstScheduledRoot; |
| 13916 | while (root !== null) { |
| 13917 | var remainingExpirationTime = root.remainingExpirationTime; |
| 13918 | if (remainingExpirationTime === NoWork) { |
| 13919 | // This root no longer has work. Remove it from the scheduler. |
| 13920 | |
| 13921 | // TODO: This check is redudant, but Flow is confused by the branch |
| 13922 | // below where we set lastScheduledRoot to null, even though we break |
| 13923 | // from the loop right after. |
| 13924 | !(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; |
| 13925 | if (root === root.nextScheduledRoot) { |
| 13926 | // This is the only root in the list. |
| 13927 | root.nextScheduledRoot = null; |
| 13928 | firstScheduledRoot = lastScheduledRoot = null; |
| 13929 | break; |
| 13930 | } else if (root === firstScheduledRoot) { |
| 13931 | // This is the first root in the list. |
| 13932 | var next = root.nextScheduledRoot; |
| 13933 | firstScheduledRoot = next; |
| 13934 | lastScheduledRoot.nextScheduledRoot = next; |
| 13935 | root.nextScheduledRoot = null; |
| 13936 | } else if (root === lastScheduledRoot) { |
| 13937 | // This is the last root in the list. |
| 13938 | lastScheduledRoot = previousScheduledRoot; |
| 13939 | lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; |
| 13940 | root.nextScheduledRoot = null; |
| 13941 | break; |
| 13942 | } else { |
| 13943 | previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; |
| 13944 | root.nextScheduledRoot = null; |
| 13945 | } |
| 13946 | root = previousScheduledRoot.nextScheduledRoot; |
| 13947 | } else { |
| 13948 | if (highestPriorityWork === NoWork || remainingExpirationTime < highestPriorityWork) { |
| 13949 | // Update the priority, if it's higher |
| 13950 | highestPriorityWork = remainingExpirationTime; |
| 13951 | highestPriorityRoot = root; |
| 13952 | } |
| 13953 | if (root === lastScheduledRoot) { |
| 13954 | break; |
| 13955 | } |
| 13956 | previousScheduledRoot = root; |
| 13957 | root = root.nextScheduledRoot; |
| 13958 | } |
| 13959 | } |
| 13960 | } |
| 13961 | |
| 13962 | // If the next root is the same as the previous root, this is a nested |
| 13963 | // update. To prevent an infinite loop, increment the nested update count. |
| 13964 | var previousFlushedRoot = nextFlushedRoot; |
| 13965 | if (previousFlushedRoot !== null && previousFlushedRoot === highestPriorityRoot && highestPriorityWork === Sync) { |
| 13966 | nestedUpdateCount++; |
| 13967 | } else { |
no test coverage detected