Skip to content

[NOJIRA][FIX][V2] Skip Babel and Metro plugins for web platform builds#1278

Merged
cdn34dd merged 1 commit intofeature/v2from
carlosnogueira/fix/skip-web-platform-babel-metro-plugins-v2
Apr 28, 2026
Merged

[NOJIRA][FIX][V2] Skip Babel and Metro plugins for web platform builds#1278
cdn34dd merged 1 commit intofeature/v2from
carlosnogueira/fix/skip-web-platform-babel-metro-plugins-v2

Conversation

@cdn34dd
Copy link
Copy Markdown
Contributor

@cdn34dd cdn34dd commented Apr 28, 2026

What does this PR do?

For cross-platform React Native apps that also target web (e.g., Expo with web support), the Babel plugin and Metro serializer were running unconditionally on all platforms, injecting native-only code into web bundles.

This PR adds awareness for the web platform so that web builds are skipped:

  • @datadog/mobile-react-native-babel-plugin: Skips all transforms when it's 'web'. This prevents injection of DdBabelInteractionTracking wrappers, __ddExtractText helpers, and the __DD_RN_BABEL_PLUGIN_ENABLED__ flag into web bundles.
  • createDatadogMetroSerializer (used by withDatadogMetroConfig): Skips debug ID injection for web builds.
  • unstable_beforeAssetSerializationPlugin (used by getDatadogExpoConfig): Same platform check for the Expo-specific code path.

When checking on a resulting bundle for an expo app built for the web, all Datadog artifacts created by babel & expo were eliminated.

Artifact Before After
DdBabelInteractionTracking 16 0
__ddExtractText 8 0
_datadogDebugIds 4 0
datadog-debug-id 1 0

Motivation

Issue #1204

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

- Babel plugin: skip all transforms when caller platform is 'web'
- Metro serializer (withDatadogMetroConfig): skip debug ID injection for
web
- Metro serializer (Expo plugin): skip debug ID injection for web
Copilot AI review requested due to automatic review settings April 28, 2026 15:38
@cdn34dd cdn34dd requested a review from a team as a code owner April 28, 2026 15:38
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

Adds platform awareness to Datadog’s React Native build tooling so that web bundles do not receive native-only Babel/Metro instrumentation artifacts.

Changes:

  • Skip Datadog Babel plugin transforms when caller.platform === 'web'.
  • Skip Metro Debug ID injection for graph.transformOptions.platform === 'web' (serializer + Expo unstable_beforeAssetSerializationPlugin path).
  • Add/extend unit tests to validate web skipping behavior (serializer + babel plugin).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/react-native-babel-plugin/src/index.ts Adds a web platform guard intended to bypass plugin transforms.
packages/react-native-babel-plugin/test/plugin.test.ts Adds a test asserting no Datadog artifacts are injected for web builds.
packages/core/src/metro/plugin/metroSerializer.ts Adds web platform guards for serializer Debug ID injection and the Expo pre-asset plugin path.
packages/core/src/metro/tests/metro.test.ts Adds a test asserting serializer skips Debug ID injection on web.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react-native-babel-plugin/src/index.ts
Comment thread packages/react-native-babel-plugin/src/index.ts
Comment thread packages/core/src/metro/plugin/metroSerializer.ts
@cdn34dd cdn34dd merged commit b9ddbd2 into feature/v2 Apr 28, 2026
13 checks passed
@cdn34dd cdn34dd deleted the carlosnogueira/fix/skip-web-platform-babel-metro-plugins-v2 branch April 28, 2026 16:10
@cdn34dd cdn34dd mentioned this pull request Apr 29, 2026
4 tasks
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.

3 participants