Skip to content

Commit 20caace

Browse files
committed
fix(PWA): avoid repeated notification of SW update
1 parent ac1731d commit 20caace

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

assets/js/pwa/app.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ if ('serviceWorker' in navigator) {
1818
.then(registration => {
1919
if (registration) {
2020
registration.addEventListener('updatefound', () => {
21-
/* console.log('updatefound'); */
2221
let serviceWorker = registration.installing;
2322

2423
serviceWorker.addEventListener('statechange', () => {
25-
/* console.log(`statechange -> ${serviceWorker.state}`); */
2624
if (serviceWorker.state === 'installed') {
27-
/* console.log('installed'); */
2825
if (navigator.serviceWorker.controller) {
2926
$notification.toast('show');
3027
/* in case the user ignores the notification */
@@ -39,9 +36,14 @@ if ('serviceWorker' in navigator) {
3936
$notification.toast('hide');
4037
});
4138

42-
/* there's a new Service Worker waiting to be activated */
4339
if (localStorage.getItem(keyWaiting)) {
44-
$notification.toast('show');
40+
if (registration.waiting) {
41+
/* there's a new Service Worker waiting to be activated */
42+
$notification.toast('show');
43+
} else {
44+
/* closed all open pages after receiving notification */
45+
localStorage.removeItem(keyWaiting);
46+
}
4547
}
4648
}
4749
});

0 commit comments

Comments
 (0)