From 6e814a05651d7063c609b63a70d9b9f0e496d694 Mon Sep 17 00:00:00 2001 From: Carlos Nogueira Date: Tue, 3 Mar 2026 18:01:00 +0000 Subject: [PATCH] Fix babel plugin wrapping on memoized named functions --- .../src/actions/rum/tap.ts | 13 +++++++++++++ .../react-native-babel-plugin/test/plugin.test.ts | 14 +++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) 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(); }, []);