@@ -112,20 +112,14 @@ export function formatRerenders(analysis: ReactProfileAnalysis, limit: number):
112112 ] . join ( '\n' ) ;
113113}
114114
115- export function findComponent (
116- analysis : ReactProfileAnalysis ,
117- name : string ,
118- ) : ComponentProfile | undefined {
119- return (
120- analysis . components . find ( ( c ) => c . name === name ) ??
121- analysis . components . find ( ( c ) => c . name . toLowerCase ( ) === name . toLowerCase ( ) )
122- ) ;
115+ /** Every component of that name, such as `Row [memo]` and `Row [function]`; case-insensitive when no exact match. */
116+ export function findComponents ( analysis : ReactProfileAnalysis , name : string ) : ComponentProfile [ ] {
117+ const exact = analysis . components . filter ( ( c ) => c . name === name ) ;
118+ if ( exact . length > 0 ) return exact ;
119+ return analysis . components . filter ( ( c ) => c . name . toLowerCase ( ) === name . toLowerCase ( ) ) ;
123120}
124121
125- export function formatComponentReport (
126- analysis : ReactProfileAnalysis ,
127- component : ComponentProfile ,
128- ) : string {
122+ function componentDetail ( analysis : ReactProfileAnalysis , component : ComponentProfile ) : string [ ] {
129123 const lines = [ componentLine ( component ) , `causes: ${ causeSummary ( component . causes ) } ` ] ;
130124 const props = Object . entries ( component . changedProps )
131125 . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
@@ -140,16 +134,25 @@ export function formatComponentReport(
140134 if ( hooks ) lines . push ( `changed hooks (by index): ${ hooks } ` ) ;
141135 const owners = keyCounts ( component . owners , 3 ) ;
142136 if ( owners ) lines . push ( `rendered by: ${ owners } ` ) ;
143- const findings = analysis . findings . filter ( ( finding ) => finding . component === component . name ) ;
144- for ( const finding of findings )
145- lines . push ( `finding ${ finding . kind } : ${ finding . evidence } -> ${ finding . fix } ` ) ;
146137 if ( component . costliestCommits . length > 0 ) {
147138 const commits = component . costliestCommits . map ( ( { index, selfMs } ) => {
148139 const commit = analysis . commits [ index ] ;
149140 return `#${ index } ${ ms ( selfMs ) } ${ commit ? ` of ${ ms ( commit . durationMs ) } ` : '' } ` ;
150141 } ) ;
151142 lines . push ( `its costliest commits (self time of commit duration): ${ commits . join ( ', ' ) } ` ) ;
152143 }
144+ return lines ;
145+ }
146+
147+ /** Reports each component of one name, then the findings that name it. */
148+ export function formatComponentReport (
149+ analysis : ReactProfileAnalysis ,
150+ components : ComponentProfile [ ] ,
151+ ) : string {
152+ const lines = components . flatMap ( ( component ) => componentDetail ( analysis , component ) ) ;
153+ const name = components [ 0 ] ?. name ;
154+ for ( const finding of analysis . findings . filter ( ( f ) => f . component === name ) )
155+ lines . push ( `finding ${ finding . kind } : ${ finding . evidence } -> ${ finding . fix } ` ) ;
153156 return lines . join ( '\n' ) ;
154157}
155158
0 commit comments