From 24b8b3427c11d7b62f5e0c06372938ef6e611f43 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 26 Jul 2019 18:30:04 +0300 Subject: [PATCH] refactor(service-worker): remove redundant argument to `versionFailed()` (#31865) The `latest` argument was only ever set to the value of comparing `this.latestHash` with the `appVersion` hash, which is already computed inside `versionFailed()`, so there is no reason to pass it as an argument as well. This doesn't have any impact on the current behavior of the SW. PR Close #31865 --- packages/service-worker/worker/src/driver.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/service-worker/worker/src/driver.ts b/packages/service-worker/worker/src/driver.ts index 36337f072b719..a7513bc886826 100644 --- a/packages/service-worker/worker/src/driver.ts +++ b/packages/service-worker/worker/src/driver.ts @@ -194,7 +194,6 @@ export class Driver implements Debuggable, UpdateSource { // returning causes the request to fall back on the network. This is preferred over // `respondWith(fetch(req))` because the latter still shows in DevTools that the // request was handled by the SW. - // TODO: try to handle DriverReadyState.EXISTING_CLIENTS_ONLY here. if (this.state === DriverReadyState.SAFE_MODE) { // Even though the worker is in safe mode, idle tasks still need to happen so // things like update checks, etc. can take place. @@ -438,7 +437,7 @@ export class Driver implements Debuggable, UpdateSource { } catch (err) { if (err.isCritical) { // Something went wrong with the activation of this version. - await this.versionFailed(appVersion, err, this.latestHash === appVersion.manifestHash); + await this.versionFailed(appVersion, err); event.waitUntil(this.idle.trigger()); return this.safeFetch(event.request); @@ -575,7 +574,7 @@ export class Driver implements Debuggable, UpdateSource { // Attempt to schedule or initialize this version. If this operation is // successful, then initialization either succeeded or was scheduled. If // it fails, then full initialization was attempted and failed. - await this.scheduleInitialization(this.versions.get(hash) !, this.latestHash === hash); + await this.scheduleInitialization(this.versions.get(hash) !); } catch (err) { this.debugger.log(err, `initialize: schedule init of ${hash}`); return false; @@ -723,13 +722,13 @@ export class Driver implements Debuggable, UpdateSource { * when the SW is not busy and has connectivity. This returns a Promise which must be * awaited, as under some conditions the AppVersion might be initialized immediately. */ - private async scheduleInitialization(appVersion: AppVersion, latest: boolean): Promise { + private async scheduleInitialization(appVersion: AppVersion): Promise { const initialize = async() => { try { await appVersion.initializeFully(); } catch (err) { this.debugger.log(err, `initializeFully for ${appVersion.manifestHash}`); - await this.versionFailed(appVersion, err, latest); + await this.versionFailed(appVersion, err); } }; // TODO: better logic for detecting localhost. @@ -739,7 +738,7 @@ export class Driver implements Debuggable, UpdateSource { this.idle.schedule(`initialization(${appVersion.manifestHash})`, initialize); } - private async versionFailed(appVersion: AppVersion, err: Error, latest: boolean): Promise { + private async versionFailed(appVersion: AppVersion, err: Error): Promise { // This particular AppVersion is broken. First, find the manifest hash. const broken = Array.from(this.versions.entries()).find(([hash, version]) => version === appVersion); @@ -753,7 +752,7 @@ export class Driver implements Debuggable, UpdateSource { // The action taken depends on whether the broken manifest is the active (latest) or not. // If so, the SW cannot accept new clients, but can continue to service old ones. - if (this.latestHash === brokenHash || latest) { + if (this.latestHash === brokenHash) { // The latest manifest is broken. This means that new clients are at the mercy of the // network, but caches continue to be valid for previous versions. This is // unfortunate but unavoidable.