Skip to content

fix(docx): refresh formatting after asynchronous list conversion - #22

Merged
pierreneter merged 1 commit into
p10node:mainfrom
mkroemer:fix/issue19-async-format-state
Nov 18, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
mkroemer:fix/issue19-async-format-state

Conversation

@mkroemer

Copy link
Copy Markdown
Contributor

After an asynchronous DOCX list conversion, the saved document could be correct while the toolbar still showed the previous list state until the selection changed. Accepted conversion results now republish formatting through the existing onState callback after the busy count is updated, using the current selection.

List toggling and model/selection behavior are preserved; this adds no controller formatting API.

Fixes #19. This is a standalone fix against main, separate from #9.

Validation with Bun 1.4.4: typecheck, 80 relevant unit tests, and one Chromium toolbar regression passed. The list-removal regressions fail on unchanged main after confirming that the saved list was correctly removed. The full repository suite was not rerun for this focused change.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this fixes the case in #19, and the new e2e test fails on the base, so it is a real regression test.

The same stale state survives on a few other paths. All four are reproduced; line numbers are at 6818920.

  1. src/react/docx/DocxEditor.ts:705: two edits before the first response. Select text, "Bulleted list", then Ctrl+Alt+2 before the first docx.edit returns. The marker loop put()s new paragraph objects, so the second response fails the cur.includes(x) identity check and is discarded as "edited again". The toolbar size stays 11 and the paragraph renders at 11pt, while the saved file has Heading 2 at 13pt.
  2. DocxEditor.ts:469: paragraphs in a table that has a tid (inserted or restructured in this session) go through commitTable, which returns no conversion. Insert a table, type in a cell, "Bulleted list": the button stays unpressed and no marker shows, the saved file has the bullet, and a second click sets the list again, so it cannot be removed from the toolbar.
  3. DocxEditor.ts:507: an obsolete response's markers are still applied, so the new finally publishes the superseded list state. Toggle a list, then undo before the response arrives: the button flashes pressed after the undo. The "obsolete conversion does not republish" test covers alignment only, which has no marker side effects.
  4. DocxEditor.ts:672: applyResult returns false while an IME composition is active (Telex, CJK) and drops the whole result. Nothing retries it, so the list never shows until that paragraph is edited again.

3 is new with this PR. 1, 2 and 4 are older gaps that this PR does not make worse; they can be follow-ups if you prefer, just say which.

A possible root fix for most of this: make the list state optimistic like alignment and line spacing (DocxEditor.ts:896, set lst on the optimistic paragraphs in toggleList). Then there is no round-trip window in which the toolbar shows the old state, and a second click inside that window no longer re-applies the list.

Small: emitState now runs in .finally() after the chain's .catch(), so a throwing onState subscriber becomes an unhandled rejection.

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.

DOCX: async list conversion leaves formatting state stale after list removal

2 participants