Skip to content

fix(core): Always re-initialize native SDK from JS in dev builds#5872

Merged
antonis merged 1 commit intomainfrom
fix/dev-build-native-reinit
Mar 24, 2026
Merged

fix(core): Always re-initialize native SDK from JS in dev builds#5872
antonis merged 1 commit intomainfrom
fix/dev-build-native-reinit

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented Mar 24, 2026

📢 Type of change

  • Bugfix

📜 Description

When sentry.options.json exists (generated by the Expo config plugin with useNativeInit: true and options), the Metro serializer injects __SENTRY_OPTIONS__ into the JS bundle. The SDK then sets autoInitializeNativeSdk = false, skipping the JS-side initNativeSdk call entirely.

This prevents the native log bridge (rnLogger.setReactContext) and runtime values (devServerUrl, defaultSidecarUrl, mobileReplayOptions) from being configured, resulting in zero envelopes being sent to sentry.io in development builds.

The fix adds a !__DEV__ guard so that:

  • Dev builds: JS always calls initNativeSdk, which re-initializes native (the native SDK handles this gracefully: "Sentry has been already initialized. Previous configuration will be overwritten."). The log bridge and runtime values are properly set up.
  • Release builds: Behavior is preserved — autoInitializeNativeSdk = false keeps the native-only init for app start crash capture.

💡 Motivation and Context

Closes #5734

Reproduction: With sentry.options.json in the project root, the Expo sample sends zero envelopes to sentry.io (events only appear in Spotlight). Without the file, everything works — JS re-initializes native and envelopes are sent successfully.

The root cause: when autoInitializeNativeSdk = false, the JS wrapper's initNativeSdk returns early at line 250-257 without ever calling RNSentry.initNativeSdk(). The native module never receives the JS options, the React context isn't set on the logger, and captureEnvelope calls from JS don't result in envelopes being delivered.

💚 How did you test it?

  1. Unit tests: Added tests for both __DEV__=true and __DEV__=false modes, verifying autoInitializeNativeSdk is set correctly in each case
  2. On-device verification (Android emulator):
    • Created sentry.options.json in the Expo sample project root
    • Before fix: didCallNativeInit: false, zero Envelope sent successfully in logs
    • After fix: didCallNativeInit: true, multiple Envelope sent successfully. in logs
  3. All 1172 existing tests pass, build and lint clean

📝 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
  • No breaking changes

🔮 Next steps

#skip-changelog since this only affects the development workflow

When `sentry.options.json` exists (generated by the Expo config plugin
with `useNativeInit: true`), the SDK was setting
`autoInitializeNativeSdk = false`, skipping the JS-side `initNativeSdk`
call entirely. This prevented the native log bridge and runtime values
(devServerUrl, defaultSidecarUrl) from being set up, causing zero
envelopes to be sent to sentry.io in development builds.

The fix adds a `!__DEV__` guard so that in dev builds, JS always
re-initializes native (the native SDK handles double-init gracefully
with "Previous configuration will be overwritten"). In release builds,
the existing behavior is preserved for app start crash capture.

Closes #5734

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

github-actions Bot commented Mar 24, 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).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 24, 2026

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

Generated by 🚫 dangerJS against 0b65f55

@antonis antonis marked this pull request as ready for review March 24, 2026 10:49
Copy link
Copy Markdown
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

Tested locally, all working!.
LGTM!

@antonis antonis merged commit cbf87ac into main Mar 24, 2026
52 of 57 checks passed
@antonis antonis deleted the fix/dev-build-native-reinit branch March 24, 2026 14:18
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.

SDK doesn't work on Expo Go when enableNative is set to true

2 participants