1

I faced an unexpected bug today, react-native 59.8 only android issue

I am using onesignal and everything is working fine (Except when my app is in foreground).

I have initialised my onesignal in app.js

OneSignal.init(ONE_SIGNAL_DRIVER);

and my listeners are in my homepage.

useEffect(() => {
    OneSignal.addEventListener('received', onReceived);
    OneSignal.addEventListener('opened', onOpened);
    return () => {
      OneSignal.removeEventListener('received', onReceived);
      OneSignal.removeEventListener('opened', onOpened);
    };
  }, []);

Now, when i receive the notification, If my app is closed (Not in foreground). It works fine. First my bundle runs, and then everything resolved. and at last these events get fired and my on opened gets called(If i open my app from the notification).

But the problem is when my app is in foreground. When I click on the notification tile, immediately my onOpened gets called, this is an expected behaviour as my app is running and the listeners are already set.

But what happens is, when i click the notification, my onOpened get called and after that my react native bundle restarts and causing my app to restart, doing all the work from the start (App.js),

So the problem is when i open the notification while my app is in foreground or open, the react native bundle restarts and it restarts my app. Thus the things i wanted to do in my onOpened, don't resolve as it happens before the restart. Now what i want is, somehow not to let onesignal notification to restart my bundle or somehow delay my onOpened till my bundle restarts.

This log may help too, this is the log when i click on the notification while my app is in foreground, as you can see my onOpened gets called but then my app restarts, I also have onesignal enabled, but i don't think that is causing any issue.

This also happens when i make a release build.

clicked onOpened
Running application "Driver" with appParams: {"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
logging.js:3 [CodePush] Checking for update.
logging.js:3 [CodePush] An update is available, but it is being ignored due to having been previously rolled back.
logging.js:3 [CodePush] App is up to date.
Sarmad Shah
  • 3,725
  • 1
  • 20
  • 42

0 Answers0