From 2875b4c1275d31b01bf7528fb1460e5c701b9e64 Mon Sep 17 00:00:00 2001 From: Carlos Nogueira Date: Wed, 25 Feb 2026 13:34:49 +0100 Subject: [PATCH] Fix babel plugin action name priority --- .../src/actions/rum/index.ts | 13 ++++++++++--- .../react-native-babel-plugin/test/plugin.test.ts | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/react-native-babel-plugin/src/actions/rum/index.ts b/packages/react-native-babel-plugin/src/actions/rum/index.ts index b7eab2bce..506234841 100644 --- a/packages/react-native-babel-plugin/src/actions/rum/index.ts +++ b/packages/react-native-babel-plugin/src/actions/rum/index.ts @@ -112,7 +112,7 @@ export function handleJSXElementActionPaths( } // Optionally compute a content getter (children + label props) - setContentAttribute(componentName, t, path, state, ddValues); + setContentAttribute(componentName, t, path, state, ddValues, options); // Wrap every actionable handler attribute with RUM for (const attrPath of actionPathList) { @@ -200,6 +200,7 @@ export function ensureMandatoryAttributes( * @param path JSXElement path. * @param state Plugin state with trackedComponents metadata. * @param ddValues Mutable map of computed values attached to attributes via `node.extra.ddValues`. + * @param options Plugin options (e.g., custom action name attribute). */ export function setContentAttribute( componentName: string, @@ -211,10 +212,16 @@ export function setContentAttribute( | Babel.types.ArrayExpression | Babel.types.ArrowFunctionExpression | Babel.types.ObjectExpression - > + >, + options: PluginOptions ) { + // Priority order for action name: actionNameAttribute > accessibilityLabel > getContent + const actionNameAttr = options.actionNameAttribute; + const hasActionName = actionNameAttr && ddValues[actionNameAttr]; + const hasAccessibilityLabel = ddValues['accessibilityLabel']; const componentData = state.trackedComponents?.[componentName]; - if (componentData?.useContent) { + + if (componentData?.useContent && !hasActionName && !hasAccessibilityLabel) { // Potential prop names to get text content from const LABEL_PROPS = ['trackingLabel', 'title', 'label', 'text']; diff --git a/packages/react-native-babel-plugin/test/plugin.test.ts b/packages/react-native-babel-plugin/test/plugin.test.ts index ad861b493..118b0789c 100644 --- a/packages/react-native-babel-plugin/test/plugin.test.ts +++ b/packages/react-native-babel-plugin/test/plugin.test.ts @@ -1151,9 +1151,6 @@ describe('Babel plugin: wrap interaction handlers for RUM', () => { "dd-action-name": ["test-action-button"], "example-button-prop": ["action-name-attr-button"], "accessibilityLabel": ["accessibility-action-button"], - "getContent": () => { - return __ddExtractText(/*#__PURE__*/React.createElement(React.Fragment, null), []); - }, "handlerArgs": [...args], "componentName": "Button" })(...args);else return func(...args);