Fix service worker installation failure on Firefox#7755
Fix service worker installation failure on Firefox#7755pranjalisr wants to merge 15 commits intowebpack:mainfrom
Conversation
|
@pranjalisr is attempting to deploy a commit to the OpenJS Foundation Team on Vercel. A member of the Team first needs to authorize it. |
|
@alexander-akait Just following up to kindly request a review of this PR when you have availability. |
|
@evenstensberg Can you look at this and test, I think we can merge it |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
src/sw.js
Outdated
| event.waitUntil( | ||
| caches.open(cacheName).then((cache) => { | ||
| // clean up those who are not listed in manifestURLs | ||
| // clean up those who are not listed in manifestURLs |
There was a problem hiding this comment.
comments should be where they were earlier so the diff is good.
| } | ||
| }), | ||
| ); | ||
| })(), |
There was a problem hiding this comment.
On each manifest item we generate fetch, don't look like a good idea, it kills the idea of cache, looks like AI generate without understanding
There was a problem hiding this comment.
My intention was specifically to prevent Firefox from aborting the install when a single precache request fails. I agree the manual fetch approach isn’t ideal for precaching. I am happy to adjust it.
What pattern would you recommend here?
There was a problem hiding this comment.
We need to minimize amount of fetches in the service worker script (this one), so maybe we can re-fetch the failed script instead of all? Maybe that works?
There was a problem hiding this comment.
One approach could be to keep cache.addAll(manifestURLs) as it is & identify the specific URL that fails in Firefox and exclude it from the precache list (or handle it separately), instead of changing the entire install logic.
Does that sound good, or would you suggest a different pattern here?
|
Tested in Firefox using production build (yarn build + yarn serve-dist). Service worker installs successfully and no longer aborts on install.
@evenstensberg Can you please check this? If this sounds Ok then I will push the code changes. |

Summary
This PR fixes a Firefox-specific issue where the service worker fails to install or register. Fixes #7738
Firefox aborts installation if any promise inside
event.waitUntil()rejects.The previous implementation used
cache.addAll(), which can reject when a single precache request fails (e.g.,/manifest.json,/app-shell/index.html, or a Workbox manifest entry).As a result, the entire service worker installation failed on Firefox, even though it worked on Chrome.
This PR replaces
cache.addAll()with defensive per-request caching so that failed precache requests no longer break the install event.What kind of change does this PR introduce?
fix— Prevents service worker installation from failing on Firefox by using safe, per-request precaching.Did you add tests for your changes?
No.
Service worker behavior differs between browsers and is not currently covered by automated tests in this repository.
This fix is isolated to the SW script and does not affect build output.
Does this PR introduce a breaking change?
No.
Chrome and other browsers behave exactly the same as before.
Only Firefox benefits from the more resilient install logic.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
No documentation changes are required.
The service worker behavior is internal and this update does not modify public APIs or user-facing features.