You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered:
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 ofOneSignalPush
is added as a listener:OneSignal-Cordova-SDK/src/android/com/onesignal/cordova/OneSignalPush.java
Lines 360 to 364 in 1e2f9e7
The collection of listeners does not seem to be a
Set
andthis
is added to the listeners again and again. The end result is that the JSclick
event listener is called once for every invocation ofOneSignal.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:
OneSignal.Notifications.addEventListener('click'.....)
- event is fires dozens of times when app starts. #970Steps to reproduce?
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 theOneSignalPush
class and only addthis
as a listener if it has not been set.OneSignal Cordova SDK version
5.2.4
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: