Skip to content

fix: React Navigation Instrumentation starts initial transaction before navigator mount #1315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 1, 2021

Conversation

jennmueng
Copy link
Member

@jennmueng jennmueng commented Jan 31, 2021

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

On V5, the initial blank transaction is now set on the routing instrumentation register instead of the navigator mount, this way it gets set on the scope before the app component is mounted. Then, once the navigator is mounted, beforeNavigate is called, and the transaction on the scope is updated with the new context.

On V4, the same strategy is adopted as V5. This means that now V4 has the option of updating a transaction on the scope instead of just setting a new one. For V4 however, this behavior is only used on the initial transaction and nothing is changed by this PR for subsequent route changes.

// Root App component

React.useEffect(() => {
    // This gets called before the next useEffect block, however, the transaction will already exist
    const transaction = Sentry.getCurrentHub().getScope().getTransaction(); // defined

    console.log(`Transaction exists: ${!!transaction}`); // "Transaction exists: true" <- Fixed from prior
}, []);

React.useEffect(() => {
    reactNavigationInstrumentation.registerNavigationContainer(navigation);
}, []);

💡 Motivation and Context

Fixes #1314

💚 How did you test it?

Updated V4 tests to account for these changes. Ran V5 on simulator, needs testing for V4.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing
  • No breaking changes

@jennmueng jennmueng self-assigned this Jan 31, 2021
@jennmueng jennmueng changed the base branch from master to jenn/performance-improve February 1, 2021 04:42
@marandaneto marandaneto requested a review from a team February 1, 2021 10:07
Base automatically changed from jenn/performance-improve to master February 1, 2021 13:26
@jennmueng jennmueng marked this pull request as ready for review February 1, 2021 13:30
@jennmueng jennmueng merged commit 7281061 into master Feb 1, 2021
@jennmueng jennmueng deleted the jenn/perf-initial branch February 1, 2021 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial transaction from React Navigation routing instrumentation starts after app component mount
2 participants