Babel plugin: an undefined `onLongPress` becomes a function, so `Pressable` drops `onPress` after a long press
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, react-native, typescript
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 146
- Fork
- 67
- Merge trung bình
- 2 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 22
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DataDog/dd-sdk-reactnative
-
Taps on a `Pressable` with more than one child are not trackedCó thể đã có người làm @cdn34dd đã nhận 1 ngày trước. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
DataDog/dd-sdk-reactnative#1499 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[actionNameAttribute] prop doesn't accept value with curly bracesCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
DataDog/dd-sdk-reactnative#1486 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Expose Android app startup Activity filtering in the React Native SDKCó thể đã có người làm @sbarrio đã nhận 13 ngày trước. Đang mởenhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
DataDog/dd-sdk-reactnative#1485 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
GraphQL variables with non-ASCII contents will make Apollo Client request throw errorCó thể đã có người làm @cdn34dd đã nhận 15 ngày trước. Đang mởawaiting response bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
DataDog/dd-sdk-reactnative#1482 · 2 bình luận · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
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 callCó thể đã có người làm @cdn34dd đã nhận 13 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
DataDog/dd-sdk-reactnative#1377 · 1 bình luận · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của DataDog/dd-sdk-reactnative
Issue tương tự
-
[Bug]: Circular app layout navigation and help icons are shifted upward in the official demoĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
cloudscape-design/components#5184 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
JarX-Concepts/react-native-platform-components#130 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(api): optimize-for-web /preview outer catches miss asDecoderOutOfMemory on V8 OOM and SIGKILLĐang mởarea: backend bug priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
snapotter-hq/SnapOtter#3773 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-driven-qa ux-audit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
linagora/twake-contacts-frontend#386 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
git: README should state plainly that without --repository every reachable repository is in scopeĐang mởdocumentation server-git v2
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
modelcontextprotocol/servers#5225 ·
Maintainer thường phản hồi trong vòng 1 ngày