GeezerVison is showing github.com — Implemented Profiler onCommit() and onPostCommit() hooks (#17910) · react/react@024a764
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.js +9-7Lines changed: 9 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -826,13 +826,8 @@ function createFiberFromProfiler( |
826 | 826 | key: null | string, |
827 | 827 | ): Fiber { |
828 | 828 | if (__DEV__) { |
829 | | - if ( |
830 | | - typeof pendingProps.id !== 'string' || |
831 | | - typeof pendingProps.onRender !== 'function' |
832 | | - ) { |
833 | | - console.error( |
834 | | - 'Profiler must specify an "id" string and "onRender" function as props', |
835 | | - ); |
| 829 | + if (typeof pendingProps.id !== 'string') { |
| 830 | + console.error('Profiler must specify an "id" as a prop'); |
836 | 831 | } |
837 | 832 | } |
838 | 833 |
|
@@ -842,6 +837,13 @@ function createFiberFromProfiler( |
842 | 837 | fiber.type = REACT_PROFILER_TYPE; |
843 | 838 | fiber.expirationTime = expirationTime; |
844 | 839 |
|
| 840 | + if (enableProfilerTimer) { |
| 841 | + fiber.stateNode = { |
| 842 | + effectDuration: 0, |
| 843 | + passiveEffectDuration: 0, |
| 844 | + }; |
| 845 | + } |
| 846 | + |
845 | 847 | return fiber; |
846 | 848 | } |
847 | 849 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -580,6 +580,12 @@ function updateProfiler( |
580 | 580 | ) { |
581 | 581 | if (enableProfilerTimer) { |
582 | 582 | workInProgress.effectTag |= Update; |
| 583 | + |
| 584 | + // Reset effect durations for the next eventual effect phase. |
| 585 | + // These are reset during render to allow the DevTools commit hook a chance to read them, |
| 586 | + const stateNode = workInProgress.stateNode; |
| 587 | + stateNode.effectDuration = 0; |
| 588 | + stateNode.passiveEffectDuration = 0; |
583 | 589 | } |
584 | 590 | const nextProps = workInProgress.pendingProps; |
585 | 591 | const nextChildren = nextProps.children; |
@@ -2944,6 +2950,12 @@ function beginWork( |
2944 | 2950 | if (hasChildWork) { |
2945 | 2951 | workInProgress.effectTag |= Update; |
2946 | 2952 | } |
| 2953 | + |
| 2954 | + // Reset effect durations for the next eventual effect phase. |
| 2955 | + // These are reset during render to allow the DevTools commit hook a chance to read them, |
| 2956 | + const stateNode = workInProgress.stateNode; |
| 2957 | + stateNode.effectDuration = 0; |
| 2958 | + stateNode.passiveEffectDuration = 0; |
2947 | 2959 | } |
2948 | 2960 | break; |
2949 | 2961 | case SuspenseComponent: { |
|