@samitouri / QOS-React / commits / ef14324441

Remove unscheduleWork

We can use the existing unscheduling logic in findNextUnitOfWork.

Andrew Clark committed Nov 4, 2016 at 17:37 UTC ef143244414edda081ef724480408bbb427e81fa
1 file changed +11 -52
src/renderers/shared/fiber/ReactFiberScheduler.js
+11 -52
@@ -101,6 +101,9 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
101 let activeErrorBoundaries : Set<Fiber> | null = null;
102 let nextTrappedErrors : Array<TrappedError> | null = null;
103
104 + // Roots that have uncaught errors and should not be worked on
105 + let rootsWithUncaughtErrors : Set<FiberRoot> | null = null;
106 +
107 function scheduleAnimationCallback(callback) {
108 if (!isAnimationCallbackScheduled) {
109 isAnimationCallbackScheduled = true;
@@ -116,8 +119,11 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
119 }
120
121 function findNextUnitOfWork() {
119 - // Clear out roots with no more work on them.
120 - while (nextScheduledRoot && nextScheduledRoot.current.pendingWorkPriority === NoWork) {
122 + // Clear out roots with no more work on them, or if they have uncaught errors
123 + while (nextScheduledRoot && (
124 + nextScheduledRoot.current.pendingWorkPriority === NoWork ||
125 + (rootsWithUncaughtErrors && rootsWithUncaughtErrors.has(nextScheduledRoot))
126 + )) {
127 // Unschedule this root.
128 nextScheduledRoot.isScheduled = false;
129 // Read the next pointer now.
@@ -539,7 +545,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
545 // If we find unhandled errors, we'll only remember the first one.
546 let firstUncaughtError = null;
547 // Keep track of which roots have fataled and need to be unscheduled.
542 - const rootsWithUncaughtErrors = new Set();
548 + rootsWithUncaughtErrors = new Set();
549
550 // All work created by error boundaries should have Task priority
551 // so that it finishes before this function exits.
@@ -567,7 +573,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
573 // unusual if we end up here. Since we assume this function always
574 // unschedules failed roots, our only resort is to completely
575 // unschedule all roots. Otherwise we may get into an infinite loop
570 - // trying to resume work and finding the failing but unknown root again.
576 + // trying to resume work and finding the failing but unknown root again.
577 nextScheduledRoot = null;
578 lastScheduledRoot = null;
579 }
@@ -607,14 +613,9 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
613 }
614 }
615
610 - // Unschedule the roots that fataled so that we can later schedule
611 - // other updates to the same roots and potentially replace them.
612 - if (rootsWithUncaughtErrors.size) {
613 - unscheduleWork(rootsWithUncaughtErrors);
614 - }
615 -
616 nextTrappedErrors = null;
617 activeErrorBoundaries = null;
618 + rootsWithUncaughtErrors = null;
619 priorityContext = previousPriorityContext;
620
621 // Return the error so we can rethrow after handling other roots.
@@ -677,48 +678,6 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
678 });
679 }
680
680 - function unscheduleWork(unscheduledRoots : Set<FiberRoot>) {
681 - // New pointers for the new linked list
682 - let newNextScheduledRoot = null;
683 - let newLastScheduledRoot = null;
684 -
685 - // Search for the first first root that should remain scheduled
686 - let root = nextScheduledRoot;
687 - while (root) {
688 - if (unscheduledRoots.has(root)) {
689 - root.isScheduled = false;
690 - // Read the next pointer now.
691 - // We need to clear it in case this root gets scheduled again later.
692 - const next = root.nextScheduledRoot;
693 - root.nextScheduledRoot = null;
694 - root = next;
695 - } else {
696 - newNextScheduledRoot = newNextScheduledRoot || root;
697 - newLastScheduledRoot = root;
698 - break;
699 - }
700 - }
701 -
702 - // Find the other roots that should remain scheduled
703 - while (root) {
704 - const next = root.nextScheduledRoot;
705 - if (next && unscheduledRoots.has(next)) {
706 - // Skip the next root.
707 - next.isScheduled = false;
708 - // Move forward.
709 - root.nextScheduledRoot = next.nextScheduledRoot;
710 - } else {
711 - // Keep the root and move forward.
712 - newLastScheduledRoot = root;
713 - root = next;
714 - }
715 - }
716 -
717 - // We're done filtering
718 - nextScheduledRoot = newNextScheduledRoot;
719 - lastScheduledRoot = newLastScheduledRoot;
720 - }
721 -
681 function scheduleWork(root : FiberRoot) {
682 let priorityLevel = priorityContext;
683