fix: persist node-level edits on reopened docx (toUint8Array flush)#19
Merged
Conversation
Node-level mutators such as setTableCellText / setParagraphText operate on a WmlTable / WmlParagraph handed out by tables()/paragraphs(), not on the Docx, so they cannot flip doc.dirty. toUint8Array()/validate() gated the document-part flush on doc.dirty, so saving a reopened document silently dropped those edits (createDocx masked it because add*/append* had already set dirty). The WML AST is the source of truth after openDocx and is round-trip stable (unknown elements preserved as pass-through), so re-serialize the document part unconditionally via a shared flushPendingParts() helper. Side parts keep their dirty fast-path. Adds a regression test: openDocx -> setTableCellText/setParagraphText -> toUint8Array -> openDocx now reflects the edits. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
openDocx()で開いた doc に対してsetTableCellText/setParagraphText等でセル/段落を書き換え、toUint8Array()→ 再度openDocx()すると 編集が消える(テーブルの空/非空セル・段落いずれも)。createDocx()経由では発生しない。根本原因
setTableCellText/setParagraphTextは WML AST を in-place で書き換えるだけでdoc.dirtyを立てない。toUint8Array()/validate()は document part のフラッシュをif (doc.dirty)でゲートしていたため、openDocx()直後(dirty:false)はフラッシュされず、writeOpcPackageが元の生パートバイト列を再出力して AST 編集を破棄していた。修正
flushPendingParts(doc)を追加し、document part を無条件でフラッシュ(AST が source of truth で round-trip 安定・未知要素は pass-through 保持)。toUint8Array()とvalidate()の重複していた dirty ゲートブロックを置き換え。検証
cell:"" / para:"para1"→ aftercell:"ANS" / para:"para-edited"flyle-nexus のセキュリティチェックシート自動記入ツールが docx の書き込みに利用するための修正。次リリース 0.1.1。