[NOJIRA] [FIX] [ANDROID] [V2] Fix Invariant Violation crash on native initialization#1273
Open
marco-saia-datadog wants to merge 2 commits intofeature/v2from
Open
[NOJIRA] [FIX] [ANDROID] [V2] Fix Invariant Violation crash on native initialization#1273marco-saia-datadog wants to merge 2 commits intofeature/v2from
marco-saia-datadog wants to merge 2 commits intofeature/v2from
Conversation
425ff1f to
a647629
Compare
cdn34dd
approved these changes
Apr 28, 2026
There was a problem hiding this comment.
Pull request overview
Fixes an Android crash during native-first initialization by preventing bridge calls until the React Native SDK has been initialized from JS (ensuring the JS callable module is registered).
Changes:
- Add an
isRnSdkInitializedgate toDdSdkSessionStartedListenerand replay cached session IDs only when safe. - Extend
DdSdkNativeInitialization.initialize()with anisCalledFromJsflag and perform session catch-up only for JS-driven init. - Update
DdSdkImplementation.initialize()and add/adjust unit tests for the new gating and catch-up behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkSessionStartedListener.kt | Gates old-arch bridge calls behind JS initialization; caches/replays session IDs. |
| packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt | Adds isCalledFromJs to differentiate JS vs native init; triggers RN-init marker and session catch-up. |
| packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt | Ensures the session listener receives a React context during JS initialize (new-arch race fix). |
| packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkSessionStartedListenerTest.kt | Adds/updates tests to validate the new gating and replay behavior. |
| packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt | Adds tests for RN-init marking and catch-up behavior based on isCalledFromJs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Port of v3 fix (marcosaia/fix/native-initialization-crash) to v2. On native-first init, a RUM session can start before JS registers DatadogInternalReactBridge. Pre-fix, the listener always tried to deliver via BatchedBridge.callFunction; on old arch this async call throws an Invariant Violation that can't be caught, crashing the app. Gate bridge delivery on a new isRnSdkInitialized flag (set only after JS initialize() runs) and set the React context from DdSdk.initialize so the new-arch event-emitter replay has a target when the TurboModule wakes up late.
a647629 to
c0fdedd
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cdn34dd
approved these changes
Apr 28, 2026
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.
What does this PR do?
Fixes an
Invariant Violation: Module DatadogInternalReactBridge is not a registered callable modulecrash on Android when the SDK is initialized natively fromMainApplicationviaDdSdkNativeInitialization.initFromNative().More context on original v3 PR: #1251
Review checklist (to be filled by reviewers)