@@ -186,43 +186,30 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
186186 }
187187
188188 const props = currentInst . memoizedProps ;
189- const sentryLabel =
189+ const labelValue =
190190 typeof props ?. [ SENTRY_LABEL_PROP_KEY ] !== 'undefined'
191191 ? `${ props [ SENTRY_LABEL_PROP_KEY ] } `
192- : undefined ;
193-
194- // For some reason type narrowing doesn't work as expected with indexing when checking it all in one go in
195- // the "check-label" if sentence, so we have to assign it to a variable here first
196- let labelValue ;
197- if ( typeof this . props . labelName === 'string' )
198- labelValue = props ?. [ this . props . labelName ] ;
192+ // For some reason type narrowing doesn't work as expected with indexing when checking it all in one go in
193+ // the "check-label" if sentence, so we have to assign it to a variable here first
194+ : ( typeof this . props . labelName === 'string' ) ? props ?. [ this . props . labelName ] : undefined ;
199195
200196 // Check the label first
201- if ( sentryLabel && ! this . _isNameIgnored ( sentryLabel ) ) {
202- if ( ! activeLabel ) {
203- activeLabel = sentryLabel ;
204- }
205- componentTreeNames . push ( sentryLabel ) ;
206- } else if (
207- typeof labelValue === 'string' &&
208- ! this . _isNameIgnored ( labelValue )
209- ) {
210- if ( ! activeLabel ) {
211- activeLabel = labelValue ;
197+ if ( labelValue && typeof labelValue === 'string' ) {
198+ if ( this . _pushIfNotIgnored ( componentTreeNames , labelValue ) ) {
199+ if ( ! activeLabel ) {
200+ activeLabel = labelValue ;
201+ }
212202 }
213- componentTreeNames . push ( labelValue ) ;
214203 } else if ( currentInst . elementType ) {
215204 const { elementType } = currentInst ;
216205
217- if (
218- elementType . displayName &&
219- ! this . _isNameIgnored ( elementType . displayName )
220- ) {
221- // Check display name
222- if ( ! activeDisplayName ) {
223- activeDisplayName = elementType . displayName ;
206+ // Check display name
207+ if ( elementType . displayName ) {
208+ if ( this . _pushIfNotIgnored ( componentTreeNames , elementType . displayName ) ) {
209+ if ( ! activeDisplayName ) {
210+ activeDisplayName = elementType . displayName ;
211+ }
224212 }
225- componentTreeNames . push ( elementType . displayName ) ;
226213 }
227214 }
228215
@@ -240,6 +227,18 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
240227 op : UI_ACTION_TOUCH ,
241228 } ) ;
242229 }
230+
231+ /**
232+ * Pushes the name to the componentTreeNames array if it is not ignored.
233+ */
234+ private _pushIfNotIgnored ( componentTreeNames : string [ ] , name : string , file ?: string ) : boolean {
235+ const value = file ? `${ name } (${ file } )` : name ;
236+ if ( this . _isNameIgnored ( value ) ) {
237+ return false ;
238+ }
239+ componentTreeNames . push ( value ) ;
240+ return true ;
241+ }
243242}
244243
245244/**
0 commit comments