Skip to content

Commit

Permalink
Implemented Profiler onCommit() and onPostCommit() hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 25, 2020
1 parent 6faf6f5 commit 30358f6
Show file tree
Hide file tree
Showing 6 changed files with 1,469 additions and 37 deletions.
16 changes: 9 additions & 7 deletions packages/react-reconciler/src/ReactFiber.js
Expand Up @@ -815,13 +815,8 @@ function createFiberFromProfiler(
key: null | string,
): Fiber {
if (__DEV__) {
if (
typeof pendingProps.id !== 'string' ||
typeof pendingProps.onRender !== 'function'
) {
console.error(
'Profiler must specify an "id" string and "onRender" function as props',
);
if (typeof pendingProps.id !== 'string') {
console.error('Profiler must specify an "id" as a prop');
}
}

Expand All @@ -831,6 +826,13 @@ function createFiberFromProfiler(
fiber.type = REACT_PROFILER_TYPE;
fiber.expirationTime = expirationTime;

if (enableProfilerTimer) {
fiber.stateNode = {
effectDuration: 0,
passiveEffectDuration: 0,
};
}

return fiber;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Expand Up @@ -577,6 +577,12 @@ function updateProfiler(
) {
if (enableProfilerTimer) {
workInProgress.effectTag |= Update;

// Reset effect durations for the next eventual effect phase.
// These are reset during render to allow the DevTools commit hook a chance to read them,
const stateNode = workInProgress.stateNode;
stateNode.effectDuration = 0;
stateNode.passiveEffectDuration = 0;
}
const nextProps = workInProgress.pendingProps;
const nextChildren = nextProps.children;
Expand Down Expand Up @@ -2974,6 +2980,12 @@ function beginWork(
if (hasChildWork) {
workInProgress.effectTag |= Update;
}

// Reset effect durations for the next eventual effect phase.
// These are reset during render to allow the DevTools commit hook a chance to read them,
const stateNode = workInProgress.stateNode;
stateNode.effectDuration = 0;
stateNode.passiveEffectDuration = 0;
}
break;
case SuspenseComponent: {
Expand Down

0 comments on commit 30358f6

Please sign in to comment.