Skip to content

Commit 88fed01

Browse files
committed
fixup! fix(docs-infra): print info to help debugging SW cache issue
1 parent 93c6beb commit 88fed01

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

aio/src/app/layout/doc-viewer/doc-viewer.component.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -259,49 +259,49 @@ export class DocViewerComponent implements OnDestroy {
259259
* issues with failing to find resources in the cache.
260260
* (See https://github.com/angular/angular/issues/28114.)
261261
*/
262-
async function printSwDebugInfo(): Promise<void> {
263-
console.log(`\nServiceWorker: ${navigator.serviceWorker?.controller?.state ?? 'N/A'}`);
264-
265-
if (typeof caches === 'undefined') {
266-
console.log('\nCaches: N/A');
267-
} else {
268-
const allCacheNames = await caches.keys();
269-
const swCacheNames = allCacheNames.filter(name => name.startsWith('ngsw:/:'));
270-
271-
await findCachesAndPrintEntries(swCacheNames, 'db:control', true, ['manifests']);
272-
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:cache', false);
273-
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:meta', true);
274-
}
262+
function printSwDebugInfo(): Promise<void> {
263+
return Promise.resolve()
264+
.then(() => console.log(`\nServiceWorker: ${navigator.serviceWorker?.controller?.state ?? 'N/A'}`))
265+
.then(() => {
266+
if (typeof caches === 'undefined') {
267+
return console.log('\nCaches: N/A');
268+
} else {
269+
return caches.keys().then(allCacheNames => {
270+
const swCacheNames = allCacheNames.filter(name => name.startsWith('ngsw:/:'));
271+
return findCachesAndPrintEntries(swCacheNames, 'db:control', true, ['manifests'])
272+
.then(() => findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:cache', false))
273+
.then(() => findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:meta', true));
274+
});
275+
}
276+
})
277+
.then(() => {
278+
console.warn(
279+
'\nIf you see this error, please report an issue at ' +
280+
'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.');
281+
});
275282

276-
console.warn(
277-
'\nIf you see this error, please report an issue at ' +
278-
'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.');
279283

280284
// Internal helpers
281-
async function findCachesAndPrintEntries(
285+
function findCachesAndPrintEntries(
282286
swCacheNames: string[], nameSuffix: string, includeValues = false,
283287
ignoredKeys: string[] = []): Promise<void> {
284288
const cacheNames = swCacheNames.filter(name => name.endsWith(nameSuffix));
285289

286-
for (const cacheName of cacheNames) {
287-
const cacheEntries = await getCacheEntries(cacheName, includeValues, ignoredKeys);
288-
await printCacheEntries(cacheName, cacheEntries);
289-
}
290+
return cacheNames.reduce((prev, cacheName) => prev
291+
.then(() => getCacheEntries(cacheName, includeValues, ignoredKeys))
292+
.then(cacheEntries => printCacheEntries(cacheName, cacheEntries)), Promise.resolve());
290293
}
291294

292-
async function getCacheEntries(
295+
function getCacheEntries(
293296
name: string, includeValues = false,
294297
ignoredKeys: string[] = []): Promise<{key: string, value?: object}[]> {
295298
const ignoredUrls = new Set(ignoredKeys.map(key => new Request(key).url));
296299

297-
const cache = await caches.open(name);
298-
const keys = (await cache.keys()).map(req => req.url).filter(url => !ignoredUrls.has(url));
299-
const entries = await Promise.all(keys.map(async key => ({
300-
key,
301-
value: !includeValues ? undefined : await (await cache.match(key))?.json(),
302-
})));
303-
304-
return entries;
300+
return caches.open(name).then(cache => cache.keys()
301+
.then(keys => keys.map(req => req.url).filter(url => !ignoredUrls.has(url)))
302+
.then(keys => Promise.all(keys.map(key => !includeValues ?
303+
{key} :
304+
cache.match(key).then(res => res?.json()).then(value => ({key, value}))))));
305305
}
306306

307307
function printCacheEntries(name: string, entries: {key: string, value?: object}[]): void {

goldens/size-tracking/aio-payloads.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"master": {
44
"uncompressed": {
55
"runtime-es2015": 3033,
6-
"main-es2015": 450959,
6+
"main-es2015": 450581,
77
"polyfills-es2015": 52343
88
}
99
}
@@ -12,7 +12,7 @@
1212
"master": {
1313
"uncompressed": {
1414
"runtime-es2015": 3033,
15-
"main-es2015": 451408,
15+
"main-es2015": 451030,
1616
"polyfills-es2015": 52493
1717
}
1818
}
@@ -21,7 +21,7 @@
2121
"master": {
2222
"uncompressed": {
2323
"runtime-es2015": 3153,
24-
"main-es2015": 437011,
24+
"main-es2015": 436633,
2525
"polyfills-es2015": 52493
2626
}
2727
}

0 commit comments

Comments
 (0)