Skip to content

Commit dcaad16

Browse files
JeanMechedylhunn
authored andcommitted
fix(service-worker): throw a critical error when handleFetch fails (#51885)
On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch()` in the `Driver`. fixes: #50378 PR Close #51885
1 parent 8be2c48 commit dcaad16

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/service-worker/worker/src/assets.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,17 @@ export abstract class AssetGroup {
128128

129129
// Look for a cached response. If one exists, it can be used to resolve the fetch
130130
// operation.
131-
const cachedResponse = await cache.match(req, this.config.cacheQueryOptions);
131+
let cachedResponse: Response|undefined;
132+
try {
133+
// Safari 16.4/17 is known to sometimes throw an unexpected internal error on cache access
134+
// This try/catch is here as a workaround to prevent a failure of the handleFetch
135+
// as the Driver falls back to safeFetch on critical errors.
136+
// See #50378
137+
cachedResponse = await cache.match(req, this.config.cacheQueryOptions);
138+
} catch (error) {
139+
throw new SwCriticalError(`Cache is throwing while looking for a match: ${error}`);
140+
}
141+
132142
if (cachedResponse !== undefined) {
133143
// A response has already been cached (which presumably matches the hash for this
134144
// resource). Check whether it's safe to serve this resource from cache.

0 commit comments

Comments
 (0)