Babel plugin: an undefined `onLongPress` becomes a function, so `Pressable` drops `onPress` after a long press
维护者通常 1 天内回复
@cdn34dd 已经在做这个了。
开始于 2026年10月22日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, react-native, typescript
调研方向
The issue identifies generated Babel output and the handler transformation in the React Native Babel plugin, but gives no source file or test path. Start by locating the transformation that wraps handlers passed by reference and the tests covering its generated output. Done means an undefined handler remains undefined and the regression is covered; the reporter says they already have a fix ready and plan to open a PR.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When a tracked handler is passed by reference and its value is undefined at runtime (for example an optional prop), the babel plugin still replaces it with a wrapper function. The component therefore always receives a defined handler.
For Pressable this changes behavior. React Native's Pressability skips onPress on release when onLongPress != null and the press was held longer than delayLongPress (500ms by default). Because the plugin wraps onLongPress even when it is undefined, every press held for more than 500ms no longer calls onPress, even though the app never set a long-press handler.
This is related to #1226. The fix for it (#1243, released in 3.3.0) added optional chaining (onLongPress?.(...args)), which stops the crash, but the prop itself is still always a function.
Generated output (3.5.0, unchanged in 3.11.0 and on develop):
onLongPress: (...args) => {
if (DdBabelInteractionTracking.getInstance()) return DdBabelInteractionTracking.getInstance().wrapRumAction(onLongPress, "TAP", { /* ... */ })(...args);
else return onLongPress?.(...args);
}
Reproduction steps
import { Pressable, Text } from 'react-native';
const Button = ({ onPress, onLongPress }: { onPress: () => void; onLongPress?: () => void }) => (
<Pressable onPress={onPress} onLongPress={onLongPress}>
<Text>Press me</Text>
</Pressable>
);
// Usage: no onLongPress is passed
<Button onPress={() => console.log('pressed')} />
- Enable
@datadog/mobile-react-native-babel-plugininbabel.config.js. - Tap the button:
pressedis logged. - Press and hold the button for more than 500ms, then release: nothing is logged.
- Remove the babel plugin (or pass
{...(onLongPress ? { onLongPress } : {})}instead ofonLongPress={onLongPress}): the long press logspressedagain.
SDK logs
N/A (no error is thrown; onPress is silently not called).
Expected behavior
A handler that is undefined at runtime stays undefined, so the component behaves the same with and without the plugin. For example:
onLongPress: onLongPress != null ? (...args) => { /* RUM wrapper */ } : undefined
Affected SDK versions
@datadog/mobile-react-native-babel-plugin 3.5.0 (also present in 3.11.0 and develop), with @datadog/mobile-react-native 3.9.0
Latest working SDK version
N/A (since the babel plugin started wrapping handlers by reference)
Did you confirm if the latest SDK version fixes the bug?
Yes
Integration Methods
NPM
React Native Version
0.86.3 (New Architecture, Hermes)
Package.json Contents
No response
iOS Setup
No response
Android Setup
No response
Device Information
iOS Simulator, iPhone 17 Pro Max
Other relevant information
Any tracked component that changes behavior based on whether a handler is set is affected the same way (for Pressable, onLongPress is the visible case). I have a fix ready and will open a PR referencing this issue.
- 主要语言
- TypeScript
- 星标
- 146
- 派生
- 67
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DataDog/dd-sdk-reactnative 的其他 Issue
-
Taps on a `Pressable` with more than one child are not tracked可能已有人在做 @cdn34dd 于 1 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 68/100
DataDog/dd-sdk-reactnative#1499 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[actionNameAttribute] prop doesn't accept value with curly braces可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 3/5 1-2 天 新手友好度 62/100
DataDog/dd-sdk-reactnative#1486 · 4 条评论 ·
维护者通常 1 天内回复
-
Expose Android app startup Activity filtering in the React Native SDK可能已有人在做 @sbarrio 于 14 天前认领。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 35/100
DataDog/dd-sdk-reactnative#1485 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
GraphQL variables with non-ASCII contents will make Apollo Client request throw error可能已有人在做 @cdn34dd 于 16 天前认领。 未关闭awaiting response bug
难度 4/5 3-5 天 新手友好度 42/100
DataDog/dd-sdk-reactnative#1482 · 2 条评论 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
Interaction tracking records nothing: the babel plugin's injected import makes Metro bundle a second copy of the SDK, so DdBabelInteractionTracking.config is set on a different class than instrumented handlers call可能已有人在做 @cdn34dd 于 14 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
DataDog/dd-sdk-reactnative#1377 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
查看 DataDog/dd-sdk-reactnative 的全部 Issue
相似的 Issue
-
bug skills
难度 2/5 1-3 小时 新手友好度 77/100
equinor/fusion-framework#5846 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
-
难度 2/5 1-3 小时 新手友好度 85/100
Eyevinn/open-videocore#1256 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
[Bug]: Theme preset geist points at undefined --font-geist可能已有人在做 @claude 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复