Closed bolanos-nava closed 1 year ago
The async functions staying pending forever were due to not running OneSignal.init on every refresh.
When I first set up my test app, I got the window.Onesignal already defined as an object
error, which I thought was due to running init
on every refresh, so I added a function to check if the service worker was installed and if it was, skip the initialization. However, doing so prevented the OneSignal web SDK functions from loading and made window.OneSignal undefined. And the window.OneSignal already defined...
error was due to React strict mode making the app render twice.
I think it would be good to add a check in the React SDK to see if window.OneSignal is defined and throw an error or warning if it is not.
How can we help?
I set up a React test app on localhost:3000 and I configured my OneSignal app in the dashboard with the option ". I'm doing the following:
init
promise resolves, set the external user ID and show the category prompt.getUserId()
method.When the browser isn't subscribed to notifications and the OneSignal service worker isn't installed yet, I click on the allow button of the native prompt and then, without refreshing, click on the button to get the player ID, I can log it to the console without issue. However, when I refresh the page, I can no longer obtain the player ID because the async
getUserId()
method stays pending forever.I have two questions:
I uploaded the test app to a repository here so you can check it out. You just have to put your app id in the
constants
object of theApp.jsx
file.