Skip to content

[api-minor] Remove the length parameter from getDocument#20840

Merged
timvandermeij merged 1 commit intomozilla:masterfrom
Snuffleupagus:getDocument-rm-length
Mar 15, 2026
Merged

[api-minor] Remove the length parameter from getDocument#20840
timvandermeij merged 1 commit intomozilla:masterfrom
Snuffleupagus:getDocument-rm-length

Conversation

@Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Mar 10, 2026

This is an old API-parameter that is now unused within the PDF.js project itself, and its description says that it's (partly) being used for "range requests operations".
Note that the length API-parameter is used to set the initial contentLength in various BasePDFStreamReader implementations, however it's always overridden by the "Content-Length" header (sent by the server) when that one exists and is a valid number. While we currently fallback to the keep the initial contentLength otherwise, note however how in that case range requests will always be disabled and thus the only spot in the code-base where fullReader.contentLength is necessary cannot actually be reached.

Hence the only possible reason to use the length API-parameter would be for improved progress reporting[1] during streaming of PDF data in rare cases where the "Content-Length" header is missing/invalid, but the user somehow has information from another source about the correct length of the PDF document.
That situation feels very much like an edge-case, but it's obviously impossible to know if someone is depending on it. However, please note that there's a work-around available for users affected by this removal:

  • Implement a PDFDataRangeTransport instance together with custom data-fetching[2], since in that case its length-parameter will always be used as-is.

Finally, updates various BasePDFStreamReader implementations to only set the _isRangeSupported field once the headers are available (since previously we'd just overwrite the "initial" value anyway).


[1] I.e. to avoid the "indeterminate" loadingBar being displayed in the viewer.

[2] This is what e.g. the Firefox PDF Viewer uses.

@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.55%. Comparing base (a7083d0) to head (09a9a7b).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/display/network.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20840      +/-   ##
==========================================
+ Coverage   62.53%   62.55%   +0.01%     
==========================================
  Files         171      173       +2     
  Lines      121171   121194      +23     
==========================================
+ Hits        75779    75817      +38     
+ Misses      45392    45377      -15     
Flag Coverage Δ
fonttest 7.66% <ø> (?)
unittestcli 62.53% <80.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Snuffleupagus Snuffleupagus force-pushed the getDocument-rm-length branch 3 times, most recently from 5456a47 to cc48e58 Compare March 13, 2026 20:19
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.241.84.105:8877/1397e4fa7998f61/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.193.163.58:8877/e99fff493d2b1aa/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/1397e4fa7998f61/output.txt

Total script time: 44.89 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 1

Image differences available at: http://54.241.84.105:8877/1397e4fa7998f61/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/e99fff493d2b1aa/output.txt

Total script time: 70.50 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 1

Image differences available at: http://54.193.163.58:8877/e99fff493d2b1aa/reftest-analyzer.html#web=eq.log

This is an old API-parameter that is now unused within the PDF.js project itself, and its description says that it's (partly) being used for "range requests operations".
Note that the `length` API-parameter is used to set the *initial* `contentLength` in various `BasePDFStreamReader` implementations, however it's always overridden by the "Content-Length" header (sent by the server) when that one exists *and* is a valid number. While we currently fallback to the keep the initial `contentLength` otherwise, note however how in that case range requests will always be *disabled* and thus the only spot in the code-base [where `fullReader.contentLength` is necessary](https://github.com/mozilla/pdf.js/blob/873378b71830a151d3350d812bf914b673149cd6/src/core/worker.js#L230-L236) cannot actually be reached.

Hence the only possible reason to use the `length` API-parameter would be for improved progress reporting[1] during streaming of PDF data in rare cases where the "Content-Length" header is missing/invalid, but the user *somehow* has information from another source about the correct `length` of the PDF document.
That situation feels very much like an edge-case, but it's obviously impossible to know if someone is depending on it. However, please note that there's a work-around available for users affected by this removal:
 - Implement a `PDFDataRangeTransport` instance together with custom data-fetching[2], since in that case its `length`-parameter will always be used as-is.

Finally, updates various `BasePDFStreamReader` implementations to only set the `_isRangeSupported` field once the headers are available (since previously we'd just overwrite the "initial" value anyway).

---

[1] I.e. to avoid the "indeterminate" loadingBar being displayed in the viewer.

[2] This is what e.g. the Firefox PDF Viewer uses.
@Snuffleupagus Snuffleupagus force-pushed the getDocument-rm-length branch from cc48e58 to 09a9a7b Compare March 13, 2026 22:43
@Snuffleupagus Snuffleupagus marked this pull request as ready for review March 13, 2026 22:46
@timvandermeij timvandermeij merged commit 315491d into mozilla:master Mar 15, 2026
12 checks passed
@timvandermeij
Copy link
Contributor

Thanks!

@Snuffleupagus Snuffleupagus deleted the getDocument-rm-length branch March 15, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants