Let a new service worker take over by itself
The update popup showed on installed PWAs after an update had already landed: the new worker sat waiting behind the open window. Nothing in the worker is per-version, so it now skips the wait on install, and the popup is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+9
-3
@@ -85,7 +85,14 @@ function isBypassRequest(url) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nothing the worker holds belongs to one version (navigations go to the
|
||||
* network, the code cache belongs to the build), so a new worker takes
|
||||
* over at once instead of waiting for every tab to close. It never
|
||||
* reloads a page: the open one keeps running, now served by it.
|
||||
*/
|
||||
self.addEventListener("install", (event) => {
|
||||
self.skipWaiting();
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) =>
|
||||
Promise.allSettled(SHELL.map((url) => cache.add(url))),
|
||||
@@ -190,9 +197,8 @@ async function cacheFirst(request) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The page asks for a new version from its update notice: nothing skips
|
||||
* the wait until the user says so. The loading page asks too, since it
|
||||
* isn't the app and nothing of the app's is running.
|
||||
* The loading page asks a waiting worker to take over. Workers from
|
||||
* before `install` skipped the wait on their own only answer this.
|
||||
*/
|
||||
self.addEventListener("message", (event) => {
|
||||
if (event.data?.type === "SKIP_WAITING") {
|
||||
|
||||
Reference in New Issue
Block a user