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:

committed by
Alex Rickabaugh

parent
d0f575bc54
commit
ae9c25ff3d
@ -516,6 +516,17 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
|
||||
expect(await scope.caches.keys()).toEqual([]);
|
||||
});
|
||||
|
||||
async_it('does not unregister or change state when offline (i.e. manifest 504s)', async() => {
|
||||
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
|
||||
await driver.initialized;
|
||||
server.online = false;
|
||||
|
||||
expect(await driver.checkForUpdate()).toEqual(false);
|
||||
expect(driver.state).toEqual(DriverReadyState.NORMAL);
|
||||
expect(scope.unregistered).toBeFalsy();
|
||||
expect(await scope.caches.keys()).not.toEqual([]);
|
||||
});
|
||||
|
||||
describe('unhashed requests', () => {
|
||||
async_beforeEach(async() => {
|
||||
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
|
||||
|
Reference in New Issue
Block a user