Skip to content

Commit 8e813ee

Browse files
authored
Workaround for DomException when invoking cache.put (#22756)
* Workaround for DomException when invoking cache.put Invoking cache.put could sometimes result in exceptions being thrown. While this seems to have been fixed in Chromium - https://bugs.chromium.org/p/chromium/issues/detail?id=968444, we've had several reports of this in our repo. The fix here is to write defensively when working with the cache apis since they appear to behave in unexpected ways.. Fixes #20256 * Fixup
1 parent 812f2f8 commit 8e813ee

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webassembly.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Platform/WebAssemblyResourceLoader.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ export class WebAssemblyResourceLoader {
8585
const cacheKey = toAbsoluteUri(`${url}.${contentHash}`);
8686
this.usedCacheKeys[cacheKey] = true;
8787

88-
const cachedResponse = await cache.match(cacheKey);
88+
let cachedResponse: Response | undefined;
89+
try {
90+
cachedResponse = await cache.match(cacheKey);
91+
} catch {
92+
// Be tolerant to errors reading from the cache. This is a guard for https://bugs.chromium.org/p/chromium/issues/detail?id=968444 where
93+
// chromium browsers may sometimes throw when working with the cache.
94+
}
95+
8996
if (cachedResponse) {
9097
// It's in the cache.
9198
const responseBytes = parseInt(cachedResponse.headers.get('content-length') || '0');
@@ -136,12 +143,19 @@ export class WebAssemblyResourceLoader {
136143

137144
// Add to cache as a custom response object so we can track extra data such as responseBytes
138145
// We can't rely on the server sending content-length (ASP.NET Core doesn't by default)
139-
await cache.put(cacheKey, new Response(responseData, {
146+
const responseToCache = new Response(responseData, {
140147
headers: {
141148
'content-type': response.headers.get('content-type') || '',
142149
'content-length': (responseBytes || response.headers.get('content-length') || '').toString()
143150
}
144-
}));
151+
});
152+
153+
try {
154+
await cache.put(cacheKey, responseToCache);
155+
} catch {
156+
// Be tolerant to errors writing to the cache. This is a guard for https://bugs.chromium.org/p/chromium/issues/detail?id=968444 where
157+
// chromium browsers may sometimes throw when performing cache operations.
158+
}
145159
}
146160
}
147161

0 commit comments

Comments
 (0)