diff --git a/packages/react-native-babel-plugin/src/actions/rum/tap.ts b/packages/react-native-babel-plugin/src/actions/rum/tap.ts index 43abc5d2f..1a2224455 100644 --- a/packages/react-native-babel-plugin/src/actions/rum/tap.ts +++ b/packages/react-native-babel-plugin/src/actions/rum/tap.ts @@ -298,6 +298,19 @@ function handleMemoization( ? callback : t.callExpression(callback, callArgs); + // Update handlerArgs in argsObject to match the actual callback params + // instead of the default [...args] computed from the outer identifier + const handlerArgsProp = argsObject.properties.find( + prop => + t.isObjectProperty(prop) && + t.isStringLiteral(prop.key) && + prop.key.value === 'handlerArgs' + ); + + if (handlerArgsProp && t.isObjectProperty(handlerArgsProp)) { + handlerArgsProp.value = t.arrayExpression(callArgs); + } + const actionWrapper = getActionWrapperFunction( t, state, diff --git a/packages/react-native-babel-plugin/test/plugin.test.ts b/packages/react-native-babel-plugin/test/plugin.test.ts index ad861b493..03fbb1779 100644 --- a/packages/react-native-babel-plugin/test/plugin.test.ts +++ b/packages/react-native-babel-plugin/test/plugin.test.ts @@ -1201,7 +1201,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [event], "componentName": "Pressable" })(event);else return (event => { console.log('Testing ', a, b, event); @@ -1299,7 +1299,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [], "componentName": "Pressable" })();else return (() => { console.log('Testing '); @@ -1348,7 +1348,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [], "componentName": "Pressable" })();else return (() => { console.log('Testing '); @@ -1407,7 +1407,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [test], "componentName": "Pressable" })(test);else return funcN(test); }, [a, b]); @@ -1461,7 +1461,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [test], "componentName": "Pressable" })(test);else return funcN(test); }, [a, b]); @@ -1511,7 +1511,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [test], "componentName": "Pressable" })(test);else return funcN(test); }, [a, b]); @@ -1594,7 +1594,7 @@ describe('Babel plugin: wrap interaction handlers for RUM ( with memoization )', "getContent": () => { return __ddExtractText(<>, []); }, - "handlerArgs": [...args], + "handlerArgs": [], "componentName": "Pressable" })();else return funcN(); }, []);