Skip to content

Fix inconsistencies with the Page.prototype.#replaceIdByRef method - #21812

Open
Snuffleupagus wants to merge 1 commit into
mozilla:masterfrom
Snuffleupagus:deletedAnnotations-RefSet
Open

Fix inconsistencies with the Page.prototype.#replaceIdByRef method#21812
Snuffleupagus wants to merge 1 commit into
mozilla:masterfrom
Snuffleupagus:deletedAnnotations-RefSet

Conversation

@Snuffleupagus

@Snuffleupagus Snuffleupagus commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

This private method has two call-sites, which provide different deletedAnnotations parameters; see

  • pdf.js/src/core/document.js

    Lines 378 to 384 in 0f26334

    const deletedAnnotations = new RefMap();
    const existingAnnotations = new RefSet();
    await this.#replaceIdByRef(
    annotations,
    deletedAnnotations,
    existingAnnotations
    );
  • pdf.js/src/core/document.js

    Lines 534 to 539 in 0f26334

    deletedAnnotations = new RefSet();
    newAnnotationsPromise = Promise.all([
    annotationGlobalsPromise,
    this.#replaceIdByRef(newAnnots, deletedAnnotations, null),
    ]).then(([annotationGlobals]) => {

Thanks to the similarities between the RefMap and RefSet classes this inconsistency hasn't caused any bugs, as far as I know, but it should still be fixed.
Given how the deletedAnnotations is being used, a RefSet really seems to be the "correct" data-structure to use here since we only need to track references.

Finally, make use of an early continue to reduce overall indentation and thus shorten the code in the Page.prototype.#replaceIdByRef method.


Much smaller diff with https://github.com/mozilla/pdf.js/pull/21812/changes?w=1

This private method has two call-sites, which provide *different* `deletedAnnotations` parameters; see
 - https://github.com/mozilla/pdf.js/blob/0f26334f9d6f96119f6e5164fb65832fbbde7344/src/core/document.js#L378-L384
 - https://github.com/mozilla/pdf.js/blob/0f26334f9d6f96119f6e5164fb65832fbbde7344/src/core/document.js#L534-L539

Thanks to the similarities between the `RefMap` and `RefSet` classes this inconsistency hasn't caused any bugs, as far as I know, but it should still be fixed.
Given how the `deletedAnnotations` is being used, a `RefSet` really seems to be the "correct" data-structure to use here since we only need to track references.

Finally, make use of an early `continue` to reduce overall indentation and thus shorten the code in the `Page.prototype.#replaceIdByRef` method.
@codecov-commenter

codecov-commenter commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.20%. Comparing base (0f26334) to head (799a57e).

Files with missing lines Patch % Lines
src/core/document.js 86.95% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21812      +/-   ##
==========================================
- Coverage   90.20%   90.20%   -0.01%     
==========================================
  Files         264      264              
  Lines       67339    67340       +1     
==========================================
  Hits        60741    60741              
- Misses       6598     6599       +1     
Flag Coverage Δ
browsertest 66.30% <86.95%> (-0.04%) ⬇️
fonttest 8.91% <ø> (ø)
integrationtest 69.40% <0.00%> (+<0.01%) ⬆️
unittest 58.38% <73.91%> (+0.01%) ⬆️
unittestcli 56.93% <73.91%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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

Copy link
Copy Markdown
Collaborator Author

/botio browsertest

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

Command cmd_browsertest from @Snuffleupagus received. Current queue size: 0

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

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_browsertest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/e1d432b8fb63896/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/e1d432b8fb63896/output.txt

Total script time: 18.22 mins

  • Regression tests: Passed

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

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

Total script time: 23.46 mins

  • Regression tests: Passed

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.

3 participants