Skip to content

Commit e33aaba

Browse files
authored
fix: revert PR 633 (#673)
1 parent 4855128 commit e33aaba

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/client/build/register.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,7 @@ export function registerSW(options: RegisterSWOptions = {}) {
6969
}
7070
else {
7171
let onNeedRefreshCalled = false
72-
const showSkipWaitingPrompt = (event?: import('workbox-window').WorkboxLifecycleWaitingEvent) => {
73-
/*
74-
FIX:
75-
- open page in a new tab and navigate to home page
76-
- add a new sw version
77-
- open a new second tab and navigate to home page
78-
- click reload on the first tab
79-
- second tab refreshed, but the first tab doesn't (still with prompt)
80-
*/
81-
if (event && onNeedRefreshCalled && event.isExternal)
82-
window.location.reload()
83-
72+
const showSkipWaitingPrompt = () => {
8473
onNeedRefreshCalled = true
8574
// \`event.wasWaitingBeforeRegister\` will be false if this is
8675
// the first time the updated service worker is waiting.
@@ -94,7 +83,7 @@ export function registerSW(options: RegisterSWOptions = {}) {
9483
// that will reload the page as soon as the previously waiting
9584
// service worker has taken control.
9685
wb?.addEventListener('controlling', (event) => {
97-
if (event.isUpdate === true || event.isExternal === true)
86+
if (!event.isUpdate)
9887
window.location.reload()
9988
})
10089

@@ -122,6 +111,8 @@ export function registerSW(options: RegisterSWOptions = {}) {
122111
// Add an event listener to detect when the registered
123112
// service worker has installed but is waiting to activate.
124113
wb.addEventListener('waiting', showSkipWaitingPrompt)
114+
// @ts-expect-error event listener provided by workbox-window
115+
wb.addEventListener('externalwaiting', showSkipWaitingPrompt)
125116
}
126117
}
127118

0 commit comments

Comments
 (0)