Codegen variable naming can result in incorrect code
未关闭
还没有人认领这个 Issue。
Resolution: PR Submitted
Stale
Tech: Codegen
Type: New Architecture
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Description
type MyEventType = {
type: string;
payload: {
message: string;
}
};
export interface NativeProps extends ViewProps {
onPressed?: CodegenTypes.BubblingEventHandler<MyEventType> | null;
}
codegen generates such a code not the payload variable gets shadowed. And the bug is in the line: payload.setProperty(runtime, "payload", payload);
void SimpleViewEventEmitter::onPressed(OnPressed event) const {
dispatchEvent("pressed", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "type", event.type);
{
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "message", event.payload.message);
payload.setProperty(runtime, "payload", payload);
}
return payload;
});
}
See
https://github.com/mfazekas/codegen-variable-naming-bug
Steps to reproduce
check out https://github.com/mfazekas/codegen-variable-naming-bug
cd ReproducerApp/ios
pod install
cat build/generated/ios/react/renderer/components/AppSpec/EventEmitters.cpp
React Native Version
0.81.4
Affected Platforms
Other (please specify)
Areas
Codegen
Output of npx @react-native-community/cli info
info Fetching system and libraries information...
System:
OS: macOS 15.6
CPU: (12) arm64 Apple M2 Max
Memory: 125.66 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 22.16.0
path: ~/.nvm/versions/node/v22.16.0/bin/node
Yarn:
version: 1.22.21
path: ~/.local/bin/yarn
npm:
version: 11.5.2
path: ~/.nvm/versions/node/v22.16.0/bin/npm
Watchman:
version: 2025.06.30.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /Users/boga/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.5
- iOS 18.5
- macOS 15.5
- tvOS 18.5
- visionOS 2.5
- watchOS 11.5
Android SDK: Not Found
IDEs:
Android Studio: 2025.1 AI-251.26094.121.2513.14007798
Xcode:
version: 16.4/16F6
path: /usr/bin/xcodebuild
Languages:
Java:
version: 20.0.1
path: /usr/bin/javac
Ruby:
version: 2.7.8
path: /Users/boga/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
n/a
MANDATORY Reproducer
https://github.com/mfazekas/codegen-variable-naming-bug
Screenshots and Videos
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从必需的复现程序开始,在 ReproducerApp/ios 中运行 pod install,并检查 build/generated/ios/react/renderer/components/AppSpec/EventEmitters.cpp。从 TypeScript 示例追踪生成的事件 payload 命名;当生成的 C++ 不再遮蔽外层 payload 并保留嵌套事件数据时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp, react-native, typescript
- 领域
- mobile-dev, tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100