Skip to content

Commit

Permalink
fix: revert PR 633 (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Feb 28, 2024
1 parent 4855128 commit e33aaba
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/client/build/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
})

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit e33aaba

Please sign in to comment.