@@ -119,6 +119,8 @@ export type ProfilerProps = {
119
119
disabled ?: boolean ;
120
120
// If component updates should be displayed as spans. False by default.
121
121
generateUpdateSpans ?: boolean ;
122
+ // props from child component
123
+ updateProps : { [ key : string ] : any } ;
122
124
} ;
123
125
124
126
/**
@@ -174,13 +176,18 @@ class Profiler extends React.Component<ProfilerProps> {
174
176
175
177
public componentDidUpdate ( prevProps : ProfilerProps ) : void {
176
178
if ( prevProps . generateUpdateSpans && this . span && prevProps !== this . props ) {
177
- const now = timestampWithMs ( ) ;
178
- this . span . startChild ( {
179
- description : `<${ prevProps . name } >` ,
180
- endTimestamp : now ,
181
- op : `react.update` ,
182
- startTimestamp : now ,
183
- } ) ;
179
+ const changedProps = Object . keys ( prevProps ) . filter ( k => prevProps . updateProps [ k ] !== this . props . updateProps [ k ] ) ;
180
+ if ( changedProps . length > 0 ) {
181
+ const now = timestampWithMs ( ) ;
182
+ const updateSpan = this . span . startChild ( {
183
+ description : `<${ prevProps . name } >` ,
184
+ endTimestamp : now ,
185
+ op : `react.update` ,
186
+ startTimestamp : now ,
187
+ } ) ;
188
+
189
+ updateSpan . setData ( 'changedProps' , changedProps ) ;
190
+ }
184
191
}
185
192
}
186
193
@@ -209,13 +216,13 @@ class Profiler extends React.Component<ProfilerProps> {
209
216
*/
210
217
function withProfiler < P extends object > (
211
218
WrappedComponent : React . ComponentType < P > ,
212
- options ?: Partial < ProfilerProps > ,
219
+ options ?: Pick < Partial < ProfilerProps > , Exclude < keyof ProfilerProps , 'updateProps' > > ,
213
220
) : React . FC < P > {
214
221
const componentDisplayName =
215
222
( options && options . name ) || WrappedComponent . displayName || WrappedComponent . name || UNKNOWN_COMPONENT ;
216
223
217
224
const Wrapped : React . FC < P > = ( props : P ) => (
218
- < Profiler name = { componentDisplayName } disabled = { options && options . disabled } >
225
+ < Profiler name = { componentDisplayName } disabled = { options && options . disabled } updateProps = { props } >
219
226
< WrappedComponent { ...props } />
220
227
</ Profiler >
221
228
) ;
0 commit comments