Skip to content

Commit e5b0a97

Browse files
atscottAndrewKushnir
authored andcommitted
Revert "feat(service-worker): notify clients about version failures (angular#62718)"
This reverts commit 6d01168. issue angular#63500 reproduces at head on the main branch in the dev app. Reverting this change along resolves it. fixes angular#63500 (cherry picked from commit 4af408a)
1 parent a278ee3 commit e5b0a97

File tree

6 files changed

+2
-66
lines changed

6 files changed

+2
-66
lines changed

goldens/public-api/service-worker/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface VersionDetectedEvent {
110110
}
111111

112112
// @public
113-
export type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | VersionFailedEvent | NoNewVersionDetectedEvent;
113+
export type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | NoNewVersionDetectedEvent;
114114

115115
// @public
116116
export interface VersionInstallationFailedEvent {

packages/service-worker/src/low_level.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,6 @@ export interface VersionReadyEvent {
7070
latestVersion: {hash: string; appData?: object};
7171
}
7272

73-
/**
74-
* An event emitted when a specific version of the app has encountered a critical failure
75-
* that prevents it from functioning correctly.
76-
*
77-
* When a version fails, the service worker will notify all clients currently using that version
78-
* and may degrade to serving only existing clients if the failed version was the latest one.
79-
*
80-
* @see {@link /ecosystem/service-workers/communications Service Worker Communication Guide}
81-
*
82-
* @publicApi
83-
*/
84-
export interface VersionFailedEvent {
85-
type: 'VERSION_FAILED';
86-
version: {hash: string; appData?: object};
87-
error: string;
88-
}
89-
9073
/**
9174
* A union of all event types that can be emitted by
9275
* {@link SwUpdate#versionUpdates}.
@@ -97,7 +80,6 @@ export type VersionEvent =
9780
| VersionDetectedEvent
9881
| VersionInstallationFailedEvent
9982
| VersionReadyEvent
100-
| VersionFailedEvent
10183
| NoNewVersionDetectedEvent;
10284

10385
/**

packages/service-worker/src/update.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export class SwUpdate {
6969
'VERSION_INSTALLATION_FAILED',
7070
'VERSION_READY',
7171
'NO_NEW_VERSION_DETECTED',
72-
'VERSION_FAILED',
7372
]);
7473
this.unrecoverable = this.sw.eventsOfType<UnrecoverableStateEvent>('UNRECOVERABLE_STATE');
7574
}

packages/service-worker/test/comm_spec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
NoNewVersionDetectedEvent,
1414
VersionDetectedEvent,
1515
VersionEvent,
16-
VersionFailedEvent,
1716
VersionReadyEvent,
1817
} from '../src/low_level';
1918
import {ngswCommChannelFactory, SwRegistrationOptions} from '../src/provider';
@@ -510,25 +509,6 @@ describe('ServiceWorker library', () => {
510509
},
511510
});
512511
});
513-
it('processes version failed events with cache corruption error', (done) => {
514-
update.versionUpdates.subscribe((event) => {
515-
expect(event.type).toEqual('VERSION_FAILED');
516-
expect((event as VersionFailedEvent).version).toEqual({
517-
hash: 'B',
518-
appData: {name: 'test-app'},
519-
});
520-
expect((event as VersionFailedEvent).error).toContain('Cache corruption detected');
521-
done();
522-
});
523-
mock.sendMessage({
524-
type: 'VERSION_FAILED',
525-
version: {
526-
hash: 'B',
527-
appData: {name: 'test-app'},
528-
},
529-
error: 'Cache corruption detected during resource fetch',
530-
});
531-
});
532512
it('activates updates when requested', async () => {
533513
mock.messages.subscribe((msg: {action: string; nonce: number}) => {
534514
expect(msg.action).toEqual('ACTIVATE_UPDATE');

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,7 @@ export class Driver implements Debuggable, UpdateSource {
992992
// Therefore, we keep clients on their current version (even if broken) and ensure that no new
993993
// clients will be assigned to it.
994994

995-
// Notify clients that are using this broken version about the failure.
996-
await this.notifyClientsAboutVersionFailure(brokenHash, err);
995+
// TODO: notify affected apps.
997996

998997
// The action taken depends on whether the broken manifest is the active (latest) or not.
999998
// - If the broken version is not the latest, no further action is necessary, since new clients
@@ -1335,29 +1334,6 @@ export class Driver implements Debuggable, UpdateSource {
13351334
);
13361335
}
13371336

1338-
async notifyClientsAboutVersionFailure(brokenHash: string, error: Error): Promise<void> {
1339-
await this.initialized;
1340-
1341-
// Find all clients using the broken version
1342-
const affectedClients = Array.from(this.clientVersionMap.entries())
1343-
.filter(([clientId, hash]) => hash === brokenHash)
1344-
.map(([clientId]) => clientId);
1345-
1346-
await Promise.all(
1347-
affectedClients.map(async (clientId) => {
1348-
const client = await this.scope.clients.get(clientId);
1349-
if (client) {
1350-
const brokenVersion = this.versions.get(brokenHash);
1351-
client.postMessage({
1352-
type: 'VERSION_FAILED',
1353-
version: this.mergeHashWithAppData(brokenVersion!.manifest, brokenHash),
1354-
error: errorToString(error),
1355-
});
1356-
}
1357-
}),
1358-
);
1359-
}
1360-
13611337
async broadcast(msg: Object): Promise<void> {
13621338
const clients = await this.scope.clients.matchAll();
13631339
clients.forEach((client) => {

packages/service-worker/worker/test/happy_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,6 @@ import {envIsSupported} from '../testing/utils';
25942594
expect(await makeRequest(scope, '/foo.hash.js', 'client-2')).toBeNull();
25952595
expect(mockClient2.messages).toEqual([
25962596
jasmine.objectContaining({type: 'UNRECOVERABLE_STATE'}),
2597-
jasmine.objectContaining({type: 'VERSION_FAILED'}),
25982597
]);
25992598

26002599
// This should also enter the `SW` into degraded mode, because the broken version was the

0 commit comments

Comments
 (0)