@@ -502,7 +502,7 @@ test('Updates navigation transaction name correctly when span is cancelled early
502502test ( 'Creates separate transactions for rapid consecutive navigations' , async ( { page } ) => {
503503 await page . goto ( '/' ) ;
504504
505- // First navigation: / -> /lazy/inner/:id/:anotherId/:someAnotherId
505+ // Set up transaction listeners
506506 const firstTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
507507 return (
508508 ! ! transactionEvent ?. transaction &&
@@ -511,19 +511,6 @@ test('Creates separate transactions for rapid consecutive navigations', async ({
511511 ) ;
512512 } ) ;
513513
514- const navigationToInner = page . locator ( 'id=navigation' ) ;
515- await expect ( navigationToInner ) . toBeVisible ( ) ;
516- await navigationToInner . click ( ) ;
517-
518- const firstEvent = await firstTransactionPromise ;
519-
520- // Verify first transaction
521- expect ( firstEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
522- expect ( firstEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
523- const firstTraceId = firstEvent . contexts ?. trace ?. trace_id ;
524- const firstSpanId = firstEvent . contexts ?. trace ?. span_id ;
525-
526- // Second navigation: /lazy/inner -> /another-lazy/sub/:id/:subId
527514 const secondTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
528515 return (
529516 ! ! transactionEvent ?. transaction &&
@@ -532,35 +519,47 @@ test('Creates separate transactions for rapid consecutive navigations', async ({
532519 ) ;
533520 } ) ;
534521
535- const navigationToAnother = page . locator ( 'id=navigate-to-another-from-inner' ) ;
536- await expect ( navigationToAnother ) . toBeVisible ( ) ;
537- await navigationToAnother . click ( ) ;
522+ // Third navigation promise - using counter to match second occurrence of same route
523+ let innerRouteMatchCount = 0 ;
524+ const thirdTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
525+ if (
526+ transactionEvent ?. transaction &&
527+ transactionEvent . contexts ?. trace ?. op === 'navigation' &&
528+ transactionEvent . transaction === '/lazy/inner/:id/:anotherId/:someAnotherId'
529+ ) {
530+ innerRouteMatchCount ++ ;
531+ return innerRouteMatchCount === 2 ; // Match the second occurrence
532+ }
533+ return false ;
534+ } ) ;
535+
536+ // Perform navigations
537+ // First navigation: / -> /lazy/inner/:id/:anotherId/:someAnotherId
538+ await page . locator ( 'id=navigation' ) . click ( ) ;
539+
540+ const firstEvent = await firstTransactionPromise ;
541+
542+ // Second navigation: /lazy/inner -> /another-lazy/sub/:id/:subId
543+ await page . locator ( 'id=navigate-to-another-from-inner' ) . click ( ) ;
538544
539545 const secondEvent = await secondTransactionPromise ;
540546
541- // Verify second transaction
547+ // Third navigation: /another-lazy -> /lazy/inner/:id/:anotherId/:someAnotherId (back to same route as first)
548+ await page . locator ( 'id=navigate-to-inner-from-deep' ) . click ( ) ;
549+
550+ const thirdEvent = await thirdTransactionPromise ;
551+
552+ // Verify transactions
553+ expect ( firstEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
554+ expect ( firstEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
555+ const firstTraceId = firstEvent . contexts ?. trace ?. trace_id ;
556+ const firstSpanId = firstEvent . contexts ?. trace ?. span_id ;
557+
542558 expect ( secondEvent . transaction ) . toBe ( '/another-lazy/sub/:id/:subId' ) ;
543559 expect ( secondEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
544560 const secondTraceId = secondEvent . contexts ?. trace ?. trace_id ;
545561 const secondSpanId = secondEvent . contexts ?. trace ?. span_id ;
546562
547- // Third navigation: /another-lazy -> /lazy/inner/:id/:anotherId/:someAnotherId (back to same route as first)
548- const thirdTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
549- return (
550- ! ! transactionEvent ?. transaction &&
551- transactionEvent . contexts ?. trace ?. op === 'navigation' &&
552- transactionEvent . transaction === '/lazy/inner/:id/:anotherId/:someAnotherId' &&
553- // Ensure we're not matching the first transaction again
554- transactionEvent . contexts ?. trace ?. trace_id !== firstTraceId
555- ) ;
556- } ) ;
557-
558- const navigationBackToInner = page . locator ( 'id=navigate-to-inner-from-deep' ) ;
559- await expect ( navigationBackToInner ) . toBeVisible ( ) ;
560- await navigationBackToInner . click ( ) ;
561-
562- const thirdEvent = await thirdTransactionPromise ;
563-
564563 // Verify third transaction
565564 expect ( thirdEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
566565 expect ( thirdEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
0 commit comments