-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix service worker installation failure on Firefox #7755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
9196cdd
670d441
4b91860
c72b3a5
f5e7e04
9bfa412
4fe19fc
574e27c
25da846
a5e552a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ import { | |
| NetworkOnly, | ||
| StaleWhileRevalidate, | ||
| } from "workbox-strategies"; | ||
| /* eslint-enable import/no-extraneous-dependencies */ | ||
|
|
||
| const cacheName = cacheNames.runtime; | ||
|
|
||
|
|
@@ -25,16 +24,23 @@ const otherManifest = [ | |
| url: "/app-shell/index.html", | ||
| }, | ||
| ]; | ||
| const manifestURLs = [...manifest, ...otherManifest].map((entry) => { | ||
| const url = new URL(entry.url, self.location); | ||
| return url.href; | ||
| }); | ||
| const manifestURLs = [ | ||
| ...new Set( | ||
| [...manifest, ...otherManifest].map((entry) => { | ||
| const url = new URL(entry.url, self.location); | ||
| return url.href; | ||
| }), | ||
| ), | ||
| ]; | ||
| self.addEventListener("install", (event) => { | ||
| event.waitUntil( | ||
| caches.open(cacheName).then((cache) => cache.addAll(manifestURLs)), | ||
| (async () => { | ||
| const cache = await caches.open(cacheName); | ||
|
|
||
| await Promise.allSettled(manifestURLs.map((url) => cache.add(url))); | ||
| })(), | ||
|
ovflowd marked this conversation as resolved.
|
||
| ); | ||
| }); | ||
|
|
||
| self.addEventListener("activate", (event) => { | ||
| // - [x] clean up outdated runtime cache | ||
| event.waitUntil( | ||
|
|
@@ -52,7 +58,6 @@ self.addEventListener("activate", (event) => { | |
| ), | ||
| ); | ||
| }); | ||
|
|
||
| registerRoute( | ||
| ({ url }) => manifestURLs.includes(url.href), | ||
| new NetworkFirst({ | ||
|
|
@@ -87,6 +92,6 @@ setCatchHandler(({ event }) => { | |
| case "document": | ||
| return caches.match("/app-shell/index.html"); | ||
| default: | ||
| return Response.error(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont remove the error handling please |
||
| return fetch(event.request); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think this is smart. Lets say something is wrong with your computer and it doesnt have a good network. You will always re-fetch until it suceeds. will be very expensive an circular-loop.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed the fetch(event.request) fallback. |
||
| } | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.