Skip to content

Commit 1f69cf9

Browse files
committed
Ensure that percent === NaN is consistently reported by the onProgress callback
With these changes `0`, `NaN`, `null`, and `undefined` in the `total`-property all result in `percent === NaN` being reported by the callback, since previously e.g. `0` would result in `percent === 100` being reported unconditionally which doesn't make a lot of sense. Also, remove the "indeterminate" loadingBar (in the viewer) if the `PDFDocumentLoadingTask` fails since there won't be any more data arriving and displaying the animation thus seems wrong.
1 parent 98dc351 commit 1f69cf9

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/display/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,9 @@ class WorkerTransport {
25242524
this.loadingTask.onProgress?.({
25252525
loaded,
25262526
total,
2527-
percent: MathClamp(Math.round((loaded / total) * 100), 0, 100),
2527+
percent: total
2528+
? MathClamp(Math.round((loaded / total) * 100), 0, 100)
2529+
: NaN,
25282530
});
25292531
}
25302532

web/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,10 @@ const PDFViewerApplication = {
12551255
if (loadingTask !== this.pdfLoadingTask) {
12561256
return undefined; // Ignore errors for previously opened PDF files.
12571257
}
1258+
if (this.loadingBar) {
1259+
// Avoid the "indeterminate" loadingBar being displayed on error.
1260+
this.loadingBar.percent ||= 0;
1261+
}
12581262

12591263
let key = "pdfjs-loading-error";
12601264
if (reason instanceof InvalidPDFException) {

web/firefoxcom.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,9 @@ class ExternalServices extends BaseExternalServices {
577577
pdfDataRangeTransport?.onDataProgressiveDone();
578578
break;
579579
case "progress":
580-
const percent = MathClamp(
581-
Math.round((args.loaded / args.total) * 100),
582-
0,
583-
100
584-
);
580+
const percent = args.total
581+
? MathClamp(Math.round((args.loaded / args.total) * 100), 0, 100)
582+
: NaN;
585583

586584
viewerApp.progress(percent);
587585
break;

0 commit comments

Comments
 (0)