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) { if (!fullReader.isStreamingSupported) {
handler.send("DocProgress", { handler.send("DocProgress", {
loaded, loaded,
total: Math.max(loaded, fullReader.contentLength || 0), total: fullReader.contentLength,
}); });
} }

View File

@ -2524,7 +2524,9 @@ class WorkerTransport {
this.loadingTask.onProgress?.({ this.loadingTask.onProgress?.({
loaded, loaded,
total, 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) { if (loadingTask !== this.pdfLoadingTask) {
return undefined; // Ignore errors for previously opened PDF files. 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"; let key = "pdfjs-loading-error";
if (reason instanceof InvalidPDFException) { if (reason instanceof InvalidPDFException) {

View File

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