Skip to content

Commit

Permalink
Implemented Profiler onCommit() and onPostCommit() hooks (#17910)
Browse files Browse the repository at this point in the history
* Implemented Profiler onCommit() and onPostCommit() hooks
* Added enableProfilerCommitHooks feature flag for commit hooks
* Moved onCommit and onPassiveCommit behind separate feature flag
  • Loading branch information
Brian Vaughn committed Mar 5, 2020
1 parent d35f8a5 commit 024a764
Show file tree
Hide file tree
Showing 15 changed files with 2,795 additions and 1,060 deletions.
16 changes: 9 additions & 7 deletions packages/react-reconciler/src/ReactFiber.js
Expand Up @@ -826,13 +826,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 @@ -842,6 +837,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 @@ -580,6 +580,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 @@ -2944,6 +2950,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 024a764

Please sign in to comment.