Repository navigation
Description
Since #22, a conversion response that has been superseded can still publish its list state, so the toolbar shows a state the document no longer has for a moment.
Reproduction:
- Open
sample.docxfor editing, select text in a paragraph and toggle a bullet list on. - Undo before the first
docx.editresponse arrives (in a test, hold the response). - The published states go: no list, no list, then
lst: 'bullet'withbusy: true(from the obsolete response), then no list. The list button flashes pressed after the undo.
Reproduced with a DocxEditor probe while reviewing #22.
Cause, on main at 43b28d6:
- The rebuilt-paragraph loop skips a paragraph that was edited again, but the marker loop has no such guard and applies the obsolete response's
lstand marker:
office-engine/src/react/docx/DocxEditor.ts
Lines 700 to 708 in 43b28d6
// list numbering changes anywhere in the document for (const [k, m] of Object.entries(res.markers)) { for (const loc of this.locate(Number(k))) { const p = loc.list[loc.index] as Paragraph if ((loc.list[loc.index - 1] as Paragraph | undefined)?.pid === p.pid) continue this.put(loc.pa, { ...p, marker: m ? { text: m.text, s: m.s, tab: m.tab } : undefined, lst: m?.lst }) touched = true } } - That makes the result count as applied, and the new
finallyrepublishes the state:
office-engine/src/react/docx/DocxEditor.ts
Lines 505 to 512 in 43b28d6
.then((res) => { applied = this.applyResult(res, sent) }) .catch((e) => console.error('[office-engine] edit failed', e)) .finally(() => { this.inflight-- // Conversion can change the look after replace's optimistic notification. Use the selection now, // after completing the edit, so the toolbar also sees the current history and busy state. if (applied) this.emitState(this.input.sel()) })
The test "an obsolete conversion does not republish" covers alignment only, which has no marker side effects.
Expected: an obsolete response does not publish list state for a paragraph that has been edited again; only the response of the latest edit does.
Possible direction: give the marker loop the same "edited again" guard for paragraphs in sent, and extend the obsolete-conversion test to a list toggle followed by undo. Related: #26, where the same marker loop makes a later response look obsolete.
Small, same place: emitState now runs in .finally() after the chain's .catch(), so a throwing onState subscriber becomes an unhandled rejection.
Activity