From e33aabadb50e6caa76dbf612bb417d781f40b47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Wed, 28 Feb 2024 14:37:10 +0100 Subject: [PATCH] fix: revert PR 633 (#673) --- src/client/build/register.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/client/build/register.ts b/src/client/build/register.ts index 5a27f0fe..3bc2570a 100644 --- a/src/client/build/register.ts +++ b/src/client/build/register.ts @@ -69,18 +69,7 @@ export function registerSW(options: RegisterSWOptions = {}) { } else { let onNeedRefreshCalled = false - const showSkipWaitingPrompt = (event?: import('workbox-window').WorkboxLifecycleWaitingEvent) => { - /* - FIX: - - open page in a new tab and navigate to home page - - add a new sw version - - open a new second tab and navigate to home page - - click reload on the first tab - - second tab refreshed, but the first tab doesn't (still with prompt) - */ - if (event && onNeedRefreshCalled && event.isExternal) - window.location.reload() - + const showSkipWaitingPrompt = () => { onNeedRefreshCalled = true // \`event.wasWaitingBeforeRegister\` will be false if this is // the first time the updated service worker is waiting. @@ -94,7 +83,7 @@ export function registerSW(options: RegisterSWOptions = {}) { // that will reload the page as soon as the previously waiting // service worker has taken control. wb?.addEventListener('controlling', (event) => { - if (event.isUpdate === true || event.isExternal === true) + if (!event.isUpdate) window.location.reload() }) @@ -122,6 +111,8 @@ export function registerSW(options: RegisterSWOptions = {}) { // Add an event listener to detect when the registered // service worker has installed but is waiting to activate. wb.addEventListener('waiting', showSkipWaitingPrompt) + // @ts-expect-error event listener provided by workbox-window + wb.addEventListener('externalwaiting', showSkipWaitingPrompt) } }