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

[Bug]: OneSignal.initialize is no longer idempotent on Android #1015

Open
2 of 3 tasks
theigl opened this issue Aug 21, 2024 · 1 comment
Open
2 of 3 tasks

[Bug]: OneSignal.initialize is no longer idempotent on Android #1015

theigl opened this issue Aug 21, 2024 · 1 comment

Comments

@theigl
Copy link

theigl commented Aug 21, 2024

What happened?

OneSignal.initialize(appId) used to be idempotent on iOS and Android. Since 3c94a25, this is no longer the case on Android.

Currently, every time OneSignal.initialize(appId) is called, the current instance of OneSignalPush is added as a listener:

// add listeners
OneSignal.getInAppMessages().addLifecycleListener(this);
OneSignal.getInAppMessages().addClickListener(this);
OneSignal.getNotifications().addForegroundLifecycleListener(this);
OneSignal.getNotifications().addClickListener(this);

The collection of listeners does not seem to be a Set and this is added to the listeners again and again. The end result is that the JS click event listener is called once for every invocation of OneSignal.initialize.

This causes problems in applications that are not 100% SPAs and navigate between different parts of the app using full-page reloads. In such a case, it is very difficult to determine if OneSignal.initialize has already been called or not and an idempotent version is much easier to use.

It can also cause problems when developing applications and using hotswapping/live reload.

Most likely related issues:

Steps to reproduce?

Create a test app that calls `OneSignal.initialize(appId)` several times
Click on a push notification
Registered click listeners will be called repeatedly

What did you expect to happen?

I expect to be able to call OneSignal.initialize(appId) as often as I want without any side effects on Android.

A simple solution would be to add a new isInitialized field to the OneSignalPush class and only add this as a listener if it has not been set.

OneSignal Cordova SDK version

5.2.4

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Lennix
Copy link

Lennix commented Oct 30, 2024

I came across this myself and this makes OneSignal unusable for me. Any plans to fix this?

This still happens with 5.2.6

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