Skip to content

fix: persist node-level edits on reopened docx (toUint8Array flush)#19

Merged
baseballyama merged 1 commit into
mainfrom
fix/persist-reopened-edits
Jul 5, 2026
Merged

fix: persist node-level edits on reopened docx (toUint8Array flush)#19
baseballyama merged 1 commit into
mainfrom
fix/persist-reopened-edits

Conversation

@baseballyama

Copy link
Copy Markdown
Collaborator

問題

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 ゲートブロックを置き換え。

検証

  • repro: before cell:"" / para:"para1" → after cell:"ANS" / para:"para-edited"
  • 回帰テスト追加(openDocx→mutate→toUint8Array→openDocx)。全テスト 453 passed(+1)、typecheck/lint/format クリーン。createDocx 経路は不変。

flyle-nexus のセキュリティチェックシート自動記入ツールが docx の書き込みに利用するための修正。次リリース 0.1.1。

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>
Copilot AI review requested due to automatic review settings July 5, 2026 02:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@baseballyama
baseballyama merged commit 3c469fd into main Jul 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants