Open staltz opened 6 years ago
Hi @staltz,
I've tried to replicate the issue, by adding the following lines at the end of the nodejs-project in this sample : https://github.com/janeasystems/nodejs-mobile-samples/blob/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/react-native/UseMultipleChannels/nodejs-assets/nodejs-project/main.js#L140
let heartbeatNumber = 1;
setInterval( () => rn_bridge.channel.post('rn-log','Heartbeat ' + (heartbeatNumber++)), 1000);
Then, while the project is running, I've shaked the device and hit Reload. The heartbeats kept being received by the UI, so the bridge is reliably sending messages to the active UI, as far as I can observe.
If react-native destroys the UI there will be no actual "active" UI until a new UI is created and the messages sent in that interval will be lost. If the application depends on even those messages being delivered for sure, some sort of buffering/confirmation that the message was received could be built in the Application's protocol, but this could keep filling up the memory until react-native recreates the UI. Another way to do this could be by having the react-native Application send some signal to nodejs when the UI gets destroyed (if react-native has some handler for this).
I hope this was helpful.
Linux 4.15.0-38-generic #41-Ubuntu x86_64 GNU/Linux
Steps to reproduce the bug:
setInterval
to periodically send a heartbeat (any data) to the UI JSExpected behavior:
Heartbeats continue to be received at the UI JS side.
Actual behavior:
Heartbeats get lost (
Calling JS function after bridge has been destroyed
), logcat reports:Notice also that the heartbeats are sent from the same process ID (23616, as expected) but different thread IDs (not expected, at least that's my impression).
Overall I'm concerned how the nodejs-project can transparently access always the "currently active" RN bridge, no matter if it was recreated upon development refresh, or if the nodejs-project lived in the background longer than the RN thread lived. I think some of the issues our app users are facing are related to this.