Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/react-native-babel-plugin/src/actions/rum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve getContent fallback when a11y labels are disabled

This condition removes getContent whenever a static accessibilityLabel exists, but runtime naming only consumes accessibilityLabel when useAccessibilityLabel is true (packages/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts lines 88-91). In apps that set useAccessibilityLabel: false (a supported config) and still render accessibilityLabel props, the transformed payload now has neither getContent nor a usable label, so getTargetName falls back to the generic component name instead of title/text-derived content, reducing action-name accuracy.

Useful? React with 👍 / 👎.

// Potential prop names to get text content from
const LABEL_PROPS = ['trackingLabel', 'title', 'label', 'text'];

Expand Down
3 changes: 0 additions & 3 deletions packages/react-native-babel-plugin/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading