Thanks! One problem here is that redux stores are not persistent. So if the user is pressing "refresh" on its browser instead of activating the waiting serviceworker, then the dialog wont pop up again. I solved that by
1) using redux-persist
2) not storing the the activated serviceworker inside the store, but getting it on the onClick() of the "update" button, just like this (very similar to Tomas Hornaks post, thank you too):
const activateUpdate = () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
const serviceWorkerWaiting = registration.waiting;
if (serviceWorkerWaiting) {
console.log("inside waiting...")
serviceWorkerWaiting.postMessage({ type: 'SKIP_WAITING' });
serviceWorkerWaiting.addEventListener('statechange', e => {
if (e.target.state === 'activated') {
dispatch(swUpdateDone());
window.location.reload();
}
});
}
});
}
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks! One problem here is that redux stores are not persistent. So if the user is pressing "refresh" on its browser instead of activating the waiting serviceworker, then the dialog wont pop up again. I solved that by
1) using redux-persist
2) not storing the the activated serviceworker inside the store, but getting it on the onClick() of the "update" button, just like this (very similar to Tomas Hornaks post, thank you too):