Skip to content

Commit

Permalink
Moved actualDuration bubbling to completeUnitOfWork error branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Nov 5, 2018
1 parent 7be6879 commit 37ab9da
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,18 @@ function completeUnitOfWork(workInProgress: Fiber): Fiber | null {
return null;
}
} else {
if (workInProgress.mode & ProfileMode) {
if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
// Record the render duration for the fiber that errored.
stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);

// Include the time spent working on failed children before continuing.
let actualDuration = workInProgress.actualDuration;
let child = workInProgress.child;
while (child !== null) {
actualDuration += child.actualDuration;
child = child.sibling;
}
workInProgress.actualDuration = actualDuration;
}

// This fiber did not complete because something threw. Pop values off
Expand All @@ -1056,19 +1065,6 @@ function completeUnitOfWork(workInProgress: Fiber): Fiber | null {
ReactFiberInstrumentation.debugTool.onCompleteWork(workInProgress);
}

if (enableProfilerTimer) {
// Include the time spent working on failed children before continuing.
if (next.mode & ProfileMode) {
let actualDuration = next.actualDuration;
let child = next.child;
while (child !== null) {
actualDuration += child.actualDuration;
child = child.sibling;
}
next.actualDuration = actualDuration;
}
}

// If completing this work spawned new work, do that next. We'll come
// back here again.
// Since we're restarting, remove anything that is not a host effect
Expand Down Expand Up @@ -1286,16 +1282,6 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void {
// Record the time spent rendering before an error was thrown.
// This avoids inaccurate Profiler durations in the case of a suspended render.
stopProfilerTimerIfRunningAndRecordDelta(nextUnitOfWork, true);

// HACK Also propagate actualDuration for the time spent in the fiber that errored.
// This avoids inaccurate Profiler durations in the case of a suspended render.
// This happens automatically for sync renders, because of resetChildExpirationTime.
if (nextUnitOfWork.mode & ConcurrentMode) {
const returnFiber = nextUnitOfWork.return;
if (returnFiber !== null) {
returnFiber.actualDuration += nextUnitOfWork.actualDuration;
}
}
}

if (__DEV__) {
Expand Down

0 comments on commit 37ab9da

Please sign in to comment.