Skip to content

DOCX: an obsolete conversion response still publishes its list state #29

Open

Description

@pierreneter

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:

  1. Open sample.docx for editing, select text in a paragraph and toggle a bullet list on.
  2. Undo before the first docx.edit response arrives (in a test, hold the response).
  3. The published states go: no list, no list, then lst: 'bullet' with busy: 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 lst and marker:
    // 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 finally republishes the state:
    .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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions