fix(service-worker): do not enter degraded mode when offline (#22883)

Previously, when trying to fetch `ngsw.json` (e.g. during
`checkForUpdate()`) while either the client or the server were offline,
the ServiceWorker would enter a degrade mode, where only existing
clients would be served. This essentially meant that the ServiceWorker
didn't work offline.
This commit fixes it by differentiating offline errors and not entering
degraded mode. The ServiceWorker will remain in the current mode until
connectivity to the server is restored.

Fixes #21636

PR Close #22883
This commit is contained in:
George Kalpakas
2018-03-20 00:40:32 +02:00
committed by Alex Rickabaugh
parent d0f575bc54
commit ae9c25ff3d
3 changed files with 35 additions and 4 deletions

View File

@ -96,6 +96,7 @@ export class MockServerState {
private gate: Promise<void> = Promise.resolve();
private resolve: Function|null = null;
private resolveNextRequest: Function;
online = true;
nextRequest: Promise<Request>;
constructor(private resources: Map<string, Response>, private errors: Set<string>) {
@ -108,6 +109,10 @@ export class MockServerState {
await this.gate;
if (!this.online) {
throw new Error('Offline.');
}
if (req.credentials === 'include') {
return new MockResponse(null, {status: 0, statusText: '', type: 'opaque'});
}
@ -171,6 +176,7 @@ export class MockServerState {
this.nextRequest = new Promise(resolve => { this.resolveNextRequest = resolve; });
this.gate = Promise.resolve();
this.resolve = null;
this.online = true;
}
}