Can't get new service worker to activate using skip waiting
Summary
What can I help with? Please keep this clear and concise.
Versions
next-pwa: 11.1.0next: 5.3.1
How To Reproduce
Same issue from - https://stackoverflow.com/questions/65537497/cant-get-new-service-worker-to-activate-using-skip-waiting
Expected Behaviors
Skipwaiting should activate the service worker
Additional Context
Next config
const runtimeCaching = require('next-pwa/cache')
const withPWA = require('next-pwa')
const config = withPWA({
pwa: {
dest: 'public',
register: false,
skipWaiting: false,
runtimeCaching,
},
})
You are adding wrong event listener to waiting event, that one should used to prompt user, not handle click
DaniAkash I think skip waitin installs the new SW, ( it does with us ) but then a reload is needed to activate the new SW.
We are looking to improve our SW lifecycle too, if you want @onair-lena and I could have a chat with you. Share our issues, and our solutions.
I have fixed the issue by updating my config to the exact one used in next.js example
@sanderkooger if you want to know the config:
In next.config.js
{
pwa: {
dest: 'public',
runtimeCaching,
},
}
For updating the service worker: (Mostly it happens automatically but you can have it as a fallback)
window.workbox.addEventListener('waiting', promptNewVersionAvailable)
// in promptNewVersionAvailable
window.workbox.addEventListener('controlling', () => {
window.location.reload()
})
window.workbox.messageSkipWaiting()
Now I have a completely different issue, I'm removing sentry generated sourcemaps in the final build following the idea from this comment
This also removes the sourcemap of the service worker - this leads to the entire service worker becoming redundant
Full explaination of this issue can be found in the discussion on the sentry repository