Skip to content

Commit 328560b

Browse files
author
Brian Vaughn
committed
Implemented Profiler onCommit() and onPostCommit() hooks
1 parent ccab494 commit 328560b

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
@@ -813,13 +813,8 @@ function createFiberFromProfiler(
813813
key: null | string,
814814
): Fiber {
815815
if (__DEV__) {
816-
if (
817-
typeof pendingProps.id !== 'string' ||
818-
typeof pendingProps.onRender !== 'function'
819-
) {
820-
console.error(
821-
'Profiler must specify an "id" string and "onRender" function as props',
822-
);
816+
if (typeof pendingProps.id !== 'string') {
817+
console.error('Profiler must specify an "id" as a prop');
823818
}
824819
}
825820

@@ -829,6 +824,13 @@ function createFiberFromProfiler(
829824
fiber.type = REACT_PROFILER_TYPE;
830825
fiber.expirationTime = expirationTime;
831826

827+
if (enableProfilerTimer) {
828+
fiber.stateNode = {
829+
effectDuration: 0,
830+
passiveEffectDuration: 0,
831+
};
832+
}
833+
832834
return fiber;
833835
}
834836

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,12 @@ function updateProfiler(
587587
) {
588588
if (enableProfilerTimer) {
589589
workInProgress.effectTag |= Update;
590+
591+
// Reset effect durations for the next eventual effect phase.
592+
// These are reset during render to allow the DevTools commit hook a chance to read them,
593+
const stateNode = workInProgress.stateNode;
594+
stateNode.effectDuration = 0;
595+
stateNode.passiveEffectDuration = 0;
590596
}
591597
const nextProps = workInProgress.pendingProps;
592598
const nextChildren = nextProps.children;
@@ -2972,6 +2978,12 @@ function beginWork(
29722978
if (hasChildWork) {
29732979
workInProgress.effectTag |= Update;
29742980
}
2981+
2982+
// Reset effect durations for the next eventual effect phase.
2983+
// These are reset during render to allow the DevTools commit hook a chance to read them,
2984+
const stateNode = workInProgress.stateNode;
2985+
stateNode.effectDuration = 0;
2986+
stateNode.passiveEffectDuration = 0;
29752987
}
29762988
break;
29772989
case SuspenseComponent: {

0 commit comments

Comments
 (0)