Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update nativeInterface default export to support bridgeless mode #717

Conversation

gabrieldonadel
Copy link
Contributor

Overview

When trying to use react-native-netinfo with the new architecture and bridgeless mode on (react-native version 0.74.0-nightly-20240123-cbd818dad), the user is faced with an unhandled promise rejection

image

This error happens because of the following code inside nativeInterface.ts

export default {
...RNCNetInfo,
get eventEmitter(): NativeEventEmitter {
if (!nativeEventEmitter) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
/// @ts-ignore
nativeEventEmitter = new NativeEventEmitter(RNCNetInfo);
}

Currently we cannot use the spread operator directly on the object returned from React Native's NativeModules, given that the module object is a host object. So to fix that we should use Object.assign instead or directly use NativeModules.RNCNetInfo

After this change everything works as expected and the compatibility layer allows react-native-netinfo to be used with bridgeless mode on

Test Plan

Tested running on Android and iOS with:

  • new arch, bridgeless off
  • new arch, bridgeless on
  • old arch

@gabrieldonadel gabrieldonadel marked this pull request as ready for review February 27, 2024 16:52
Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subtle! Nice fix, this works for me.
Do you have an upstream link to maybe track this as an extension to the bridgeless layer?

@mikehardy mikehardy merged commit 950410b into react-native-netinfo:master Feb 27, 2024
2 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 27, 2024
## [11.3.1](v11.3.0...v11.3.1) (2024-02-27)

### Bug Fixes

* update nativeInterface default export to support bridgeless mode ([#717](#717)) ([950410b](950410b))
@matt-oakes
Copy link
Collaborator

🎉 This PR is included in version 11.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gabrieldonadel
Copy link
Contributor Author

subtle! Nice fix, this works for me. Do you have an upstream link to maybe track this as an extension to the bridgeless layer?

Yep, here is the GH issue facebook/react-native#43221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants