@@ -186,43 +186,30 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
186
186
}
187
187
188
188
const props = currentInst . memoizedProps ;
189
- const sentryLabel =
189
+ const labelValue =
190
190
typeof props ?. [ SENTRY_LABEL_PROP_KEY ] !== 'undefined'
191
191
? `${ 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 ;
199
195
200
196
// 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
+ }
212
202
}
213
- componentTreeNames . push ( labelValue ) ;
214
203
} else if ( currentInst . elementType ) {
215
204
const { elementType } = currentInst ;
216
205
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
+ }
224
212
}
225
- componentTreeNames . push ( elementType . displayName ) ;
226
213
}
227
214
}
228
215
@@ -240,6 +227,18 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
240
227
op : UI_ACTION_TOUCH ,
241
228
} ) ;
242
229
}
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
+ }
243
242
}
244
243
245
244
/**
0 commit comments