From 436ed8b8c212a44f560742252d9253b8cf70d5f3 Mon Sep 17 00:00:00 2001 From: Netanel Haber <58652339+netanel-haber@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:58:10 +0200 Subject: [PATCH] Fixed instant loading indicator in Chrome when serving gzipped (#6322) * bypass chrome event.total 0 when content gzipped by getting total off of Content-Length header * styling; NaN should be replaced with 0 as well, so no nullish coalescing won't work --- src/templates/assets/javascripts/browser/request/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/templates/assets/javascripts/browser/request/index.ts b/src/templates/assets/javascripts/browser/request/index.ts index 74a56a64d..3c050f9b8 100644 --- a/src/templates/assets/javascripts/browser/request/index.ts +++ b/src/templates/assets/javascripts/browser/request/index.ts @@ -85,7 +85,12 @@ export function request( // Handle download progress if (typeof options?.progress$ !== "undefined") { req.addEventListener("progress", event => { - options.progress$!.next((event.loaded / event.total) * 100) + if (event.lengthComputable) { + options.progress$!.next((event.loaded / event.total) * 100) + } else { // https://bugs.chromium.org/p/chromium/issues/detail?id=463622 + const totalFromHeader = Number(req.getResponseHeader("Content-Length")) || 0 + options.progress$!.next((event.loaded / totalFromHeader) * 100) + } }) // Immediately set progress to 5% to indicate that we're loading