Scenario

Firefox undo stack corrupted when DOM mutates during editing

In Firefox, programmatic DOM changes during typing (auto-formatting, spellcheck fixes, framework reconciliation) can desynchronize the internal undo stack. Undo/redo may jump to wrong snapshots or truncate history.

input
Scenario ID
scenario-firefox-undo-dom-mutation

Details

In Firefox, programmatic DOM changes during typing (auto-formatting, spellcheck fixes, framework reconciliation) can desynchronize the internal undo stack. Undo/redo may jump to wrong snapshots or truncate history.

Problem Overview

Gecko’s contenteditable undo model ties to editing sessions and DOM mutations. When JavaScript or the browser inserts nodes between keystrokes, the undo ring may record boundaries that do not match user intent.

Observed Behavior

  • Undo removes more or less text than the last visible edit.
  • Redo becomes a no-op after certain mutations.
  • Corruption worsens when combining IME composition with programmatic wraps.

Impact

Data loss perception, broken editor sync layers, and difficult-to-reproduce bug reports.

Browser Comparison

Chromium and WebKit have different undo granularity; this scenario is specifically about Firefox’s stack interaction with mid-input DOM changes.

Solutions

  • Defer non-essential DOM mutations until compositionend or idle time.
  • Batch structural changes; avoid wrapping runs on every keystroke.
  • When you must mutate, consider replacing the undo stack with a custom document history (ProseMirror-style) for Firefox.

Best Practices

  • Reproduce with Firefox ESR and current release; behavior evolves.

References

  • MDN: Document.execCommand (legacy, but relevant to undo stacks)
  • Firefox bug tracker: search for contenteditable undo + mutation

Scenario flow

Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.

React Flow mini map

Variants

Each row is a concrete case for this scenario, with a dedicated document and playground.

Case OS Device Browser Keyboard Status
ce-0224-firefox-undo-corruption Windows 10/11 Desktop Any Firefox 115.0+ US QWERTY draft

Cases

Open a case to see the detailed description and its dedicated playground.

Related Scenarios

Other scenarios that share similar tags or category.

Tags: undo, redo, dom

Undo stack and programmatic DOM changes

Programmatic inserts or execCommand during typing can split undo transactions or clear the stack—browser-specific rules differ from custom editor history.

1 case
Tags: dom

Caret jumps to end after DOM manipulation in Chrome

In Chromium, programmatic DOM updates (normalization, wrapping, React reconciliation) while the user is typing can move the caret to the end of the contenteditable or to an unexpected boundary—especially when the mutation happens between keystrokes.

1 case
Tags: firefox

HTML Drag and Drop API with contenteditable

Using the HTML drag-and-drop API inside or alongside contenteditable regions often diverges from behavior on plain elements: default actions, `contenteditable` hit-testing, and `beforeinput`/`drop` ordering differ by browser. Custom editors must reconcile native DnD with their own selection model.

1 case

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.