Skip to content

Commit 2ffd2e6

Browse files
Merge pull request #20827 from Snuffleupagus/worker-DocProgress-contentLength
Ensure that `percent === NaN` is consistently reported by the `onProgress` callback
2 parents 43fd680 + ddd69ce commit 2ffd2e6

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/core/worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class WorkerMessageHandler {
275275
if (!fullReader.isStreamingSupported) {
276276
handler.send("DocProgress", {
277277
loaded,
278-
total: Math.max(loaded, fullReader.contentLength || 0),
278+
total: fullReader.contentLength,
279279
});
280280
}
281281

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)