Skip to content
代码片段 群组 项目
未验证 提交 8e813eea 编辑于 作者: Pranav K's avatar Pranav K 提交者: GitHub
浏览文件

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 https://github.com/dotnet/aspnetcore/issues/20256

* Fixup
上级 812f2f81
No related branches found
No related tags found
无相关合并请求
文件被 .gitattributes 条目压制或文件的编码不受支持。
文件被 .gitattributes 条目压制或文件的编码不受支持。
......@@ -85,7 +85,14 @@ export class WebAssemblyResourceLoader {
const cacheKey = toAbsoluteUri(`${url}.${contentHash}`);
this.usedCacheKeys[cacheKey] = true;
const cachedResponse = await cache.match(cacheKey);
let cachedResponse: Response | undefined;
try {
cachedResponse = await cache.match(cacheKey);
} catch {
// Be tolerant to errors reading from the cache. This is a guard for https://bugs.chromium.org/p/chromium/issues/detail?id=968444 where
// chromium browsers may sometimes throw when working with the cache.
}
if (cachedResponse) {
// It's in the cache.
const responseBytes = parseInt(cachedResponse.headers.get('content-length') || '0');
......@@ -136,12 +143,19 @@ export class WebAssemblyResourceLoader {
// Add to cache as a custom response object so we can track extra data such as responseBytes
// We can't rely on the server sending content-length (ASP.NET Core doesn't by default)
await cache.put(cacheKey, new Response(responseData, {
const responseToCache = new Response(responseData, {
headers: {
'content-type': response.headers.get('content-type') || '',
'content-length': (responseBytes || response.headers.get('content-length') || '').toString()
}
}));
});
try {
await cache.put(cacheKey, responseToCache);
} catch {
// Be tolerant to errors writing to the cache. This is a guard for https://bugs.chromium.org/p/chromium/issues/detail?id=968444 where
// chromium browsers may sometimes throw when performing cache operations.
}
}
}
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册