Skip to content

Don't bind transparent XFA nodes to data nodes - #22117

Open
LoukasPap wants to merge 1 commit into
mozilla:masterfrom
LoukasPap:fix/xfa-area-consumes-data-node
Open

LoukasPap wants to merge 1 commit into
mozilla:masterfrom
LoukasPap:fix/xfa-area-consumes-data-node

Conversation

@LoukasPap

@LoukasPap LoukasPap commented Oct 9, 2026 •

Copy link
Copy Markdown

Fixes #21904

An area is only a layout container, however the XFA binder treated it like a subform and matched it by name: it looked for a data node with the same name in the current data node, its parent and its grandparent, and marked the match as consumed.

In the PDF from the issue there is an <area name="Pretensao"> (inside SubformPret1) and, later on, a <subform name="Pretensao"> containing the "Requer o seguinte" textarea (Pret2). The area took the Pretensao data node first, hence the subform found nothing to bind to and Pret2 was never linked to its data node. Since values are saved by writing them into the linked data nodes, the text typed in that field was lost when saving. The DropDownList1 field in the area was affected too.

Now transparent nodes (unnamed nodes and area elements, see $isTransparent) are never matched with a data node, and their children are bound against the data node of the enclosing container.

Test cases

  • Added unit tests in the Bind data into form block of test/unit/xfa_parser_spec.js; both fail without the patch and pass with it:
    • an area and a subform sharing the same name: the subform is bound to its data node;
    • a named area in matchTemplate mode: its fields are bound to the data of its parent and no data node is created for the area.
  • Manually checked with the PDF from the issue: after typing in both "Requer o seguinte" and "DOCUMENTOS APRESENTADOS", saving and re-opening the saved file, both values are kept.

@LoukasPap
LoukasPap force-pushed the fix/xfa-area-consumes-data-node branch from 3ea190f to 487e28b Compare October 9, 2026 13:55
@LoukasPap
LoukasPap marked this pull request as ready for review October 9, 2026 13:57
@LoukasPap

LoukasPap commented Oct 9, 2026 •

Copy link
Copy Markdown
Author

Tell me if an integration test is needed for this issue.

Comment thread src/core/xfa/bind.js Resolved
@LoukasPap
LoukasPap force-pushed the fix/xfa-area-consumes-data-node branch from 487e28b to ca2320b Compare October 10, 2026 20:45
@LoukasPap LoukasPap changed the title Don't bind XFA area elements to data nodes (issue 21904) Don't bind transparent XFA nodes to data nodes (issue 21904) Oct 10, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

Commit d91ced2 (build logs).

Viewer Build Preview
Modern (gulp generic) ✅ not published
Legacy (gulp generic-legacy) ✅ not published

🔒 A user with write access must approve this commit with the viewer-preview label to publish the viewers.

@codecov-commenter

codecov-commenter commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (f5e56f0) to head (d91ced2).
⚠️ Report is 222 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22117      +/-   ##
==========================================
+ Coverage   90.23%   90.46%   +0.22%     
==========================================
  Files         277      277              
  Lines       67807    68278     +471     
==========================================
+ Hits        61186    61765     +579     
+ Misses       6621     6513     -108     
Flag Coverage Δ
browsertest 66.32% <100.00%> (+0.15%) ⬆️
fonttest 8.97% <ø> (-0.01%) ⬇️
integrationtest 69.40% <100.00%> (+0.08%) ⬆️
unittest 60.78% <100.00%> (+0.78%) ⬆️
unittestcli 58.52% <100.00%> (+0.27%) ⬆️

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.

@LoukasPap

Copy link
Copy Markdown
Author

Failing test runs on my pc. Probably a flaky one.

@calixteman calixteman 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.

The fix looks good to me. A few comments about the tests:

  • Please move them into the Bind data into form block in test/unit/xfa_parser_spec.js. Those tests use Binder and searchNode directly; there's already one with an (unnamed) area at the end of the file, which is a good starting point. Going through XFAFactory, the HTML output and serializeData needs a custom tree walk, and the dataId !== fieldId check depends on the internals of html.js.
  • Of the 4 tests, only the first one fails without the patch:
    • the unnamed subform tests (with or without dataRef) go through code this patch doesn't change, so they can be dropped;
    • the "fields of an area" test only passes on master because, in consumeData mode, an unmatched container with min > 0 falls back to the parent data node. With mergeMode="matchTemplate" it does fail without the patch: a data node named after the area is created and the field is bound to it, so the existing data is never used. Please switch it to matchTemplate, and also check that no data node was created for the area (binder.getData()).

So two tests should be enough: the area/subform name clash from the issue, and a named area in matchTemplate mode. Please make sure both fail without your change.

An integration test isn't needed for this.

An `area` is only a layout container, however it was bound to data like
a subform, i.e. by looking for a data node with the same name in the
current data node, its parent and its grandparent.
Hence, an `area` could consume a data node meant for a subform having
the same name, which was then left without any data node. Fields inside
that subform were never linked to the data, so their values were lost
when saving the document.

Now, transparent nodes (unnamed nodes and `area` elements) are never
matched with a data node and their children are bound against the data
node of the enclosing container.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@LoukasPap
LoukasPap force-pushed the fix/xfa-area-consumes-data-node branch from ca2320b to d91ced2 Compare October 20, 2026 23:05
@LoukasPap

LoukasPap commented Oct 20, 2026 •

Copy link
Copy Markdown
Author

I moved the tests to the Bind data into form block of xfa_parser_spec.js, using Binder directly, and kept only two: the area/subform name clash from the issue, and a named area in matchTemplate mode. Both tests fail without the patch.

@LoukasPap
LoukasPap requested a review from calixteman October 21, 2026 08:10
@codspeed

codspeed Bot commented Oct 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 86 untouched benchmarks


Comparing LoukasPap:fix/xfa-area-consumes-data-node (d91ced2) with master (8fb674c)

Open in CodSpeed

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Reference tests

Results for d91ced2 (run, references from mozilla/pdf.js.refs@6cc7acf45c).

Platform Status Tests Total runtime Errors Different FBF No reference Report
Linux ⚠️ 1382 12m 34s 0 9 0 0 view differences
Windows ⚠️ 1382 15m 56s 0 7 0 0 view differences

The report is kept for 30 days and replaced by the next run.

Problems on Linux
TEST-UNEXPECTED-FAIL | test failed issue16114-partial | in firefox-1 | page1 round 1 | Optimized rendering differs from full rendering.
Problems on Windows
TEST-UNEXPECTED-FAIL | test failed issue16114-partial | in firefox-1 | page1 round 1 | Optimized rendering differs from full rendering.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 21, 2026
@LoukasPap LoukasPap changed the title Don't bind transparent XFA nodes to data nodes (issue 21904) Don't bind transparent XFA nodes to data nodes Oct 26, 2026

This branch was previously deployed

1 inactive deployment
sync_pdfs — d91ced27 Deployed Oct 21, 2026 by calixteman via request #543
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