From b3c07f4b3d1390fe2b84bf7283daf62926bb8f93 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 12 Feb 2026 17:49:22 +0100 Subject: [PATCH] Avoid parsing skipped range requests in `ChunkedStreamManager` (PR 10694 follow-up) While we don't dispatch the actual range request after PR 10694 we still parse the returned data, which ends up being an *empty* `ArrayBuffer` and thus cannot affect the `ChunkedStream.prototype._loadedChunks` property. Given that no actual data arrived, it's thus pointless[1] to invoke the `ChunkedStreamManager.prototype.onReceiveData` method in this case (and it also avoids sending effectively duplicate "DocProgress" messages). --- [1] With the *possible* exception of `disableAutoFetch === false` being set, see https://github.com/mozilla/pdf.js/blob/f24768d7b4ef0f64976a7f9e80e15ef50c759356/src/core/chunked_stream.js#L499-L517 however that never happens when streaming is being used; note https://github.com/mozilla/pdf.js/blob/f24768d7b4ef0f64976a7f9e80e15ef50c759356/src/core/worker.js#L237-L238 --- src/core/chunked_stream.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 642323fae223a..3b712c15a8060 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -301,7 +301,11 @@ class ChunkedStreamManager { const readChunk = ({ value, done }) => { try { if (done) { - resolve(arrayBuffersToBytes(chunks)); + resolve( + chunks.length > 0 || !this.disableAutoFetch + ? arrayBuffersToBytes(chunks) + : null + ); chunks = null; return; } @@ -322,6 +326,11 @@ class ChunkedStreamManager { if (this.aborted) { return; // Ignoring any data after abort. } + if (!data) { + // The range request wasn't dispatched, see the "GetRangeReader" handler + // in the `src/display/api.js` file. + return; + } this.onReceiveData({ chunk: data.buffer, begin }); }); }