Skip to content

fix(core): Fix stale route when reactNavigationIntegration uses a route override provider - #6458

Merged
alwx merged 2 commits into
mainfrom
alwx/fix/6436
Jul 16, 2026
Merged

fix(core): Fix stale route when reactNavigationIntegration uses a route override provider#6458
alwx merged 2 commits into
mainfrom
alwx/fix/6436

Conversation

@alwx

@alwx alwx commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix

📜 Description

reactNavigationIntegration subscribes to route changes via navigationContainer.addListener('state', ...). In React Navigation's BaseNavigationContainer, on every state change these fire back-to-back in this order:

emitter.emit({ type: 'state', data: { state } });   // → our listener
if (!isFirstMountRef.current && onStateChangeRef.current) {
  onStateChangeRef.current(hydratedState);          // → Expo Router refreshes its store here
}

Integrations like expoRouterIntegration supply a RouteOverrideProvider that reads Expo Router's store.getRouteInfo(), and that store is refreshed via the onStateChange prop — which runs after our listener. So we were reading the override for the previous route on every transition. Since updateLatestNavigationSpanWithCurrentRoute clears its span reference after one call, there was no second chance to correct it.

Fix: schedule the update as a microtask so the read happens after the synchronous state-change chain unwinds and downstream caches (Expo Router's store) have been refreshed.

💡 Motivation and Context

Fixes #6436.

💚 How did you test it?

  • Tests are added

📝 Checklist

  • I added tests to verify changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • No breaking changes.

🔮 Next steps

React Navigation fires `emit('state')` synchronously before invoking the
`onStateChange` prop. Integrations like Expo Router refresh their route
cache (which the override provider reads) inside that prop, so reading
the override synchronously in the `state` listener returns the previous
route for the current transition. Defer the read with a microtask so the
override read happens after the synchronous state-change chain completes.

Fixes #6436
@github-actions

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(core): Fix stale route when reactNavigationIntegration uses a route override provider by alwx in #6458
  • docs(sdk-versions): Add 8.14.2 row to main by alwx in #6456
  • docs(changelog): Add 8.14.2 changelog entry by alwx in #6455
  • chore(deps): bump ruby/setup-ruby from 1.314.0 to 1.316.0 by dependabot in #6446
  • chore(deps): bump actions/setup-java from 5.3.0 to 5.5.0 by dependabot in #6444
  • chore(deps): bump github/codeql-action/analyze from 4.36.3 to 4.37.0 by dependabot in #6443
  • chore(deps): bump dorny/paths-filter from 4.0.1 to 4.0.2 by dependabot in #6442
  • chore(deps): update JavaScript SDK to v10.65.0 by github-actions in #6441
  • fix(ios): Break RNSentryOnDrawReporterView retain cycle in emit-new-frame block by alwx in #6449
  • refactor(ios): Migrate from PrivateSentrySDKOnly to SentrySDK.internal by alwx in #6380
  • docs: Improve PR template guidance by sentry-junior in #6447
  • fix(ios): Resolve getNewScreenTimeToDisplay Promise with number not array by antonis in #6438
  • fix(feedback): Guard show/hide against uninitialized _setVisibility by antonis in #6435
  • fix(tracing): Fix orphaned TTID/TTFD spans in the trace view by antonis in #6437
  • feat(tracing): Add reportFullyDisplayed() static API by antonis in #6419
  • feat(core): Track CaptureAppStartErrors adoption by antonis in #6429
  • feat(replay): Track mobile replay network capture adoption by antonis in #6428
  • feat(tracing): Track standalone app start adoption by antonis in #6427
  • feat(tracing): Track appLoaded and extendAppStart adoption by antonis in #6426
  • feat(tracing): Track wrapExpoRouterErrorBoundary adoption by antonis in #6425
  • feat(core): Track NavigationContainer adoption by antonis in #6424
  • feat(core): Track GlobalErrorBoundary adoption by antonis in #6421

🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against e381d80

@alwx
alwx marked this pull request as ready for review July 16, 2026 09:41

@lucas-zimerman lucas-zimerman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants