Skip to content

Commit 9196cdd

Browse files
committed
fix(sw): prevent Firefox install failure on precache errors
1 parent bd3d39e commit 9196cdd

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/sw.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { CacheableResponsePlugin } from "workbox-cacheable-response";
33
import { cacheNames } from "workbox-core";
44
import { ExpirationPlugin } from "workbox-expiration";
5+
56
import {
67
registerRoute,
78
setCatchHandler,
@@ -12,7 +13,6 @@ import {
1213
NetworkOnly,
1314
StaleWhileRevalidate,
1415
} from "workbox-strategies";
15-
/* eslint-enable import/no-extraneous-dependencies */
1616

1717
const cacheName = cacheNames.runtime;
1818

@@ -25,13 +25,21 @@ const otherManifest = [
2525
url: "/app-shell/index.html",
2626
},
2727
];
28-
const manifestURLs = [...manifest, ...otherManifest].map((entry) => {
29-
const url = new URL(entry.url, self.location);
30-
return url.href;
31-
});
28+
const manifestURLs = [
29+
...new Set(
30+
[...manifest, ...otherManifest].map((entry) => {
31+
const url = new URL(entry.url, self.location);
32+
return url.href;
33+
}),
34+
),
35+
];
3236
self.addEventListener("install", (event) => {
3337
event.waitUntil(
34-
caches.open(cacheName).then((cache) => cache.addAll(manifestURLs)),
38+
(async () => {
39+
const cache = await caches.open(cacheName);
40+
41+
await Promise.allSettled(manifestURLs.map((url) => cache.add(url)));
42+
})(),
3543
);
3644
});
3745

0 commit comments

Comments
 (0)