@@ -88,10 +88,10 @@ export type ProfilerProps = {
88
88
name : string ;
89
89
// If the Profiler is disabled. False by default.
90
90
disabled ?: boolean ;
91
- // If component updates should be displayed as spans. False by default.
92
- generateUpdateSpans ?: boolean ;
93
- // If time component is on page should be displayed as spans. True by default.
94
- generateRenderSpans ?: boolean ;
91
+ // If time component is on page should be displayed as spans. False by default.
92
+ hasRenderSpan ?: boolean ;
93
+ // If component updates should be displayed as spans. True by default.
94
+ hasUpdateSpan ?: boolean ;
95
95
// props from child component
96
96
updateProps : { [ key : string ] : any } ;
97
97
} ;
@@ -110,8 +110,8 @@ class Profiler extends React.Component<ProfilerProps> {
110
110
111
111
public static defaultProps : Partial < ProfilerProps > = {
112
112
disabled : false ,
113
- generateRenderSpans : true ,
114
- generateUpdateSpans : false ,
113
+ hasRenderSpan : false ,
114
+ hasUpdateSpan : true ,
115
115
} ;
116
116
117
117
public constructor ( props : ProfilerProps ) {
@@ -135,18 +135,21 @@ class Profiler extends React.Component<ProfilerProps> {
135
135
popActivity ( this . mountActivity ) ;
136
136
this . mountActivity = null ;
137
137
138
+ const { name, hasRenderSpan = false } = this . props ;
139
+
138
140
// If we were able to obtain the spanId of the mount activity, we should set the
139
141
// next activity as a child to the component mount activity.
140
- if ( this . mountSpan ) {
142
+ if ( this . mountSpan && hasRenderSpan ) {
141
143
this . renderSpan = this . mountSpan . startChild ( {
142
- description : `<${ this . props . name } >` ,
144
+ description : `<${ name } >` ,
143
145
op : `react.render` ,
144
146
} ) ;
145
147
}
146
148
}
147
149
148
150
public componentDidUpdate ( prevProps : ProfilerProps ) : void {
149
- if ( prevProps . generateUpdateSpans && this . mountSpan && prevProps . updateProps !== this . props . updateProps ) {
151
+ const { hasUpdateSpan = true } = prevProps ;
152
+ if ( hasUpdateSpan && this . mountSpan && prevProps . updateProps !== this . props . updateProps ) {
150
153
const changedProps = Object . keys ( prevProps ) . filter ( k => prevProps . updateProps [ k ] !== this . props . updateProps [ k ] ) ;
151
154
if ( changedProps . length > 0 ) {
152
155
const now = timestampWithMs ( ) ;
@@ -209,8 +212,18 @@ function withProfiler<P extends object>(
209
212
* Requires React 16.8 or above.
210
213
* @param name displayName of component being profiled
211
214
*/
212
- function useProfiler ( name : string ) : void {
215
+ function useProfiler (
216
+ name : string ,
217
+ options ?: {
218
+ disabled ?: boolean ;
219
+ hasRenderSpan ?: boolean ;
220
+ } ,
221
+ ) : void {
213
222
const [ mountActivity ] = React . useState ( ( ) => {
223
+ if ( options && options . disabled ) {
224
+ return null ;
225
+ }
226
+
214
227
if ( getTracingIntegration ( ) ) {
215
228
return pushActivity ( name , 'mount' ) ;
216
229
}
@@ -223,12 +236,13 @@ function useProfiler(name: string): void {
223
236
const mountSpan = getActivitySpan ( mountActivity ) ;
224
237
popActivity ( mountActivity ) ;
225
238
226
- const renderSpan = mountSpan
227
- ? mountSpan . startChild ( {
228
- description : `<${ name } >` ,
229
- op : `react.render` ,
230
- } )
231
- : undefined ;
239
+ const renderSpan =
240
+ mountSpan && options && options . hasRenderSpan
241
+ ? mountSpan . startChild ( {
242
+ description : `<${ name } >` ,
243
+ op : `react.render` ,
244
+ } )
245
+ : undefined ;
232
246
233
247
return ( ) => {
234
248
if ( renderSpan ) {
0 commit comments