Merge pull request #20827 from Snuffleupagus/worker-DocProgress-contentLength

Ensure that `percent === NaN` is consistently reported by the `onProgress` callback
This commit is contained in:
Tim van der Meij 2026-03-08 10:58:29 +01:00 committed by GitHub
commit 2ffd2e65dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 7 deletions

View File

@ -275,7 +275,7 @@ class WorkerMessageHandler {
if (!fullReader.isStreamingSupported) {
handler.send("DocProgress", {
loaded,
total: Math.max(loaded, fullReader.contentLength || 0),
total: fullReader.contentLength,
});
}

View File

@ -2524,7 +2524,9 @@ class WorkerTransport {
this.loadingTask.onProgress?.({
loaded,
total,
percent: MathClamp(Math.round((loaded / total) * 100), 0, 100),
percent: total
? MathClamp(Math.round((loaded / total) * 100), 0, 100)
: NaN,
});
}

View File

@ -1255,6 +1255,10 @@ const PDFViewerApplication = {
if (loadingTask !== this.pdfLoadingTask) {
return undefined; // Ignore errors for previously opened PDF files.
}
if (this.loadingBar) {
// Avoid the "indeterminate" loadingBar being displayed on error.
this.loadingBar.percent ||= 0;
}
let key = "pdfjs-loading-error";
if (reason instanceof InvalidPDFException) {

View File

@ -577,11 +577,9 @@ class ExternalServices extends BaseExternalServices {
pdfDataRangeTransport?.onDataProgressiveDone();
break;
case "progress":
const percent = MathClamp(
Math.round((args.loaded / args.total) * 100),
0,
100
);
const percent = args.total
? MathClamp(Math.round((args.loaded / args.total) * 100), 0, 100)
: NaN;
viewerApp.progress(percent);
break;