fix(core): Fix stale route when reactNavigationIntegration uses a route override provider - #6458
Merged
Conversation
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
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
Contributor
alwx
marked this pull request as ready for review
July 16, 2026 09:41
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
reactNavigationIntegrationsubscribes to route changes vianavigationContainer.addListener('state', ...). In React Navigation'sBaseNavigationContainer, on every state change these fire back-to-back in this order:Integrations like
expoRouterIntegrationsupply aRouteOverrideProviderthat reads Expo Router'sstore.getRouteInfo(), and that store is refreshed via theonStateChangeprop — which runs after our listener. So we were reading the override for the previous route on every transition. SinceupdateLatestNavigationSpanWithCurrentRouteclears 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?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps