Skip to content

Make native module resolution lazy and expose core internals entry point - #1316

Open
cdn34dd wants to merge 9 commits into
developfrom
carlosnogueira/draft/lazy-native-module-resolution
Open

cdn34dd wants to merge 9 commits into
developfrom
carlosnogueira/draft/lazy-native-module-resolution

Conversation

@cdn34dd

@cdn34dd cdn34dd commented Jun 28, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR makes Datadog React Native native module specs resolve lazily instead of at module importtime. It updates the core SDK wrappers to use explicit native module getter functions, adds regression tests to verify imports no longer trigger TurboModuleRegistry lookups, and exposes a scoped @datadog/mobile-react-native/internal entry point for platform packages that need shared core internals.

Motivation

Some platforms, such as Vega, need to import parts of the core package in environments where the React Native native modules are not available. Resolving TurboModules during import makes those imports fail before the caller actually uses native functionality.

Lazy native module resolution keeps the package import-safe while preserving runtime behavior on supported React Native platforms. The internal entry point also avoids unsupported deep imports from platform packages by providing a single maintained path for shared core internals.

Additional Notes

Anything else we should know when reviewing?

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

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 27796fe | Docs | View more details | Give us feedback!

@cdn34dd
cdn34dd force-pushed the carlosnogueira/draft/lazy-native-module-resolution branch from 5db666e to 1c84ce5 Compare September 15, 2026 16:25
@cdn34dd
cdn34dd marked this pull request as ready for review September 15, 2026 16:26
@cdn34dd
cdn34dd requested review from a team as code owners September 15, 2026 16:26
@cdn34dd
cdn34dd requested review from sameerank and vjfridge and a lite review from Copilot and removed request for a team September 15, 2026 16:26
@cdn34dd

cdn34dd commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T19:12:50.102856Z 27796fe New commits
🔒 Security Review ✅ Completed 2026-10-27T19:16:22.740246Z 27796fe New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c84ce5252

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/rum/DdRum.ts Outdated
Comment thread packages/core/src/specs/NativeDdSdk.ts

This comment was marked as resolved.

@leoromanovsky
leoromanovsky self-requested a review October 27, 2026 03:17
@cdn34dd
cdn34dd force-pushed the carlosnogueira/draft/lazy-native-module-resolution branch from 1c84ce5 to 4952ad3 Compare October 27, 2026 11:26
Copilot AI lite review requested due to automatic review settings October 27, 2026 11:26

This comment was marked as outdated.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4952ad3f6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/sdk/DdSdkInternal.ts Outdated
Comment thread packages/core/package.json
Copilot AI lite review requested due to automatic review settings October 27, 2026 14:35

This comment was marked as outdated.

The DdRum, DdLogs, DdTrace and DdFlags singletons are built at module
evaluation, so field initializers calling the native getters still
performed TurboModule lookups when importing the public barrel or the
internal entry point. Resolve them through getters at call time instead.
The native getters cached a null lookup result forever, so a module
that was unavailable on first use could never be picked up later.
Only cache a module once it is found, and drop the redundant cache in
DdSdkInternal.
@cdn34dd
cdn34dd force-pushed the carlosnogueira/draft/lazy-native-module-resolution branch from ef9e96a to 4d30fe7 Compare October 27, 2026 16:24
Copilot AI lite review requested due to automatic review settings October 27, 2026 16:24

This comment was marked as outdated.

Proxy is not available on older Android JSC and Hermes versions still
supported by the SDK, so importing the package threw a ReferenceError
there. Resolve the native module through a private getter on
DdSdkWrapper instead, matching the other SDK wrappers.
The import-safety assertions in importSafety.test.ts and
internalEntry.test.ts spied on TurboModuleRegistry outside
jest.isolateModules, so they could not observe lookups made by the
isolated modules and passed regardless. Remove them and cover the spec
modules and DdSdkWrapper in wrapperImportSafety.test.ts, which installs
the spy inside the isolate.

Update the DdSdkNativeBridge mocks to the getNativeDdSdk contract and
cover the fallback used when NativeModules.DdSdk is missing.
Copilot AI lite review requested due to automatic review settings October 27, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@cdn34dd

cdn34dd commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

@leoromanovsky leoromanovsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Approval submitted by Codex at @leoromanovsky's explicit request. The two follow-ups are nonblocking for the scoped import-safety change.

This branch has not been deployed

No deployments
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.

4 participants