@samitouri / QOS-React / commits / a960d18bc7

eliminate unnecessary do-while loop in renderRoot() (#13087)

Nathan Quarles committed Jun 21, 2018 at 13:52 UTC a960d18bc76dfd2528536651efcd1b646d7d882f
1 file changed +42 -45
packages/react-reconciler/src/ReactFiberScheduler.js
+42 -45
@@ -1011,54 +1011,52 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void {
1011
1012 startWorkLoopTimer(nextUnitOfWork);
1013
1014 - do {
1015 - try {
1016 - workLoop(isYieldy);
1017 - } catch (thrownValue) {
1018 - if (enableProfilerTimer) {
1019 - // Stop "base" render timer in the event of an error.
1020 - stopBaseRenderTimerIfRunning();
1014 + try {
1015 + workLoop(isYieldy);
1016 + } catch (thrownValue) {
1017 + if (enableProfilerTimer) {
1018 + // Stop "base" render timer in the event of an error.
1019 + stopBaseRenderTimerIfRunning();
1020 + }
1021 +
1022 + if (nextUnitOfWork === null) {
1023 + // This is a fatal error.
1024 + didFatal = true;
1025 + onUncaughtError(thrownValue);
1026 + } else {
1027 + if (__DEV__) {
1028 + // Reset global debug state
1029 + // We assume this is defined in DEV
1030 + (resetCurrentlyProcessingQueue: any)();
1031 }
1032
1023 - if (nextUnitOfWork === null) {
1024 - // This is a fatal error.
1033 + const failedUnitOfWork: Fiber = nextUnitOfWork;
1034 + if (__DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
1035 + replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
1036 + }
1037 +
1038 + // TODO: we already know this isn't true in some cases.
1039 + // At least this shows a nicer error message until we figure out the cause.
1040 + // https://github.com/facebook/react/issues/12449#issuecomment-386727431
1041 + invariant(
1042 + nextUnitOfWork !== null,
1043 + 'Failed to replay rendering after an error. This ' +
1044 + 'is likely caused by a bug in React. Please file an issue ' +
1045 + 'with a reproducing case to help us find it.',
1046 + );
1047 +
1048 + const sourceFiber: Fiber = nextUnitOfWork;
1049 + let returnFiber = sourceFiber.return;
1050 + if (returnFiber === null) {
1051 + // This is the root. The root could capture its own errors. However,
1052 + // we don't know if it errors before or after we pushed the host
1053 + // context. This information is needed to avoid a stack mismatch.
1054 + // Because we're not sure, treat this as a fatal error. We could track
1055 + // which phase it fails in, but doesn't seem worth it. At least
1056 + // for now.
1057 didFatal = true;
1058 onUncaughtError(thrownValue);
1059 } else {
1028 - if (__DEV__) {
1029 - // Reset global debug state
1030 - // We assume this is defined in DEV
1031 - (resetCurrentlyProcessingQueue: any)();
1032 - }
1033 -
1034 - const failedUnitOfWork: Fiber = nextUnitOfWork;
1035 - if (__DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
1036 - replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
1037 - }
1038 -
1039 - // TODO: we already know this isn't true in some cases.
1040 - // At least this shows a nicer error message until we figure out the cause.
1041 - // https://github.com/facebook/react/issues/12449#issuecomment-386727431
1042 - invariant(
1043 - nextUnitOfWork !== null,
1044 - 'Failed to replay rendering after an error. This ' +
1045 - 'is likely caused by a bug in React. Please file an issue ' +
1046 - 'with a reproducing case to help us find it.',
1047 - );
1048 -
1049 - const sourceFiber: Fiber = nextUnitOfWork;
1050 - let returnFiber = sourceFiber.return;
1051 - if (returnFiber === null) {
1052 - // This is the root. The root could capture its own errors. However,
1053 - // we don't know if it errors before or after we pushed the host
1054 - // context. This information is needed to avoid a stack mismatch.
1055 - // Because we're not sure, treat this as a fatal error. We could track
1056 - // which phase it fails in, but doesn't seem worth it. At least
1057 - // for now.
1058 - didFatal = true;
1059 - onUncaughtError(thrownValue);
1060 - break;
1061 - }
1060 throwException(
1061 root,
1062 returnFiber,
@@ -1069,8 +1067,7 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void {
1067 nextUnitOfWork = completeUnitOfWork(sourceFiber);
1068 }
1069 }
1072 - break;
1073 - } while (true);
1070 + }
1071
1072 // We're done performing work. Time to clean up.
1073 isWorking = false;