From 5be4edfa17120ab1b9c9e8d87b7b539cdd180a25 Mon Sep 17 00:00:00 2001 From: Sonu Kapoor Date: Tue, 28 Jul 2020 08:41:15 -0400 Subject: [PATCH] fix(service-worker): fix condition to check for a cache-busted request (#36847) Previously, the condition to make the cache busted was executing although the network request was successful. However, this is not valid. The cache should only be marked as busted when the request failed. This commit fixes the invalid condition. PR Close #36847 --- packages/service-worker/worker/src/assets.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/service-worker/worker/src/assets.ts b/packages/service-worker/worker/src/assets.ts index 90e639d651..bfb8a66413 100644 --- a/packages/service-worker/worker/src/assets.ts +++ b/packages/service-worker/worker/src/assets.ts @@ -393,8 +393,8 @@ export abstract class AssetGroup { // reasons: either the non-cache-busted request failed (hopefully transiently) or if the // hash of the content retrieved does not match the canonical hash from the manifest. It's // only valid to access the content of the first response if the request was successful. - let makeCacheBustedRequest: boolean = networkResult.ok; - if (makeCacheBustedRequest) { + let makeCacheBustedRequest: boolean = !networkResult.ok; + if (networkResult.ok) { // The request was successful. A cache-busted request is only necessary if the hashes // don't match. Compare them, making sure to clone the response so it can be used later // if it proves to be valid.