Skip to content

[NOJIRA] [FIX] [ANDROID] [V2] Fix Invariant Violation crash on native initialization#1273

Open
marco-saia-datadog wants to merge 2 commits intofeature/v2from
marcosaia/v2/fix/native-initialization-crash
Open

[NOJIRA] [FIX] [ANDROID] [V2] Fix Invariant Violation crash on native initialization#1273
marco-saia-datadog wants to merge 2 commits intofeature/v2from
marcosaia/v2/fix/native-initialization-crash

Conversation

@marco-saia-datadog
Copy link
Copy Markdown
Member

What does this PR do?

Fixes an Invariant Violation: Module DatadogInternalReactBridge is not a registered callable module crash on Android when the SDK is initialized natively from MainApplication via DdSdkNativeInitialization.initFromNative().

More context on original v3 PR: #1251

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@marco-saia-datadog marco-saia-datadog changed the base branch from develop to feature/v2 April 24, 2026 09:07
@marco-saia-datadog marco-saia-datadog force-pushed the marcosaia/v2/fix/native-initialization-crash branch 2 times, most recently from 425ff1f to a647629 Compare April 28, 2026 08:50
@marco-saia-datadog marco-saia-datadog marked this pull request as ready for review April 28, 2026 08:50
@marco-saia-datadog marco-saia-datadog requested a review from a team as a code owner April 28, 2026 08:50
Copilot AI review requested due to automatic review settings April 28, 2026 08:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 isRnSdkInitialized gate to DdSdkSessionStartedListener and replay cached session IDs only when safe.
  • Extend DdSdkNativeInitialization.initialize() with an isCalledFromJs flag 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.
@marco-saia-datadog marco-saia-datadog force-pushed the marcosaia/v2/fix/native-initialization-crash branch from a647629 to c0fdedd Compare April 28, 2026 09:18
Copilot AI review requested due to automatic review settings April 28, 2026 12:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants