Skip to content

[FIX] [V2] Babel Plugin: handle undefined wrapped callback functions#1243

Merged
cdn34dd merged 1 commit intofeature/v2from
carlosnogueira/issue-1226/fix-babel-action-wrapping-v2
Apr 9, 2026
Merged

[FIX] [V2] Babel Plugin: handle undefined wrapped callback functions#1243
cdn34dd merged 1 commit intofeature/v2from
carlosnogueira/issue-1226/fix-babel-action-wrapping-v2

Conversation

@cdn34dd
Copy link
Copy Markdown
Contributor

@cdn34dd cdn34dd commented Apr 8, 2026

What does this PR do?

Solves issue #1226 by using optional chaining on the wrapped function invocation.

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

@cdn34dd cdn34dd requested a review from a team as a code owner April 8, 2026 16:18
Copilot AI review requested due to automatic review settings April 8, 2026 16:18
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

This PR fixes issue #1226 by implementing optional chaining (?.) on handler function invocations in the Babel plugin to safely guard against undefined optional handler props (e.g., onPress on Pressable components).

Changes:

  • Applied optional chaining to the fallback branch where handlers are called when the DD SDK is not initialized (using Babel's optionalCallExpression API)
  • Applied optional chaining to the DD-initialized branch in DdBabelInteractionTracking.wrapRumAction()
  • Updated all test snapshots to reflect the new optional chaining syntax
  • Added comprehensive test coverage for undefined/null handler scenarios

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/react-native-babel-plugin/src/actions/rum/tap.ts Replaced t.callExpression with t.optionalCallExpression for fallback branches to generate optional chaining in both inline and memoized scenarios
packages/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts Updated the fallback branch to use optional chaining (func?.(...args)) when calling handlers
packages/react-native-babel-plugin/test/plugin.test.ts Updated all test snapshots to expect optional chaining syntax and added new test suite for undefined handler safety
packages/core/src/rum/instrumentation/interactionTracking/tests/DdBabelInteractionTracking.test.ts New comprehensive test file verifying undefined/null handlers don't crash

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

@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 bot commented Apr 8, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3775d49 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@cdn34dd cdn34dd force-pushed the carlosnogueira/issue-1226/fix-babel-action-wrapping-v2 branch from 0924b49 to 3775d49 Compare April 9, 2026 08:28
@cdn34dd cdn34dd merged commit e87aeaa into feature/v2 Apr 9, 2026
9 checks passed
@cdn34dd cdn34dd deleted the carlosnogueira/issue-1226/fix-babel-action-wrapping-v2 branch April 9, 2026 09:26
@sbarrio sbarrio mentioned this pull request Apr 14, 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