@@ -69,18 +69,7 @@ export function registerSW(options: RegisterSWOptions = {}) {
69
69
}
70
70
else {
71
71
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 = ( ) => {
84
73
onNeedRefreshCalled = true
85
74
// \`event.wasWaitingBeforeRegister\` will be false if this is
86
75
// the first time the updated service worker is waiting.
@@ -94,7 +83,7 @@ export function registerSW(options: RegisterSWOptions = {}) {
94
83
// that will reload the page as soon as the previously waiting
95
84
// service worker has taken control.
96
85
wb ?. addEventListener ( 'controlling' , ( event ) => {
97
- if ( event . isUpdate === true || event . isExternal === true )
86
+ if ( ! event . isUpdate )
98
87
window . location . reload ( )
99
88
} )
100
89
@@ -122,6 +111,8 @@ export function registerSW(options: RegisterSWOptions = {}) {
122
111
// Add an event listener to detect when the registered
123
112
// service worker has installed but is waiting to activate.
124
113
wb . addEventListener ( 'waiting' , showSkipWaitingPrompt )
114
+ // @ts -expect-error event listener provided by workbox-window
115
+ wb . addEventListener ( 'externalwaiting' , showSkipWaitingPrompt )
125
116
}
126
117
}
127
118
0 commit comments