@@ -1297,6 +1297,109 @@ describe('TouchEventBoundary._onTouchStart', () => {
12971297 ) ;
12981298 } ) ;
12991299
1300+ it ( 'stops collecting text beyond depth limit' , ( ) => {
1301+ const { defaultProps } = TouchEventBoundary ;
1302+ const boundary = new TouchEventBoundary ( defaultProps ) ;
1303+ jest . spyOn ( client , 'getIntegrationByName' ) . mockReturnValue ( undefined ) ;
1304+
1305+ // Build a fiber tree beyond the depth limit (> 3), depths 0-3 are allowed
1306+ const event = {
1307+ _targetInst : {
1308+ elementType : { displayName : 'TouchableOpacity' } ,
1309+ memoizedProps : { } ,
1310+ child : {
1311+ // depth 0
1312+ elementType : { name : 'View' } ,
1313+ memoizedProps : { } ,
1314+ child : {
1315+ // depth 1
1316+ elementType : { name : 'View' } ,
1317+ memoizedProps : { } ,
1318+ child : {
1319+ // depth 2
1320+ elementType : { name : 'View' } ,
1321+ memoizedProps : { } ,
1322+ child : {
1323+ // depth 3
1324+ elementType : { name : 'View' } ,
1325+ memoizedProps : { } ,
1326+ child : {
1327+ // depth 4 — beyond limit, should be ignored
1328+ elementType : { name : 'Text' } ,
1329+ memoizedProps : { children : 'Too deep' } ,
1330+ } ,
1331+ } ,
1332+ } ,
1333+ } ,
1334+ } ,
1335+ } ,
1336+ } ;
1337+
1338+ // @ts -expect-error Calling private member
1339+ boundary . _onTouchStart ( event ) ;
1340+
1341+ expect ( addBreadcrumb ) . toHaveBeenCalledWith (
1342+ expect . objectContaining ( {
1343+ message : 'Touch event within element: TouchableOpacity' ,
1344+ } ) ,
1345+ ) ;
1346+ } ) ;
1347+
1348+ it ( 'stops collecting text beyond sibling limit' , ( ) => {
1349+ const { defaultProps } = TouchEventBoundary ;
1350+ const boundary = new TouchEventBoundary ( defaultProps ) ;
1351+ jest . spyOn ( client , 'getIntegrationByName' ) . mockReturnValue ( undefined ) ;
1352+
1353+ // Build 6 sibling text nodes, limit is 5
1354+ const sibling6 = {
1355+ elementType : { name : 'Text' } ,
1356+ memoizedProps : { children : 'six' } ,
1357+ sibling : undefined ,
1358+ } ;
1359+ const sibling5 = {
1360+ elementType : { name : 'Text' } ,
1361+ memoizedProps : { children : 'five' } ,
1362+ sibling : sibling6 ,
1363+ } ;
1364+ const sibling4 = {
1365+ elementType : { name : 'Text' } ,
1366+ memoizedProps : { children : 'four' } ,
1367+ sibling : sibling5 ,
1368+ } ;
1369+ const sibling3 = {
1370+ elementType : { name : 'Text' } ,
1371+ memoizedProps : { children : 'three' } ,
1372+ sibling : sibling4 ,
1373+ } ;
1374+ const sibling2 = {
1375+ elementType : { name : 'Text' } ,
1376+ memoizedProps : { children : 'two' } ,
1377+ sibling : sibling3 ,
1378+ } ;
1379+ const sibling1 = {
1380+ elementType : { name : 'Text' } ,
1381+ memoizedProps : { children : 'one' } ,
1382+ sibling : sibling2 ,
1383+ } ;
1384+
1385+ const event = {
1386+ _targetInst : {
1387+ elementType : { displayName : 'TouchableOpacity' } ,
1388+ memoizedProps : { } ,
1389+ child : sibling1 ,
1390+ } ,
1391+ } ;
1392+
1393+ // @ts -expect-error Calling private member
1394+ boundary . _onTouchStart ( event ) ;
1395+
1396+ expect ( addBreadcrumb ) . toHaveBeenCalledWith (
1397+ expect . objectContaining ( {
1398+ message : 'Touch event within element: one two three four five' ,
1399+ } ) ,
1400+ ) ;
1401+ } ) ;
1402+
13001403 it ( 'handles string memoizedProps (raw text fiber nodes)' , ( ) => {
13011404 const { defaultProps } = TouchEventBoundary ;
13021405 const boundary = new TouchEventBoundary ( defaultProps ) ;
0 commit comments