@@ -498,3 +498,87 @@ test('Updates navigation transaction name correctly when span is cancelled early
498498 expect ( [ 'externalFinish' , 'cancelled' ] ) . toContain ( idleSpanFinishReason ) ;
499499 }
500500} ) ;
501+
502+ test ( 'Creates separate transactions for rapid consecutive navigations' , async ( { page } ) => {
503+ await page . goto ( '/' ) ;
504+
505+ // First navigation: / -> /lazy/inner/:id/:anotherId/:someAnotherId
506+ const firstTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
507+ return (
508+ ! ! transactionEvent ?. transaction &&
509+ transactionEvent . contexts ?. trace ?. op === 'navigation' &&
510+ transactionEvent . transaction === '/lazy/inner/:id/:anotherId/:someAnotherId'
511+ ) ;
512+ } ) ;
513+
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
527+ const secondTransactionPromise = waitForTransaction ( 'react-router-7-lazy-routes' , async transactionEvent => {
528+ return (
529+ ! ! transactionEvent ?. transaction &&
530+ transactionEvent . contexts ?. trace ?. op === 'navigation' &&
531+ transactionEvent . transaction === '/another-lazy/sub/:id/:subId'
532+ ) ;
533+ } ) ;
534+
535+ const navigationToAnother = page . locator ( 'id=navigate-to-another-from-inner' ) ;
536+ await expect ( navigationToAnother ) . toBeVisible ( ) ;
537+ await navigationToAnother . click ( ) ;
538+
539+ const secondEvent = await secondTransactionPromise ;
540+
541+ // Verify second transaction
542+ expect ( secondEvent . transaction ) . toBe ( '/another-lazy/sub/:id/:subId' ) ;
543+ expect ( secondEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
544+ const secondTraceId = secondEvent . contexts ?. trace ?. trace_id ;
545+ const secondSpanId = secondEvent . contexts ?. trace ?. span_id ;
546+
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+
564+ // Verify third transaction
565+ expect ( thirdEvent . transaction ) . toBe ( '/lazy/inner/:id/:anotherId/:someAnotherId' ) ;
566+ expect ( thirdEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
567+ const thirdTraceId = thirdEvent . contexts ?. trace ?. trace_id ;
568+ const thirdSpanId = thirdEvent . contexts ?. trace ?. span_id ;
569+
570+ // Verify each navigation created a separate transaction with unique trace and span IDs
571+ expect ( firstTraceId ) . toBeDefined ( ) ;
572+ expect ( secondTraceId ) . toBeDefined ( ) ;
573+ expect ( thirdTraceId ) . toBeDefined ( ) ;
574+
575+ // All trace IDs should be unique
576+ expect ( firstTraceId ) . not . toBe ( secondTraceId ) ;
577+ expect ( secondTraceId ) . not . toBe ( thirdTraceId ) ;
578+ expect ( firstTraceId ) . not . toBe ( thirdTraceId ) ;
579+
580+ // All span IDs should be unique
581+ expect ( firstSpanId ) . not . toBe ( secondSpanId ) ;
582+ expect ( secondSpanId ) . not . toBe ( thirdSpanId ) ;
583+ expect ( firstSpanId ) . not . toBe ( thirdSpanId ) ;
584+ } ) ;
0 commit comments