Skip to content

Commit

Permalink
Updated the code
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitBhalla committed May 8, 2021
1 parent 8ef7d1c commit 90e0e99
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ function Analytics() {
return null;
}

let reloadInterval;

// Avoid infinite loop when "Upload on reload" is set in the Chrome sw dev tools.
function lazyReload() {
clearInterval(reloadInterval);
reloadInterval = setInterval(() => {
if (document.hasFocus()) {
window.location.reload();
}
}, 100);
}

// Inspired by
// https://developers.google.com/web/tools/workbox/guides/advanced-recipes#offer_a_page_reload_for_users
function forcePageReload(registration) {
Expand Down Expand Up @@ -192,7 +204,7 @@ function forcePageReload(registration) {
registration.waiting.postMessage('skipWaiting');
} else if (event.target.state === 'activated') {
// Force the control of the page by the activated service worker.
window.location.reload();
lazyReload();
}
});
}
Expand Down

0 comments on commit 90e0e99

Please sign in to comment.