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

$OneSignal sometimes works in a PROD environment, sometimes not, in DEV enviroment works fine #1

Open
buglavecz opened this issue Jan 14, 2020 · 8 comments · May be fixed by #19
Open

Comments

@buglavecz
Copy link

Version

v3.0.0-beta.19

Reproduction link

https://github.com/nuxt-community/pwa-module

Steps to reproduce

I was create a trusted https on localhost for testing, there working fine with OneSignal.
But, in production environment sometimes working.

If not works, then I got this error, when refresh browser:

one-signal-error.jpg

I don't understand what is wrong?


I call OneSignal in mounted() hook in app layout.

this.$OneSignal.push(() => {

   this.$OneSignal.showNativePrompt();


    this.$OneSignal.isPushNotificationsEnabled((isEnabled) => {
    if (isEnabled) {
      console.log('Push notifications are enabled!')
    } else {
      console.log('Push notifications are not enabled yet.')
    }
  })
});

If I refresh many times the browser, then I got this (only in production):

one-signal-error-2.jpg

What is expected ?

Every page refresh show native prompt to user.

What is actually happening?

Sometimes show, sometimes not showing native prompt.

Additional comments?

I don't understand, why works on DEV env, and why not in PROD env. :-(

Please help!!!

This bug report is available on Nuxt community (#c195)
@buglavecz
Copy link
Author

@pi0 can you help me? Thanks.

@buglavecz
Copy link
Author

In PROD enviroment:
If I unregister Service Worker in devtools and after refresh Chrome, it is working. Again and again...
But, I no unregister service worker manually, just I refresh Chrome, again and again, then very randomly works.

In DEV environment all working fine.

@zhuharev
Copy link

Has same issue

@Galaco
Copy link

Galaco commented Mar 28, 2020

I appear to have the same/similar issue. Everything is fine on dev environment. Building for prod, OneSignal behaves correctly until notifications have been enabled. Push notifications then work until page is refreshed.

All subsequent page loads after that generates the following error OP mentioned, and notifications no longer work until clearing site data and repeating the notifications prompt process:

installWorker - SW's 'controllerchange' fired but no state change!

My config:

{
      cdn: true,
      init: {
        appId: <removed>,
        allowLocalhostAsSecureOrigin: true,
        welcomeNotification: {
            disable: true
        },
        autoResubscribe: true,
        autoRegister: false
      }
}

@pi0 pi0 transferred this issue from nuxt-community/pwa-module Apr 16, 2020
@icangku
Copy link

icangku commented May 27, 2020

anyone?

@ajay-wohlig
Copy link

Facing the same issue

@luisjoserivera
Copy link

After experiencing the same issue I started digging.
Go to Chrome Developer Tools / Application > Service Workers
When reloading the page the service worker changes from sw.js to OneSignalSDKWorker.js and vice-versa.
It seems the process in charge of updating the service worker is getting all mixed up somewhere.
In one refresh the update installs the OneSignalSDKWorker.js which imports sw.js, but in next refresh install sw.js alone, dismissing OneSignalSDKWorker.js completely.
I'm not well seasoned around service workers, workbox etc. Someone with better knowledge could bring some light here.

@luisjoserivera
Copy link

Problem found.
According to OneSignal documentation their service worker overwrites other service workers.

To fix this '@nuxtjs/onesignal' imports sw.js (the sw created by @nuxtjs/pwa with workbox) into OneSignalSDKWorker.js as recomended by OneSignal in here.

Then it tries to set our pwa sw path to OneSignalSDKWorker.js using this.options.workbox.swURL but it should be this.options.pwa.workbox.swURL. I'm not sure if workbox options used to be placed at the top level of nuxt config but now they go under options.pwa.workbox.

This is why at first install we always get sw.js first, but OneSignalSDK.js overwrite this under the hood and on refresh our app sees it has a different service worker and overwrites it again.

I'll try to make a pull request but while it gets accepted feel free to fix this manually by addding pwa.workbox.swURL: 'OneSignalSDKWorker.js' in your nuxt-config options.

@luisjoserivera luisjoserivera linked a pull request Oct 17, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

6 participants