From d75323f65d0f263dd4b0c15cebe987cccf822783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Tue, 3 Dec 2019 10:35:17 -0800 Subject: [PATCH] Remove case that only exists for createBatch (#17506) The comment says this is only needed for createBatch().commit() which doesn't exist anymore. --- .../src/ReactFiberWorkLoop.js | 126 ++++++++---------- 1 file changed, 58 insertions(+), 68 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index 954d646bd789..ad6ff4037edf 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -978,82 +978,72 @@ function performSyncWorkOnRoot(root) { // Check if there's expired work on this root. Otherwise, render at Sync. const lastExpiredTime = root.lastExpiredTime; const expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync; - if (root.finishedExpirationTime === expirationTime) { - // There's already a pending commit at this expiration time. - // TODO: This is poorly factored. This case only exists for the - // batch.commit() API. - commitRoot(root); - } else { - invariant( - (executionContext & (RenderContext | CommitContext)) === NoContext, - 'Should not already be working.', - ); - - flushPassiveEffects(); - - // If the root or expiration time have changed, throw out the existing stack - // and prepare a fresh one. Otherwise we'll continue where we left off. - if ( - root !== workInProgressRoot || - expirationTime !== renderExpirationTime - ) { - prepareFreshStack(root, expirationTime); - startWorkOnPendingInteractions(root, expirationTime); - } + invariant( + (executionContext & (RenderContext | CommitContext)) === NoContext, + 'Should not already be working.', + ); - // If we have a work-in-progress fiber, it means there's still work to do - // in this root. - if (workInProgress !== null) { - const prevExecutionContext = executionContext; - executionContext |= RenderContext; - const prevDispatcher = pushDispatcher(root); - const prevInteractions = pushInteractions(root); - startWorkLoopTimer(workInProgress); + flushPassiveEffects(); - do { - try { - workLoopSync(); - break; - } catch (thrownValue) { - handleError(root, thrownValue); - } - } while (true); - resetContextDependencies(); - executionContext = prevExecutionContext; - popDispatcher(prevDispatcher); - if (enableSchedulerTracing) { - popInteractions(((prevInteractions: any): Set)); - } + // If the root or expiration time have changed, throw out the existing stack + // and prepare a fresh one. Otherwise we'll continue where we left off. + if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) { + prepareFreshStack(root, expirationTime); + startWorkOnPendingInteractions(root, expirationTime); + } - if (workInProgressRootExitStatus === RootFatalErrored) { - const fatalError = workInProgressRootFatalError; - stopInterruptedWorkLoopTimer(); - prepareFreshStack(root, expirationTime); - markRootSuspendedAtTime(root, expirationTime); - ensureRootIsScheduled(root); - throw fatalError; - } + // If we have a work-in-progress fiber, it means there's still work to do + // in this root. + if (workInProgress !== null) { + const prevExecutionContext = executionContext; + executionContext |= RenderContext; + const prevDispatcher = pushDispatcher(root); + const prevInteractions = pushInteractions(root); + startWorkLoopTimer(workInProgress); - if (workInProgress !== null) { - // This is a sync render, so we should have finished the whole tree. - invariant( - false, - 'Cannot commit an incomplete root. This error is likely caused by a ' + - 'bug in React. Please file an issue.', - ); - } else { - // We now have a consistent tree. Because this is a sync render, we - // will commit it even if something suspended. - stopFinishedWorkLoopTimer(); - root.finishedWork = (root.current.alternate: any); - root.finishedExpirationTime = expirationTime; - finishSyncRender(root, workInProgressRootExitStatus, expirationTime); + do { + try { + workLoopSync(); + break; + } catch (thrownValue) { + handleError(root, thrownValue); } + } while (true); + resetContextDependencies(); + executionContext = prevExecutionContext; + popDispatcher(prevDispatcher); + if (enableSchedulerTracing) { + popInteractions(((prevInteractions: any): Set)); + } - // Before exiting, make sure there's a callback scheduled for the next - // pending level. + if (workInProgressRootExitStatus === RootFatalErrored) { + const fatalError = workInProgressRootFatalError; + stopInterruptedWorkLoopTimer(); + prepareFreshStack(root, expirationTime); + markRootSuspendedAtTime(root, expirationTime); ensureRootIsScheduled(root); + throw fatalError; } + + if (workInProgress !== null) { + // This is a sync render, so we should have finished the whole tree. + invariant( + false, + 'Cannot commit an incomplete root. This error is likely caused by a ' + + 'bug in React. Please file an issue.', + ); + } else { + // We now have a consistent tree. Because this is a sync render, we + // will commit it even if something suspended. + stopFinishedWorkLoopTimer(); + root.finishedWork = (root.current.alternate: any); + root.finishedExpirationTime = expirationTime; + finishSyncRender(root, workInProgressRootExitStatus, expirationTime); + } + + // Before exiting, make sure there's a callback scheduled for the next + // pending level. + ensureRootIsScheduled(root); } return null;