Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Nuxt PWA module no longer compatible with Nuxt One Signal module (with workaround) #299

Open
benjaminrichardson-ms opened this issue Jun 11, 2020 · 1 comment

Comments

@benjaminrichardson-ms
Copy link

benjaminrichardson-ms commented Jun 11, 2020

Version

v3.0.0-beta.19

Reproduction link

https://jsbin.com/towacag/

Steps to reproduce

Install both "@nuxtjs/onesignal": "^3.0.0-beta.16" and "@nuxtjs/pwa": "^3.0.0-beta.20"

Setup your nuxt.config.js to load both modules.

  modules: [
    '@nuxtjs/onesignal',
    '@nuxtjs/pwa'
  ]

Run your application

What is expected ?

The One Signal service worker is meant to combine the default sw.js service worker in workbox with the One Signal SW. If this works as expected, the browser should run OneSignalSDKWorker.js as the worker, which subsequently loads sw.js and https://cdn.onesignal.com/sdks/OneSignalSDK.js.

What is actually happening?

Even though @nuxtjs/onesignal is running first in the modules, because they are both async the order in which they run can get muddled up. Because of the change to grouping the option for @nuxtjs/pwa, in beta 17 under the pwa: {} object, and a flawed method that is meant to ensure backwards compatibility, the One Signal and PWA modules do not work together.

As you can see in the screen shots, the order in modules is correct, but when the modules run, the pwa module tries to get the modified this.options from the onesignal module, before it has had a chance to run.

Specifically this line is undefined when the pwa module is collecting up all of the options from the global options object.
this.options.workbox.swURL = 'OneSignalSDKWorker.js'

This causes the wrong worker to load and One Signal is never properly setup. Because the onesignal config cannot be passed to the workbox config, the default sw.js is still loaded as the service worker, rather than OneSignalSDKWorker.js

example-of-modules-in-nuxt-config.png

nuxtjs-pwa-option-set-log.png

Code in onesignal module that is meant to run first
Screenshot 2020-06-12 at 12.15.10 AM.png

Code in PWA module that actually runs first, thus missing the modifications from onesignal module
Screenshot 2020-06-12 at 12.14.55 AM.png

Additional comments?

Splitting out of the One Signal module is a good idea, but the fact that both of the most recent versions of these modules no longer work together is quite annoying (wasted many hours on nothing to figure this out).

To work around this, at a minimum you need to have the following in your PWA configuration in nuxt.config.js.

  pwa: {
    workbox: {
      swURL: 'OneSignalSDKWorker.js'
    },
    manifest: {
      gcm_sender_id: '482941778795'
    }
  },

By doing this, the part of the config that are supplied by the one signal module are already part of the PWA module config. Then the order in which they modules run will no longer matter.

This bug report is available on Nuxt community (#c224)
@benjaminrichardson-ms benjaminrichardson-ms changed the title Nuxt PWA module no longer compatible with Nuxt One Signal module Nuxt PWA module no longer compatible with Nuxt One Signal module (with workaround) Jun 12, 2020
@ghost
Copy link

ghost commented Nov 7, 2022

Thanksç for yoủ sharing, but Can you explain what is the '482941778795' mean in gcm_sender_id: '482941778795'?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant