react / react/react-native

Codegen variable naming can result in incorrect code

オープン
#53,839 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Resolution: PR Submitted Stale Tech: Codegen Type: New Architecture
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

必須の再現手順から始め、ReproducerApp/iospod install を実行し、build/generated/ios/react/renderer/components/AppSpec/EventEmitters.cpp を調べます。TypeScript の例から生成されるイベントペイロードの命名を追跡します。生成された C++ が外側のペイロードをシャドーイングせず、ネストされたイベントデータを保持するようになれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, react-native, typescript
領域
mobile-dev, tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。