Skip to content

fix(docx-core): use replaceData in setLeafText to sync xmldom data/nodeValue#40

Open
stevenobiajulu wants to merge 1 commit intomainfrom
fix/setleaftext-replacedata
Open

fix(docx-core): use replaceData in setLeafText to sync xmldom data/nodeValue#40
stevenobiajulu wants to merge 1 commit intomainfrom
fix/setleaftext-replacedata

Conversation

@stevenobiajulu
Copy link
Copy Markdown
Member

Summary

  • Fix setLeafText to use replaceData() instead of direct nodeValue assignment in dom-helpers.ts
  • Root cause: In @xmldom/xmldom, CharacterData stores text in two separate plain properties — data (read by XMLSerializer) and nodeValue (read by textContent). A direct child.nodeValue = text only updates nodeValue, leaving data stale. XMLSerializer then silently outputs old text.
  • Impact: ILPA corpus inplace reconstruction fell back to rebuild because the round-trip safety check detected stale serialized text. With this fix, ILPA succeeds in inplace mode.
  • Upstream bug test: Adds xmldom-characterdata-nodevalue.test.ts documenting the desync for upstream filing at xmldom/xmldom

Files changed

File Change
src/primitives/dom-helpers.ts child.nodeValue = text(child as CharacterData).replaceData(...)
src/xmldom-characterdata-nodevalue.test.ts New: 3 tests documenting upstream xmldom bug
src/integration/reconstruction-metadata.test.ts Expect 'inplace' instead of 'rebuild'
src/integration/inplace-bookmark-semantic-regression.test.ts Same expectation update
src/integration/stability-invariants.test.ts Same expectation update

Fixes: #35

Test plan

  • npm run lint:workspaces — 0 errors
  • npx vitest run in docx-core — 808 tests (807 pass + 1 skip)
  • ILPA corpus now succeeds in inplace mode without fallback
  • Upstream bug documented with it.fails() tests

…deValue

In @xmldom/xmldom, CharacterData stores text in two separate plain
properties: `data` (read by XMLSerializer) and `nodeValue` (read by
`textContent`). Direct `child.nodeValue = text` assignment only updates
`nodeValue`, leaving `data` stale — XMLSerializer silently outputs old
text.

Replace the direct assignment with `replaceData()` which updates both
atomically. This fixes Issue #35 where ILPA corpus inplace
reconstruction fell back to rebuild due to the round-trip safety check
detecting stale serialized text.

Also adds a standalone test documenting the upstream xmldom desync bug
for future upstream filing, and updates integration test expectations
from 'rebuild' to 'inplace' since the fix eliminates the fallback.

Fixes: #35
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
site Ready Ready Preview, Comment Mar 7, 2026 6:34pm

Request Review

@github-actions github-actions bot added the fix label Mar 7, 2026
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.

Premerge-enabled inplace safety check failure on ILPA corpus

1 participant