@@ -504,7 +504,7 @@ test('Updates navigation transaction name correctly when span is cancelled early
504504test ( 'Creates separate transactions for rapid consecutive navigations' , async ( { page } ) => {
505505 await page . goto ( '/' ) ;
506506
507- // First navigation: / -> /lazy/inner/:id/:anotherId/:someAnotherId
507+ // Set up transaction listeners
508508 const firstTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
509509 return (
510510 ! ! transactionEvent ?. transaction &&
@@ -513,21 +513,6 @@ test('Creates separate transactions for rapid consecutive navigations', async ({
513513 ) ;
514514 } ) ;
515515
516- const navigationToInner = page . locator ( 'id=navigation' ) ;
517- await expect ( navigationToInner ) . toBeVisible ( ) ;
518- await navigationToInner . click ( ) ;
519-
520- const firstEvent = await firstTransactionPromise ;
521-
522- // Verify first transaction
523- expect ( firstEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
524- expect ( firstEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
525- expect ( firstEvent . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
526-
527- const firstTraceId = firstEvent . contexts ?. trace ?. trace_id ;
528- const firstSpanId = firstEvent . contexts ?. trace ?. span_id ;
529-
530- // Second navigation: /lazy/inner -> /another-lazy/sub/:id/:subId
531516 const secondTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
532517 return (
533518 ! ! transactionEvent ?. transaction &&
@@ -536,37 +521,49 @@ test('Creates separate transactions for rapid consecutive navigations', async ({
536521 ) ;
537522 } ) ;
538523
539- const navigationToAnother = page . locator ( 'id=navigate-to-another-from-inner' ) ;
540- await expect ( navigationToAnother ) . toBeVisible ( ) ;
541- await navigationToAnother . click ( ) ;
524+ // Third navigation promise - using counter to match second occurrence of same route
525+ let innerRouteMatchCount = 0 ;
526+ const thirdTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
527+ if (
528+ transactionEvent ?. transaction &&
529+ transactionEvent . contexts ?. trace ?. op === 'navigation' &&
530+ transactionEvent . transaction === '/lazy/inner/:id/:anotherId/:someAnotherId'
531+ ) {
532+ innerRouteMatchCount ++ ;
533+ return innerRouteMatchCount === 2 ; // Match the second occurrence
534+ }
535+ return false ;
536+ } ) ;
537+
538+ // Perform navigations
539+ // First navigation: / -> /lazy/inner/:id/:anotherId/:someAnotherId
540+ await page . locator ( 'id=navigation' ) . click ( ) ;
541+
542+ const firstEvent = await firstTransactionPromise ;
543+
544+ // Second navigation: /lazy/inner -> /another-lazy/sub/:id/:subId
545+ await page . locator ( 'id=navigate-to-another-from-inner' ) . click ( ) ;
542546
543547 const secondEvent = await secondTransactionPromise ;
544548
545- // Verify second transaction
549+ // Third navigation: /another-lazy -> /lazy/inner/:id/:anotherId/:someAnotherId (back to same route as first)
550+ await page . locator ( 'id=navigate-to-inner-from-deep' ) . click ( ) ;
551+
552+ const thirdEvent = await thirdTransactionPromise ;
553+
554+ // Verify transactions
555+ expect ( firstEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
556+ expect ( firstEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
557+ const firstTraceId = firstEvent . contexts ?. trace ?. trace_id ;
558+ const firstSpanId = firstEvent . contexts ?. trace ?. span_id ;
559+
546560 expect ( secondEvent . transaction ) . toBe ( '/another-lazy/sub/:id/:subId' ) ;
547561 expect ( secondEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
548562 expect ( secondEvent . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
549563
550564 const secondTraceId = secondEvent . contexts ?. trace ?. trace_id ;
551565 const secondSpanId = secondEvent . contexts ?. trace ?. span_id ;
552566
553- // Third navigation: /another-lazy -> /lazy/inner/:id/:anotherId/:someAnotherId (back to same route as first)
554- const thirdTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
555- return (
556- ! ! transactionEvent ?. transaction &&
557- transactionEvent . contexts ?. trace ?. op === 'navigation' &&
558- transactionEvent . transaction === '/lazy/inner/:id/:anotherId/:someAnotherId' &&
559- // Ensure we're not matching the first transaction again
560- transactionEvent . contexts ?. trace ?. trace_id !== firstTraceId
561- ) ;
562- } ) ;
563-
564- const navigationBackToInner = page . locator ( 'id=navigate-to-inner-from-deep' ) ;
565- await expect ( navigationBackToInner ) . toBeVisible ( ) ;
566- await navigationBackToInner . click ( ) ;
567-
568- const thirdEvent = await thirdTransactionPromise ;
569-
570567 // Verify third transaction
571568 expect ( thirdEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
572569 expect ( thirdEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
0 commit comments