Skip to content

Commit f386cdb

Browse files
gkalpakAndrewKushnir
authored andcommitted
refactor(docs-infra): remove code that prints debug info (#46987)
In #41106, code was added in angular.io to print info that would help us investigate and debug a ServiceWorker issue (#28114). Since the fix for the issue was deployed on October 6th, 2021, the related error rate has dropped dramatically: ![ChunkLoadError rate](https://user-images.githubusercontent.com/8604205/181502119-64ffb5de-f38e-4414-abcd-0fada29fd6d5.png) Additionally, there have been no known occurrences or reports of the issue in the last several months. The remaining occurrences could be attributed to older versions still being around on people's devices (due to the ServiceWorker caching) and other circumstances not related to the ServiceWorker, for which there is not much we can do. For example, a user could keep a tab open with an older version of the app, which requests hashed files that no longer exist on the server. If the ServiceWorker is not activated on such a tab (either because the browser does not support it or because the user has disabled it, for example), then it is expected that these requests would fail. This commit removes the code that prints ServiceWorker-related debug info to reduce the payload size of the app. Fixes #41117 PR Close #46987
1 parent 9960710 commit f386cdb

2 files changed

Lines changed: 2 additions & 90 deletions

File tree

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

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ export class DocViewerComponent implements OnDestroy {
156156
this.nextViewContainer.textContent = '';
157157
this.setNoIndex(true);
158158

159-
// TODO(gkalpak): Remove this once gathering debug info is no longer needed.
160-
if (/loading chunk \S+ failed/i.test(errorMessage)) {
161-
// Print some info to help with debugging.
162-
// (There is no reason to wait for this async call to complete before continuing.)
163-
printSwDebugInfo();
164-
}
165-
166159
return this.void$;
167160
}),
168161
);
@@ -268,84 +261,3 @@ export class DocViewerComponent implements OnDestroy {
268261
);
269262
}
270263
}
271-
272-
// Helpers
273-
/**
274-
* Print some info regarding the ServiceWorker and the caches contents to help debugging potential
275-
* issues with failing to find resources in the cache.
276-
* (See https://github.com/angular/angular/issues/28114.)
277-
*/
278-
async function printSwDebugInfo(): Promise<void> {
279-
const sep = '\n----------';
280-
const swState = navigator.serviceWorker?.controller?.state ?? 'N/A';
281-
282-
console.log(`\nServiceWorker: ${swState}`);
283-
284-
if (typeof caches === 'undefined') {
285-
console.log(`${sep}\nCaches: N/A`);
286-
} else {
287-
const allCacheNames = await caches.keys();
288-
const swCacheNames = allCacheNames.filter(name => name.startsWith('ngsw:/:'));
289-
290-
await findCachesAndPrintEntries(swCacheNames, 'db:control', true, ['manifests']);
291-
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:cache', false);
292-
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:meta', true);
293-
}
294-
295-
if (swState === 'activated') {
296-
console.log(sep);
297-
await fetchAndPrintSwInternalDebugInfo();
298-
}
299-
300-
console.warn(
301-
`${sep}\nIf you see this error, please report an issue at ` +
302-
'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.');
303-
304-
// Internal helpers
305-
async function fetchAndPrintSwInternalDebugInfo() {
306-
try {
307-
const res = await fetch('/ngsw/state');
308-
if (!res.ok) {
309-
throw new Error(`Response ${res.status} ${res.statusText}`);
310-
}
311-
console.log(await res.text());
312-
} catch (err) {
313-
console.log(
314-
`Failed to retrieve debug info from '/ngsw/state': ${(err as Error).message || err}`);
315-
}
316-
}
317-
318-
async function findCachesAndPrintEntries(
319-
swCacheNames: string[], nameSuffix: string, includeValues: boolean,
320-
ignoredKeys: string[] = []): Promise<void> {
321-
const cacheNames = swCacheNames.filter(name => name.endsWith(nameSuffix));
322-
323-
for (const cacheName of cacheNames) {
324-
const cacheEntries = await getCacheEntries(cacheName, includeValues, ignoredKeys);
325-
await printCacheEntries(cacheName, cacheEntries);
326-
}
327-
}
328-
329-
async function getCacheEntries(name: string, includeValues: boolean, ignoredKeys: string[] = []):
330-
Promise<{key: string, value?: unknown}[]> {
331-
const ignoredUrls = new Set(ignoredKeys.map(key => new Request(key).url));
332-
333-
const cache = await caches.open(name);
334-
const keys = (await cache.keys()).map(req => req.url).filter(url => !ignoredUrls.has(url));
335-
const entries = await Promise.all(
336-
keys.map(async key => ({
337-
key,
338-
value: !includeValues ? undefined : await (await cache.match(key))?.json(),
339-
})));
340-
341-
return entries;
342-
}
343-
344-
function printCacheEntries(name: string, entries: {key: string, value?: unknown}[]): void {
345-
const entriesStr =
346-
entries.map(({key, value}) => ` - ${key}${!value ? '' : `: ${JSON.stringify(value)}`}`)
347-
.join('\n');
348-
349-
console.log(`\nCache: ${name} (${entries.length} entries)\n${entriesStr}`);
350-
}
351-
}

‎goldens/size-tracking/aio-payloads.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"aio": {
33
"uncompressed": {
44
"runtime": 4325,
5-
"main": 457028,
5+
"main": 454820,
66
"polyfills": 33814,
77
"styles": 73640,
88
"light-theme": 78276,
@@ -12,7 +12,7 @@
1212
"aio-local": {
1313
"uncompressed": {
1414
"runtime": 4325,
15-
"main": 457651,
15+
"main": 455179,
1616
"polyfills": 33922,
1717
"styles": 73640,
1818
"light-theme": 78045,

0 commit comments

Comments
 (0)