OneSignal / react-onesignal

React OneSignal Module: Make it easy to integrate OneSignal with your React App!
Other
73 stars 26 forks source link

2.0.3 Release #59

Closed rgomezp closed 2 years ago

rgomezp commented 2 years ago

Switch from a timeout strategy to script#onload and script#onerror so that calls to #init will always resolve. This is important for consumers of the react-onesignal package who want to call multiple functions synchronously, for example:

const doThingsInOrder = async () => {
  await OneSignal.init({ ... });
  await OneSignal.showSlidedownPrompt();
};

Without this change, those calls will hang indefinitely if adblock prevents executing the web SDK from the cdn.onesignal.com domain.

An additional flag, isOneSignalScriptFailed is kept around to resolve OneSignal SDK methods in the event of a CDN load failure. Since resolutions in the queue are only called on #init, if SDK methods are called after #init has already failed they will never resolve.


Also includes other minor miscellaneous nits and improvements.