vite-plugin-pwa
vite-plugin-pwa copied to clipboard
auto update should not equal reload page
I use autoUpdate registerType and the app will reload when new version deployed, but why reload? auto update should only download new version and update local cache, not reload page, reload page is a terrible experience . whether reload page should control by developer. I just want the worker auto download new version, and auto update while user visit the app next time.
@bimohxh it is the way the New sw will control again the app once new version cache ready, check sw lifecycle
@userquin I don't think so. just look this code https://github.com/vite-pwa/vite-plugin-pwa/blob/ea1a58bf6219233bddac1b663a8bf49c8e6c888e/src/client/build/register.ts
if (!event.isUpdate && event.isExternal)
window.location.reload()
else if (event.isUpdate)
auto && window.location.reload()
else if (!autoDestroy)
onOfflineReady?.()
wb?.addEventListener('controlling', (event) => {
if (event.isUpdate)
window.location.reload()
})
@bimohxh I wrote previous code, if you dont reload the window the new sw will not control the page that is being controlled by the current sw version (old one), check sw lifecycle for more info: https://web.dev/service-worker-lifecycle/
@userquin thanks. my question is why must controll the page at current session , why not controll at next time user enter the app? the auto mode process now is like:
user enter page --> mybe wait 5 seconds pwa find and download new version ---> auto reload
this is not friendly, my idea process is:
user enter page --> mybe wait 5 seconds pwa find and download new version ---> user enter page next time -> auto update in new version.
I also use pwa plugin @vue/cli-plugin-pwa
at vue2, which provides a config like:
import { register } from 'register-service-worker';
register(`${process.env.BASE_URL}service-worker.js`, {
ready() {},
....
updated() {
console.log('New content is available; please refresh.');
// window.location.reload();
}
as you can seee, I can decide whether need reload page at updated
envet.
@bimohxh then use prompt for update strategy, other logic is when there are other clients and the update comes from them.
@userquin but the prompt strategy will also disturb user, I just want to update app unconsciously, so I need auto strategy. thanks any way, I will remove window.location.reload
from the souce code if no options will be provided.
@bimohxh if you only want the sw to get updated you will need to remove any virtual from your code, Safari users will have problems using the PWA (previous sw will control the app and no the new one): check https://github.com/vite-pwa/vite-plugin-pwa/issues/438#issuecomment-1370171111
check the warning here: https://vite-pwa-org.netlify.app/guide/auto-update.html#automatic-reload