Remove case that only exists for createBatch (#17506)
The comment says this is only needed for createBatch().commit() which doesn't exist anymore.
Sebastian Markbåge committed
Dec 3, 2019 at 10:35 UTC
d75323f65d0f263dd4b0c15cebe987cccf822783
1 file changed
+58
-68
packages/react-reconciler/src/ReactFiberWorkLoop.js
+58
-68
@@ -978,82 +978,72 @@ function performSyncWorkOnRoot(root) {
978
// Check if there's expired work on this root. Otherwise, render at Sync.
979
const lastExpiredTime = root.lastExpiredTime;
980
const expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
981
- if (root.finishedExpirationTime === expirationTime) {
982
- // There's already a pending commit at this expiration time.
983
- // TODO: This is poorly factored. This case only exists for the
984
- // batch.commit() API.
985
- commitRoot(root);
986
- } else {
987
- invariant(
988
- (executionContext & (RenderContext | CommitContext)) === NoContext,
989
- 'Should not already be working.',
990
- );
991
-
992
- flushPassiveEffects();
993
-
994
- // If the root or expiration time have changed, throw out the existing stack
995
- // and prepare a fresh one. Otherwise we'll continue where we left off.
996
- if (
997
- root !== workInProgressRoot ||
998
- expirationTime !== renderExpirationTime
999
- ) {
1000
- prepareFreshStack(root, expirationTime);
1001
- startWorkOnPendingInteractions(root, expirationTime);
1002
- }
981
+ invariant(
982
+ (executionContext & (RenderContext | CommitContext)) === NoContext,
983
+ 'Should not already be working.',
984
+ );
985
1004
- // If we have a work-in-progress fiber, it means there's still work to do
1005
- // in this root.
1006
- if (workInProgress !== null) {
1007
- const prevExecutionContext = executionContext;
1008
- executionContext |= RenderContext;
1009
- const prevDispatcher = pushDispatcher(root);
1010
- const prevInteractions = pushInteractions(root);
1011
- startWorkLoopTimer(workInProgress);
986
+ flushPassiveEffects();
987
1013
- do {
1014
- try {
1015
- workLoopSync();
1016
- break;
1017
- } catch (thrownValue) {
1018
- handleError(root, thrownValue);
1019
- }
1020
- } while (true);
1021
- resetContextDependencies();
1022
- executionContext = prevExecutionContext;
1023
- popDispatcher(prevDispatcher);
1024
- if (enableSchedulerTracing) {
1025
- popInteractions(((prevInteractions: any): Set<Interaction>));
1026
- }
988
+ // If the root or expiration time have changed, throw out the existing stack
989
+ // and prepare a fresh one. Otherwise we'll continue where we left off.
990
+ if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
991
+ prepareFreshStack(root, expirationTime);
992
+ startWorkOnPendingInteractions(root, expirationTime);
993
+ }
994
1028
- if (workInProgressRootExitStatus === RootFatalErrored) {
1029
- const fatalError = workInProgressRootFatalError;
1030
- stopInterruptedWorkLoopTimer();
1031
- prepareFreshStack(root, expirationTime);
1032
- markRootSuspendedAtTime(root, expirationTime);
1033
- ensureRootIsScheduled(root);
1034
- throw fatalError;
1035
- }
995
+ // If we have a work-in-progress fiber, it means there's still work to do
996
+ // in this root.
997
+ if (workInProgress !== null) {
998
+ const prevExecutionContext = executionContext;
999
+ executionContext |= RenderContext;
1000
+ const prevDispatcher = pushDispatcher(root);
1001
+ const prevInteractions = pushInteractions(root);
1002
+ startWorkLoopTimer(workInProgress);
1003
1037
- if (workInProgress !== null) {
1038
- // This is a sync render, so we should have finished the whole tree.
1039
- invariant(
1040
- false,
1041
- 'Cannot commit an incomplete root. This error is likely caused by a ' +
1042
- 'bug in React. Please file an issue.',
1043
- );
1044
- } else {
1045
- // We now have a consistent tree. Because this is a sync render, we
1046
- // will commit it even if something suspended.
1047
- stopFinishedWorkLoopTimer();
1048
- root.finishedWork = (root.current.alternate: any);
1049
- root.finishedExpirationTime = expirationTime;
1050
- finishSyncRender(root, workInProgressRootExitStatus, expirationTime);
1004
+ do {
1005
+ try {
1006
+ workLoopSync();
1007
+ break;
1008
+ } catch (thrownValue) {
1009
+ handleError(root, thrownValue);
1010
}
1011
+ } while (true);
1012
+ resetContextDependencies();
1013
+ executionContext = prevExecutionContext;
1014
+ popDispatcher(prevDispatcher);
1015
+ if (enableSchedulerTracing) {
1016
+ popInteractions(((prevInteractions: any): Set<Interaction>));
1017
+ }
1018
1053
- // Before exiting, make sure there's a callback scheduled for the next
1054
- // pending level.
1019
+ if (workInProgressRootExitStatus === RootFatalErrored) {
1020
+ const fatalError = workInProgressRootFatalError;
1021
+ stopInterruptedWorkLoopTimer();
1022
+ prepareFreshStack(root, expirationTime);
1023
+ markRootSuspendedAtTime(root, expirationTime);
1024
ensureRootIsScheduled(root);
1025
+ throw fatalError;
1026
}
1027
+
1028
+ if (workInProgress !== null) {
1029
+ // This is a sync render, so we should have finished the whole tree.
1030
+ invariant(
1031
+ false,
1032
+ 'Cannot commit an incomplete root. This error is likely caused by a ' +
1033
+ 'bug in React. Please file an issue.',
1034
+ );
1035
+ } else {
1036
+ // We now have a consistent tree. Because this is a sync render, we
1037
+ // will commit it even if something suspended.
1038
+ stopFinishedWorkLoopTimer();
1039
+ root.finishedWork = (root.current.alternate: any);
1040
+ root.finishedExpirationTime = expirationTime;
1041
+ finishSyncRender(root, workInProgressRootExitStatus, expirationTime);
1042
+ }
1043
+
1044
+ // Before exiting, make sure there's a callback scheduled for the next
1045
+ // pending level.
1046
+ ensureRootIsScheduled(root);
1047
}
1048
1049
return null;