Skip to content

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

Open
kevindice wants to merge 1 commit into
DataDog:developfrom
kevindice:fix/babel-plugin-nested-tracked-handlers
Open

kevindice wants to merge 1 commit into
DataDog:developfrom
kevindice:fix/babel-plugin-nested-tracked-handlers

Conversation

@kevindice

Copy link
Copy Markdown

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.

…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 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.

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.

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

2 participants