mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
Revert "feat(service-worker): notify clients about version failures (#62718)"
This reverts commit 6d011687ec.
issue #63500 reproduces at head on the main branch in the dev app.
Reverting this change along resolves it.
fixes https://github.com/angular/angular/issues/63500
This commit is contained in:
committed by
Andrew Kushnir
parent
d337cfb68f
commit
4af408afcb
@@ -110,7 +110,7 @@ export interface VersionDetectedEvent {
|
||||
}
|
||||
|
||||
// @public
|
||||
export type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | VersionFailedEvent | NoNewVersionDetectedEvent;
|
||||
export type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | NoNewVersionDetectedEvent;
|
||||
|
||||
// @public
|
||||
export interface VersionInstallationFailedEvent {
|
||||
|
||||
@@ -70,23 +70,6 @@ export interface VersionReadyEvent {
|
||||
latestVersion: {hash: string; appData?: object};
|
||||
}
|
||||
|
||||
/**
|
||||
* An event emitted when a specific version of the app has encountered a critical failure
|
||||
* that prevents it from functioning correctly.
|
||||
*
|
||||
* When a version fails, the service worker will notify all clients currently using that version
|
||||
* and may degrade to serving only existing clients if the failed version was the latest one.
|
||||
*
|
||||
* @see {@link /ecosystem/service-workers/communications Service Worker Communication Guide}
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface VersionFailedEvent {
|
||||
type: 'VERSION_FAILED';
|
||||
version: {hash: string; appData?: object};
|
||||
error: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A union of all event types that can be emitted by
|
||||
* {@link SwUpdate#versionUpdates}.
|
||||
@@ -97,7 +80,6 @@ export type VersionEvent =
|
||||
| VersionDetectedEvent
|
||||
| VersionInstallationFailedEvent
|
||||
| VersionReadyEvent
|
||||
| VersionFailedEvent
|
||||
| NoNewVersionDetectedEvent;
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,6 @@ export class SwUpdate {
|
||||
'VERSION_INSTALLATION_FAILED',
|
||||
'VERSION_READY',
|
||||
'NO_NEW_VERSION_DETECTED',
|
||||
'VERSION_FAILED',
|
||||
]);
|
||||
this.unrecoverable = this.sw.eventsOfType<UnrecoverableStateEvent>('UNRECOVERABLE_STATE');
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
NoNewVersionDetectedEvent,
|
||||
VersionDetectedEvent,
|
||||
VersionEvent,
|
||||
VersionFailedEvent,
|
||||
VersionReadyEvent,
|
||||
} from '../src/low_level';
|
||||
import {ngswCommChannelFactory, SwRegistrationOptions} from '../src/provider';
|
||||
@@ -510,25 +509,6 @@ describe('ServiceWorker library', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
it('processes version failed events with cache corruption error', (done) => {
|
||||
update.versionUpdates.subscribe((event) => {
|
||||
expect(event.type).toEqual('VERSION_FAILED');
|
||||
expect((event as VersionFailedEvent).version).toEqual({
|
||||
hash: 'B',
|
||||
appData: {name: 'test-app'},
|
||||
});
|
||||
expect((event as VersionFailedEvent).error).toContain('Cache corruption detected');
|
||||
done();
|
||||
});
|
||||
mock.sendMessage({
|
||||
type: 'VERSION_FAILED',
|
||||
version: {
|
||||
hash: 'B',
|
||||
appData: {name: 'test-app'},
|
||||
},
|
||||
error: 'Cache corruption detected during resource fetch',
|
||||
});
|
||||
});
|
||||
it('activates updates when requested', async () => {
|
||||
mock.messages.subscribe((msg: {action: string; nonce: number}) => {
|
||||
expect(msg.action).toEqual('ACTIVATE_UPDATE');
|
||||
|
||||
@@ -992,8 +992,7 @@ export class Driver implements Debuggable, UpdateSource {
|
||||
// Therefore, we keep clients on their current version (even if broken) and ensure that no new
|
||||
// clients will be assigned to it.
|
||||
|
||||
// Notify clients that are using this broken version about the failure.
|
||||
await this.notifyClientsAboutVersionFailure(brokenHash, err);
|
||||
// TODO: notify affected apps.
|
||||
|
||||
// The action taken depends on whether the broken manifest is the active (latest) or not.
|
||||
// - 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 {
|
||||
);
|
||||
}
|
||||
|
||||
async notifyClientsAboutVersionFailure(brokenHash: string, error: Error): Promise<void> {
|
||||
await this.initialized;
|
||||
|
||||
// Find all clients using the broken version
|
||||
const affectedClients = Array.from(this.clientVersionMap.entries())
|
||||
.filter(([clientId, hash]) => hash === brokenHash)
|
||||
.map(([clientId]) => clientId);
|
||||
|
||||
await Promise.all(
|
||||
affectedClients.map(async (clientId) => {
|
||||
const client = await this.scope.clients.get(clientId);
|
||||
if (client) {
|
||||
const brokenVersion = this.versions.get(brokenHash);
|
||||
client.postMessage({
|
||||
type: 'VERSION_FAILED',
|
||||
version: this.mergeHashWithAppData(brokenVersion!.manifest, brokenHash),
|
||||
error: errorToString(error),
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async broadcast(msg: Object): Promise<void> {
|
||||
const clients = await this.scope.clients.matchAll();
|
||||
clients.forEach((client) => {
|
||||
|
||||
@@ -2594,7 +2594,6 @@ import {envIsSupported} from '../testing/utils';
|
||||
expect(await makeRequest(scope, '/foo.hash.js', 'client-2')).toBeNull();
|
||||
expect(mockClient2.messages).toEqual([
|
||||
jasmine.objectContaining({type: 'UNRECOVERABLE_STATE'}),
|
||||
jasmine.objectContaining({type: 'VERSION_FAILED'}),
|
||||
]);
|
||||
|
||||
// This should also enter the `SW` into degraded mode, because the broken version was the
|
||||
|
||||
Reference in New Issue
Block a user