Phenomenon
Pressing Undo while Japanese IME composition is active in a contenteditable element removes more text than expected, including characters that were committed before the current composition or incomplete kanji conversions.
Reproduction example
- Focus the editable area.
- Type a Japanese character and finalize it (e.g., “漢”).
- Activate Japanese IME and start composing another character (e.g., “字”), but do not finalize it.
- Press Cmd+Z (or the platform-specific Undo shortcut).
Observed behavior
- Both the active composition and previously committed characters are removed
- Incomplete kanji conversions may be lost
- The event log shows a sequence of
beforeinput/inputevents that do not map cleanly to user intent - Undo granularity is incorrect
Expected behavior
- Undo reverts only the last committed edit step, or at least behaves in the same way as native controls in the same environment
- Active composition should be cancelled, but previously committed text should remain
Browser Comparison
- Safari: Undo may remove more than expected during composition, especially on macOS
- Chrome: May have different undo behavior
- Firefox: May have different undo behavior
Notes and possible direction for workarounds
- This behavior can interfere with predictable text editing and undo/redo stacks
- Monitor composition state when handling undo operations
- Consider implementing custom undo/redo logic for better control