Skip to content

Commit 470e4ef

Browse files
author
Brian Vaughn
committed
Implemented Profiler onCommit() and onPostCommit() hooks
1 parent f727803 commit 470e4ef

File tree

6 files changed

+2721
-1059
lines changed

6 files changed

+2721
-1059
lines changed

packages/react-reconciler/src/ReactFiber.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,8 @@ function createFiberFromProfiler(
815815
key: null | string,
816816
): Fiber {
817817
if (__DEV__) {
818-
if (
819-
typeof pendingProps.id !== 'string' ||
820-
typeof pendingProps.onRender !== 'function'
821-
) {
822-
console.error(
823-
'Profiler must specify an "id" string and "onRender" function as props',
824-
);
818+
if (typeof pendingProps.id !== 'string') {
819+
console.error('Profiler must specify an "id" as a prop');
825820
}
826821
}
827822

@@ -831,6 +826,13 @@ function createFiberFromProfiler(
831826
fiber.type = REACT_PROFILER_TYPE;
832827
fiber.expirationTime = expirationTime;
833828

829+
if (enableProfilerTimer) {
830+
fiber.stateNode = {
831+
effectDuration: 0,
832+
passiveEffectDuration: 0,
833+
};
834+
}
835+
834836
return fiber;
835837
}
836838

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ function updateProfiler(
577577
) {
578578
if (enableProfilerTimer) {
579579
workInProgress.effectTag |= Update;
580+
581+
// Reset effect durations for the next eventual effect phase.
582+
// These are reset during render to allow the DevTools commit hook a chance to read them,
583+
const stateNode = workInProgress.stateNode;
584+
stateNode.effectDuration = 0;
585+
stateNode.passiveEffectDuration = 0;
580586
}
581587
const nextProps = workInProgress.pendingProps;
582588
const nextChildren = nextProps.children;
@@ -2974,6 +2980,12 @@ function beginWork(
29742980
if (hasChildWork) {
29752981
workInProgress.effectTag |= Update;
29762982
}
2983+
2984+
// Reset effect durations for the next eventual effect phase.
2985+
// These are reset during render to allow the DevTools commit hook a chance to read them,
2986+
const stateNode = workInProgress.stateNode;
2987+
stateNode.effectDuration = 0;
2988+
stateNode.passiveEffectDuration = 0;
29772989
}
29782990
break;
29792991
case SuspenseComponent: {

0 commit comments

Comments
 (0)