Skip to content

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

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

[NOJIRA][FIX] Skip Babel and Metro plugins for web platform builds#1277
cdn34dd merged 1 commit intodevelopfrom
carlosnogueira/fix/skip-web-platform-babel-metro-plugins

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

Copilot AI review requested due to automatic review settings April 28, 2026 14:51
@cdn34dd cdn34dd requested a review from a team as a code owner April 28, 2026 14:51
- 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
@cdn34dd cdn34dd force-pushed the carlosnogueira/fix/skip-web-platform-babel-metro-plugins branch from ea455e2 to ebd15fd Compare April 28, 2026 14:55
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 web bundles don’t receive native-only instrumentation/debug-ID injection.

Changes:

  • Update @datadog/mobile-react-native-babel-plugin to skip transforms when caller.platform === 'web'.
  • Update Metro serializer to skip debug ID injection for platform === 'web'.
  • Add Jest coverage for web skipping in the Babel plugin and Metro serializer paths.

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/test/plugin.test.ts Adds a test asserting the Babel plugin is a no-op on web builds.
packages/react-native-babel-plugin/src/index.ts Adds a platform check in Program.enter to skip plugin initialization on web.
packages/core/src/metro/plugin/metroSerializer.ts Skips debug ID injection for web in both serializer and Expo pre-asset hook.
packages/core/src/metro/tests/metro.test.ts Adds a test verifying the serializer does not inject debug IDs for web builds.

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

Comment thread packages/core/src/metro/plugin/metroSerializer.ts
Comment thread packages/core/src/metro/__tests__/metro.test.ts
Comment thread packages/react-native-babel-plugin/src/index.ts
@cdn34dd cdn34dd merged commit 682670d into develop Apr 28, 2026
11 checks passed
@cdn34dd cdn34dd deleted the carlosnogueira/fix/skip-web-platform-babel-metro-plugins branch April 28, 2026 15:44
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