Skip to content

Prevent stale asynchronous editor transforms from overwriting newer document state #1

Open

Description

@LunaStev

Problem

WaveEditorDocument.apply captures a snapshot, awaits engine.transform, and then unconditionally records the old snapshot and replaces the current document. A replace, undo, redo, or another completed transform during that wait is not detected. A delayed formatting response can discard newer text and replace its undo history with the older state.

The plain DOM adapter has the same conflict: its busy flag prevents another formatting command but leaves typing and setValue available. The awaited result then overwrites input.value. A result can also arrive after the controller has been destroyed.

Code references:

Reproduction

Use an adapter whose promise is resolved explicitly by the test rather than using a timer:

  1. Create WaveEditorDocument('old', 0, 3).
  2. Start apply('bold', delayedEngine) without awaiting completion.
  3. Call replace('new user input').
  4. Resolve the adapter with the bold transformation of the original snapshot, then await apply.
  5. Inspect the document and call undo().

A focused Node.js execution of the current core modules produced:

After the delayed result: content = "**old**"
After undo:               content = "old"

The newer text is absent from both results. The core reproduction used the repository modules with only local import suffixes adjusted for direct TypeScript execution; it did not run the browser UI.

For the DOM regression, start a delayed toolbar transform, type new text or call setValue, and then release the promise.

Expected behavior and scope

An asynchronous transformation must only commit against the document revision it was computed from, or participate in a documented serialized/rebased operation policy. Do not silently discard a newer edit. A rejected or obsolete result must not mutate undo/redo history.

Apply the same stale-result protection to the plain DOM controller and invalidate pending UI work on destruction. Keep adapter errors distinguishable from an obsolete result, and handle any rejection in the event-handler path rather than leaving an unhandled promise.

This is local editor state coordination, not server persistence, collaborative editing, or a new transport protocol.

Completion criteria

  • Add deferred-promise tests for a pending transform followed by replace, undo, or redo; later content and history are preserved.
  • Cover overlapping apply calls resolved in reverse order and document the chosen conflict/serialization behavior.
  • A normal uncontended transform still updates content and selection and supports undo/redo.
  • A failed or obsolete transform does not add a misleading undo snapshot or clear valid redo history.
  • DOM tests cover typing and setValue during a pending transform, plus completion after destroy without DOM changes, focus changes, or callbacks.
  • Clear busy state on all completion paths without blocking ordinary editing indefinitely.
  • Keep the framework-independent core free of DOM dependencies and run the editor package tests.

Difficulty: medium.

Activity

  1. added
    bug
    help wanted
    on Sep 21, 2026
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

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions