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

W/unknown:ReactNative: Calling JS function after bridge has been destroyed #18

Open
miumiu316 opened this issue Aug 30, 2021 · 4 comments

Comments

@miumiu316
Copy link

miumiu316 commented Aug 30, 2021

The react-native-serial-port-api works well from start of the react native app, but when restart the app from RNRestart Libiary or DevSettings.reload() method, the react-native-serial-port-api seems have some issues, see below scenario:
1 Start APP--react-native-serial-port-api, send and receive OK, the "dataReceived" event is triggered on the java script side

2 Reload the APP using RNRestart Libiary(https://github.com/avishayil/react-native-restart) or using DevSetting.reload() or just "r" from the console. the first time when react-native-serial-port-api can send out the Data out, and from Physical Layer there is data response back, but the "dataReceived" event is not triggered on the java script side, from the second time send out the data, the react-native-serial-port-api works normal on send and receive.

3 see below logs from Android Studio:
2021-08-29 19:59:25.537 30148-30362/com.inst.hct802h I/serialport: send: 550500000002aa
2021-08-29 19:59:26.045 30148-30326/com.inst.hct802h W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["dataReceived",{"data":"FFFFFFFFFFFF0600180042FE174005070108009B0837050401260200101701"}])

4 by Search the google, seems above behavior might be the context is destroyed when RNRestart or DevSetting.reload, and the react-native-serial-port-api is using the old old react context before restart or reload.

5 see reference saying it might be triggered by the the RCTDeviceEventEmitter module trying to send a message to javascript.
https://stackoverflow.com/questions/45972220/react-calling-js-function-after-bridge-has-been-destroyed-how-to-find-which

Help Needed: are there any thoughts that we can workaroud of this behavior from the react-native-serial-port-api libiary or the RN side?

@bastengao
Copy link
Owner

Why do you need to restart app?

Try to close serial port and open a new one.

serialPort.close()
serialPort = await SerialPortAPI.open(...)

@miumiu316
Copy link
Author

Thanks for the Comments. The reason why we restart the app is that there is some critical parameters that allowed for the user to config and save to local storage, not only including the baudrate, parity but also some other User Business logic related paramters that we need to make sure these parameters are saved correctly.
Our Scenario is Like this:
1 serialPort.open()(await SerialPortAPI.open(...))
2 Send Data and Receive Data and Render
3 serialPort.close()
4 RNRestart.restart()
and repeat 1-4
so each restart we open a new serial port using await SerialPortAPI.open(...)

@bastengao
Copy link
Owner

Try reinstall with fix-eventEmitter-cache branch. Let me know if it works. I will merge this branch to master and release new version.

npm install react-native-serial-port-api@fix-eventEmitter-cache --save

@miumiu316
Copy link
Author

Unfortunately, same behavior as before using this fix-eventEmitter-cache branch code.
We will investigate this libiary code in the coming days and we will get you back if we find something.

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

No branches or pull requests

2 participants