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
This commit is contained in:
Netanel Haber 2023-11-17 10:58:10 +02:00 committed by GitHub
parent 86c76c4461
commit 436ed8b8c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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