Skip to content

Implement proper serialization of OptionalContentConfig#21349

Merged
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:OptionalContentConfig-serializable
Jun 2, 2026
Merged

Implement proper serialization of OptionalContentConfig#21349
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:OptionalContentConfig-serializable

Conversation

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

I happened to notice that the way the OptionalContentConfig-data handled in the PR that implements worker-rendering leaves a lot to be desired:

  • The way that the optional content state is handled is not correct, since that PR collects the "effective visibility" of the optional content groups rather than their actual internal state.

  • The necessary OptionalContentConfig-data is collected piecemeal in the API, which leads to quite frankly very messy code that's hard to read and will be even harder to maintain.

The solution to all of these issues seem really simple though, just add a couple of OptionalContentConfig methods that serialize/de-serialize the necessary data.
In the API calling optionalContentConfig.serializable will get all of the needed data for transferring to the worker-renderer, and once received there calling OptionalContentConfig.fromSerializable(/* transferred data here */) will create an OptionalContentConfig instance with the correct internal state.

As part of this patch, to avoid increasing bundle-size unnecessarily, a couple of existing methods are stubbed out when the OptionalContentConfig class ends up in a worker-file (since they're unused there).
This part assumes that the new worker-renderer is built correctly, note how the existing pdf.worker.mjs is handled in

pdf.js/gulpfile.mjs

Lines 539 to 545 in 03eda70

function createWorkerBundle(defines) {
const workerDefines = {
...defines,
WORKER_THREAD: true,
};
const workerFileConfig = createWebpackConfig(workerDefines, {
filename: workerDefines.MINIFIED ? "pdf.worker.min.mjs" : "pdf.worker.mjs",

(Note: Submitting a PR was a lot faster than trying to provide review comments, since writing this commit message took longer than writing the patch.)

I happened to notice that the way the `OptionalContentConfig`-data handled in the PR that implements worker-rendering leaves a lot to be desired:
 - The way that the optional content state is handled is not correct, since that PR collects the "effective visibility" of the optional content groups rather than their *actual* internal state.

 - The necessary `OptionalContentConfig`-data is collected piecemeal in the API, which leads to quite frankly very messy code that's hard to read and will be even harder to maintain.

The solution to all of these issues seem really simple though, just add a couple of `OptionalContentConfig` methods that serialize/de-serialize the necessary data.
In the API calling `optionalContentConfig.serializable` will get *all* of the needed data for transferring to the worker-renderer, and once received there calling `OptionalContentConfig.fromSerializable(/* transferred data here */)` will create an `OptionalContentConfig` instance with the correct internal state.

As part of this patch, to avoid increasing bundle-size unnecessarily, a couple of existing methods are stubbed out when the `OptionalContentConfig` class ends up in a worker-file (since they're unused there).
This part assumes that the new worker-renderer is built correctly, note how the existing `pdf.worker.mjs` is handled in https://github.com/mozilla/pdf.js/blob/03eda70d7e75267bc58ee4f446a20f7f38792b47/gulpfile.mjs#L539-L545

(*Note:* Submitting a PR was a lot faster than trying to provide review comments, since writing this commit message took longer than writing the patch.)
@Snuffleupagus Snuffleupagus requested a review from calixteman May 27, 2026 09:14
@codecov-commenter

codecov-commenter commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.46154% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.41%. Comparing base (b849567) to head (ce45d5a).

Files with missing lines Patch % Lines
src/display/optional_content_config.js 38.46% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21349      +/-   ##
==========================================
- Coverage   81.42%   81.41%   -0.01%     
==========================================
  Files         257      257              
  Lines       65351    65367      +16     
==========================================
+ Hits        53212    53219       +7     
- Misses      12139    12148       +9     
Flag Coverage Δ
fonttest 9.10% <ø> (ø)
integrationtest 67.00% <38.46%> (+<0.01%) ⬆️
unittest 56.85% <34.61%> (-0.03%) ⬇️
unittestcli 56.06% <34.61%> (-0.02%) ⬇️

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

Copy link
Copy Markdown
Collaborator Author

/botio browsertest

@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/a730ab861be62a6/output.txt

@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/f91ab7b6aa5a48f/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Failed

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

Total script time: 19.40 mins

  • Regression tests: FAILED
  errors: 5

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

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

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

Total script time: 25.43 mins

  • Regression tests: Passed

@timvandermeij timvandermeij left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me; thanks!

@Snuffleupagus Snuffleupagus merged commit 19046a6 into mozilla:master Jun 2, 2026
25 of 26 checks passed
@Snuffleupagus Snuffleupagus deleted the OptionalContentConfig-serializable branch June 2, 2026 19:57
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