vite-plugin-pwa
vite-plugin-pwa copied to clipboard
updateServiceWorker() not always working
I'm using import { useRegisterSW } from "virtual:pwa-register/react"; to manage updates. I
I've noticed occasionally (especially with multiple tabs) after the needsRefresh gets set to true and the popup appears, if the user clicks the button calling updateServiceWorker() sometimes nothing happens. The service worker is 'waiting to become active' and the needsRefresh fired, but it doesn't actually install it.
Usually a refresh will fix it and the updateServiceWorker() will work then, but it seems to happen at random, though I've noticed it more when multiple tabs of the website are open.
Here is the logic:
This hook is also present in the root of my app to force an update if they refresh the page, but I don't think that is affecting the above code.
Here is the configuration for the PWA:
I don't see any errors appearing when this happens either, it just..doesn't work.
Any help is appreciated! Thanks.
Still an issue with 0.17.2.
I also had to increase the workbox.maximumFileSizeToCacheInBytes, maybe it could be related ?
We've implemented a window.location.reload() to be sure that the SW will be updated just after our updateServiceWorker(true)
There are some edge cases when running multiple clients (multiple tabs and browsers instances), it seems workbox-window not working properly (I guess it is a race condition)
About the reload, it should work in most cases (I did some tests with multiple clients, and sometimes some client cannot reload the window).
should be fixed in v0.18.0
I cannot get updateServiceWorker to either reload the page successfully or activate the waiting service worker for my reload prompt React component as of 0.19.8.
Update: I was missing the skipWait listener for my custom sw.js file as noted here.