[bare] EXReactNativeEventEmitter not added to NativeModules in development builds
Summary
I've tested using using a fresh install of react native (tried 0.68.3, 0.69.5, 0.70.0) followed by a successful npx install-expo-modules@latest.
Expo modules that use the EventEmitter from expo-modules-core fail to register listeners in iOS development builds.
- in
NativeModulesProxy.native.js, the addListener and removeListeners methods of proxy modules are conditionally bound based on the truthiness ofNativeModules.EXReactNativeEventEmitter. - in development builds, this check resolves to undefined which assigns empty listener functions to the proxy modules.
- this means add addListener events via EventEmitter never actually get registered.
- I've seen some if/else logic in
EXNativeModulesProxy.mmwhich uses a different method of registering modules based on whether you're in remote debugging mode or not.- This also seems to be the file that attaches
EXReactNativeEventEmitterto the bridge, but it's a bit deep into undocumented land so not too sure exactly where modules get mounted to the NativeModules object to find the issue (doesn't seem to be documented on the RN side either).
- This also seems to be the file that attaches
What platform(s) does this occur on?
iOS
Environment
expo-env-info 1.0.5 environment info: System: OS: macOS 12.5.1 Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm Watchman: 2022.09.05.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: API Levels: 23, 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0 System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom, android-31 | Google APIs Intel x86 Atom_64 IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild npmPackages: expo: ^45.0.0 => 45.0.8 react: 17.0.2 => 17.0.2 react-native: 0.68.3 => 0.68.3 npmGlobalPackages: expo-cli: 6.0.5 Expo Workflow: bare
Minimal reproducible example
This repo is made with the following commands:
-
npx react-native init ExpoTest3 --version 0.68.3 -
npx install-expo-modules@latest -
npx expo install expo-screen-capture
After which I added a small snippet in App.js to add a screen capture listener. If you build for release on a device and screenshot you'll get an alert, if you build for dev on a device you will not.
https://github.com/ivo-digital/expo-event-emitter-example
hi there! i test your example from a debug build on an ios 15 device or ios 16 simulator and it works for me. the alert is shown after taking screenshot. could you help to double confirm that?
@Kudo thanks for testing it out! Have you tried with remote debugger on?
As mentioned it only occurs with development builds, if you cmd + D then hit Debug with Chrome and try again you should see that the alert will no longer show.
oh sorry i got confused for the "development builds", i used to call it remote debugging 😅 i can confirm this is an issue and will follow up it. thanks for letting us know the issue and great minimal reproducible example 👍
Thank you for filing this issue! This comment acknowledges we believe this may be a bug and there’s enough information to investigate it. However, we can’t promise any sort of timeline for resolution. We prioritize issues based on severity, breadth of impact, and alignment with our roadmap. If you’d like to help move it more quickly, you can continue to investigate it more deeply and/or you can open a pull request that fixes the cause.