Skip to content

feat(tracing): Add Sentry.NavigationContainer wrapper for React Navigation#6199

Draft
antonis wants to merge 7 commits into
mainfrom
feat/sentry-navigation-container
Draft

feat(tracing): Add Sentry.NavigationContainer wrapper for React Navigation#6199
antonis wants to merge 7 commits into
mainfrom
feat/sentry-navigation-container

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented May 21, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Adds a Sentry.NavigationContainer component — a drop-in replacement for
NavigationContainer from @react-navigation/native that automatically
registers the navigation container with reactNavigationIntegration.

Before:

const ref = useRef(null);

<NavigationContainer
  ref={ref}
  onReady={() => navigationIntegration.registerNavigationContainer(ref)}
>
  ...
</NavigationContainer>

After:

<Sentry.NavigationContainer>
  ...
</Sentry.NavigationContainer>

The component:

  • Internally creates a ref and calls registerNavigationContainer on ready
  • Forwards refs via forwardRef so users keep imperative navigation access
  • Passes through all NavigationContainer props
  • Chains user-provided onReady callbacks (Sentry registers first)
  • Resolves the integration from the current client; no-ops if not registered
  • Gracefully falls back to rendering children if @react-navigation/native is not installed
  • Caches the require() result and warns only once to avoid noise

💡 Motivation and Context

reactNavigationIntegration requires manual ref + onReady wiring that is a
recurring source of misconfiguration — when users forget onReady, navigation
spans silently don't work. This is the biggest friction point for React Native
tracing adoption compared to iOS/Android where navigation auto-instruments via
OS lifecycle hooks.

Fixes #6065

💚 How did you test it?

CI, Manual, Unit tests

📝 Checklist

🔮 Next steps

…ation

Drop-in replacement for NavigationContainer that automatically wires up
reactNavigationIntegration, removing the manual ref/onReady boilerplate
that is a recurring source of misconfiguration.

Closes #6065

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

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).


  • feat(tracing): Add Sentry.NavigationContainer wrapper for React Navigation by antonis in #6199
  • feat(core): Expose pauseAppHangTracking and resumeAppHangTracking APIs by antonis in #6192

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 134cc57

antonis and others added 2 commits May 21, 2026 17:20
…nContainer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis antonis added the ready-to-merge Triggers the full CI test suite label May 21, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented May 21, 2026

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.12.0 (89) Release

⚙️ sentry-react-native Build Distribution Settings

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 458.94 ms 503.52 ms 44.58 ms
Size 48.30 MiB 53.58 MiB 5.28 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
bc0d8cf+dirty 412.37 ms 466.26 ms 53.89 ms
b9bebee+dirty 438.86 ms 452.21 ms 13.35 ms
5c1e987+dirty 423.52 ms 471.64 ms 48.12 ms
71abba0+dirty 496.54 ms 525.16 ms 28.63 ms
5569641+dirty 406.43 ms 428.51 ms 22.08 ms
3b6e9f9+dirty 442.70 ms 486.44 ms 43.74 ms
6177334+dirty 408.16 ms 441.14 ms 32.98 ms
2c735cc+dirty 414.09 ms 438.47 ms 24.38 ms
ef27341+dirty 412.94 ms 443.98 ms 31.04 ms
0d9949d+dirty 403.57 ms 437.00 ms 33.43 ms

App size

Revision Plain With Sentry Diff
bc0d8cf+dirty 48.30 MiB 53.48 MiB 5.18 MiB
b9bebee+dirty 48.30 MiB 53.58 MiB 5.28 MiB
5c1e987+dirty 43.75 MiB 48.08 MiB 4.33 MiB
71abba0+dirty 48.30 MiB 53.49 MiB 5.19 MiB
5569641+dirty 48.30 MiB 53.48 MiB 5.18 MiB
3b6e9f9+dirty 48.30 MiB 53.54 MiB 5.23 MiB
6177334+dirty 48.30 MiB 53.54 MiB 5.23 MiB
2c735cc+dirty 43.75 MiB 48.08 MiB 4.33 MiB
ef27341+dirty 48.30 MiB 53.54 MiB 5.24 MiB
0d9949d+dirty 43.75 MiB 48.13 MiB 4.37 MiB

Previous results on branch: feat/sentry-navigation-container

Startup times

Revision Plain With Sentry Diff
161ef26+dirty 419.96 ms 463.76 ms 43.80 ms

App size

Revision Plain With Sentry Diff
161ef26+dirty 48.30 MiB 53.58 MiB 5.28 MiB

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3842.59 ms 1224.66 ms -2617.93 ms
Size 5.15 MiB 6.68 MiB 1.53 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
3817909+dirty 1183.90 ms 1187.50 ms 3.60 ms
44c8b3f+dirty 3823.85 ms 1207.66 ms -2616.19 ms
b0d3373+dirty 3831.75 ms 1227.29 ms -2604.46 ms
7d6fd3a+dirty 1223.29 ms 1229.57 ms 6.28 ms
6176a94+dirty 3836.50 ms 1217.64 ms -2618.86 ms
5c1e987+dirty 1204.30 ms 1222.15 ms 17.85 ms
3d377b5+dirty 1218.48 ms 1219.51 ms 1.03 ms
7d8c8bd+dirty 3837.24 ms 1215.51 ms -2621.73 ms
4966363+dirty 3854.04 ms 1231.55 ms -2622.50 ms
5fe1c6c+dirty 1220.79 ms 1217.63 ms -3.16 ms

App size

Revision Plain With Sentry Diff
3817909+dirty 3.38 MiB 4.73 MiB 1.35 MiB
44c8b3f+dirty 5.15 MiB 6.66 MiB 1.51 MiB
b0d3373+dirty 5.15 MiB 6.68 MiB 1.53 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
6176a94+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5c1e987+dirty 3.38 MiB 4.73 MiB 1.35 MiB
3d377b5+dirty 3.38 MiB 4.76 MiB 1.38 MiB
7d8c8bd+dirty 5.15 MiB 6.68 MiB 1.53 MiB
4966363+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5fe1c6c+dirty 3.38 MiB 4.77 MiB 1.39 MiB

Previous results on branch: feat/sentry-navigation-container

Startup times

Revision Plain With Sentry Diff
161ef26+dirty 3833.45 ms 1215.96 ms -2617.49 ms

App size

Revision Plain With Sentry Diff
161ef26+dirty 5.15 MiB 6.68 MiB 1.53 MiB

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3845.29 ms 1222.18 ms -2623.11 ms
Size 5.15 MiB 6.68 MiB 1.53 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
3817909+dirty 1210.76 ms 1215.64 ms 4.89 ms
44c8b3f+dirty 3849.24 ms 1209.94 ms -2639.31 ms
b0d3373+dirty 3842.49 ms 1218.49 ms -2624.00 ms
7d6fd3a+dirty 1210.89 ms 1217.63 ms 6.74 ms
6176a94+dirty 3854.15 ms 1221.77 ms -2632.38 ms
5c1e987+dirty 1208.43 ms 1220.72 ms 12.29 ms
3d377b5+dirty 1201.55 ms 1201.80 ms 0.25 ms
7d8c8bd+dirty 3847.98 ms 1230.77 ms -2617.21 ms
4966363+dirty 3863.07 ms 1227.19 ms -2635.88 ms
5fe1c6c+dirty 1201.36 ms 1209.15 ms 7.78 ms

App size

Revision Plain With Sentry Diff
3817909+dirty 3.38 MiB 4.73 MiB 1.35 MiB
44c8b3f+dirty 5.15 MiB 6.66 MiB 1.51 MiB
b0d3373+dirty 5.15 MiB 6.68 MiB 1.53 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
6176a94+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5c1e987+dirty 3.38 MiB 4.73 MiB 1.35 MiB
3d377b5+dirty 3.38 MiB 4.76 MiB 1.38 MiB
7d8c8bd+dirty 5.15 MiB 6.68 MiB 1.53 MiB
4966363+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5fe1c6c+dirty 3.38 MiB 4.77 MiB 1.39 MiB

Previous results on branch: feat/sentry-navigation-container

Startup times

Revision Plain With Sentry Diff
161ef26+dirty 3844.87 ms 1227.50 ms -2617.37 ms

App size

Revision Plain With Sentry Diff
161ef26+dirty 5.15 MiB 6.68 MiB 1.53 MiB

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 477.42 ms 547.94 ms 70.52 ms
Size 48.30 MiB 53.58 MiB 5.28 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
b9bebee+dirty 500.50 ms 536.42 ms 35.92 ms
71abba0+dirty 411.04 ms 453.67 ms 42.63 ms
5569641+dirty 465.92 ms 532.22 ms 66.30 ms
3b6e9f9+dirty 442.39 ms 486.44 ms 44.05 ms
6177334+dirty 404.80 ms 456.74 ms 51.94 ms
ef27341+dirty 519.02 ms 553.42 ms 34.40 ms
23598c3+dirty 371.92 ms 420.65 ms 48.74 ms
a0d8cf8+dirty 533.71 ms 564.25 ms 30.54 ms
7ac3378+dirty 410.67 ms 442.60 ms 31.92 ms
c004dae+dirty 404.60 ms 430.67 ms 26.07 ms

App size

Revision Plain With Sentry Diff
b9bebee+dirty 48.30 MiB 53.58 MiB 5.28 MiB
71abba0+dirty 48.30 MiB 53.49 MiB 5.19 MiB
5569641+dirty 48.30 MiB 53.48 MiB 5.18 MiB
3b6e9f9+dirty 48.30 MiB 53.54 MiB 5.23 MiB
6177334+dirty 48.30 MiB 53.54 MiB 5.23 MiB
ef27341+dirty 48.30 MiB 53.54 MiB 5.24 MiB
23598c3+dirty 43.94 MiB 49.02 MiB 5.08 MiB
a0d8cf8+dirty 48.30 MiB 53.49 MiB 5.19 MiB
7ac3378+dirty 43.94 MiB 48.99 MiB 5.05 MiB
c004dae+dirty 48.30 MiB 53.49 MiB 5.19 MiB

Previous results on branch: feat/sentry-navigation-container

Startup times

Revision Plain With Sentry Diff
161ef26+dirty 426.07 ms 473.14 ms 47.07 ms

App size

Revision Plain With Sentry Diff
161ef26+dirty 48.30 MiB 53.58 MiB 5.28 MiB

antonis and others added 2 commits May 21, 2026 18:37
… NavigationContainer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread packages/core/src/js/NavigationContainer.tsx
Comment thread packages/core/src/js/NavigationContainer.tsx Outdated
antonis and others added 2 commits May 21, 2026 22:04
…ck behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 21, 2026

@sentry review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 134cc57. Configure here.

@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 21, 2026

Re: Warden findings — 3 low-severity issues about module-level _warned* flags not being reset between tests.

This is expected: the warn-once flags are intentional for production, and jest.resetModules() isn't viable here because it causes React instance mismatches between the test renderer and the component under test. Each warning branch is covered by exactly one test, so there's no actual flakiness. No changes needed.

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

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tracing): Add <Sentry.NavigationContainer> wrapper to auto-register React Navigation

1 participant