Skip to content

[Babel plugin] Wrap nested tracked components with their own options and content - #1470

Merged
cdn34dd merged 1 commit into
DataDog:developfrom
kevindice:fix/babel-plugin-nested-tracked-handlers
Oct 8, 2026
Merged

cdn34dd merged 1 commit into
DataDog:developfrom
kevindice:fix/babel-plugin-nested-tracked-handlers

Conversation

@kevindice

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #1469.

In getJSXElementActionPaths, handler attributes are collected with path.traverse({ JSXAttribute }), which also visits nested elements. When a tracked component contains another tracked component, the inner component's handler was collected during the outer element's pass and wrapped with the outer element's ddValues (options.useContent, getContent); the inner element's own JSXElement visit then skipped it as __wrappedForRum.

This PR only accepts handler attributes whose parent is the element being processed (subpath.parentPath?.node === path.node.openingElement). Nested tracked elements are then wrapped on their own visit with their own options and content. Descendant collection of dd-action-name / accessibilityLabel literals (compound components) is unchanged.

Two tests cover a tracked container with and without its own handler enclosing a tracked button; the existing suite (210 tests) passes.

Motivation

We track layout containers (Tamagui XStack/YStack) with useContent: false for their own onPress, and every tracked button nested in one lost its content getter and reported as the bare component name. With a useContent: true outer component the inner button instead reports the outer component's content.

Additional Notes

The fix is a single condition; before/after output is in the issue.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 15:52
@kevindice
kevindice requested a review from a team as a code owner October 2, 2026 15:52

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.

Copilot review overview

🟢 Approval recommended

The focused fix correctly addresses the traversal bug and includes coverage for both reported scenarios.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes nested tracked components inheriting their parent’s RUM options and content.

Changes:

  • Restricts handler collection to the current JSX element.
  • Adds regression tests for nested tracked components with and without parent handlers.
File Description
packages/​react-native-babel-plugin/​src/​actions/​rum/​index.ts Limits actionable handlers to direct attributes.
packages/​react-native-babel-plugin/​test/​plugin.test.ts Tests correct nested-component wrapping.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@barboraplasovska
barboraplasovska removed their request for review October 8, 2026 09:14
…n options

getJSXElementActionPaths collected handler attributes with path.traverse,
which also visits nested elements, so a tracked component inside another
tracked component was wrapped with the outer element's ddValues
(useContent/getContent) and then skipped on its own visit. Only accept
handler attributes that belong to the element being processed.

Fixes DataDog#1469
Copilot AI balanced review requested due to automatic review settings October 8, 2026 10:41
@cdn34dd
cdn34dd force-pushed the fix/babel-plugin-nested-tracked-handlers branch from 16c4cd1 to 3797682 Compare October 8, 2026 10:41

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cdn34dd
cdn34dd merged commit d6c7449 into DataDog:develop Oct 8, 2026
15 checks passed
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.

[Babel plugin] A tracked component nested inside another tracked component is wrapped with the outer component's options/getContent

3 participants