fix(core): Retry native module resolution to prevent silent event drops#5981
Open
fix(core): Retry native module resolution to prevent silent event drops#5981
Conversation
The RNSentry TurboModule reference is resolved once at module load time. In production Hermes bytecode builds, JS execution can start before the TurboModule registry is fully populated, causing getRNSentryModule() to return undefined permanently. This silently disables native transport and drops all events. Re-resolve the native module in isNativeAvailable() if the initial resolution returned undefined. By the time Sentry.init() calls this method, TurboModules are registered and the module resolves correctly. Fixes #5508 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
Plus 6 more 🤖 This preview updates automatically when you update the PR. |
Contributor
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@sentry review |
Contributor
Author
|
@cursor review |
There was a problem hiding this comment.
✅ 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 f6c6b67. Configure here.
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
The
RNSentryTurboModule reference is resolved once at module load time (wrapper.ts:48). In production Hermes bytecode builds, JS execution can start before the TurboModule registry is fully populated, causinggetRNSentryModule()to returnundefinedpermanently. This silently disables native transport and drops all events.The fix re-resolves the native module in
isNativeAvailable()if the initial resolution returnedundefined. By the timeSentry.init()calls this method (milliseconds after module load), TurboModules are registered and the module resolves correctly.Changes:
const RNSentry→let RNSentryto allow re-assignmentisNativeAvailable()retriesgetRNSentryModule()ifRNSentryisundefined💡 Motivation and Context
Fixes RN-447
Users report that events are silently dropped in production builds (Hermes + New Architecture) when
Sentry.init()is the first statement after an early return guard. Adding any statement (e.g.,console.log('test')) beforeSentry.init()resolves the issue, pointing to a race condition in TurboModule registration timing.💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
__SENTRY_OPTIONS__+autoInitializeNativeSdkcode path which has a related but distinct silent event drop bug in 8.x whenuseNativeInit: falseis combined withoptionsin the Expo plugin config.