Composition events are not fired consistently for all IMEs
OS: macOS Ubuntu 22.04 · Device: Desktop or Laptop Any · Browser: Safari 120.0
Open case →Scenario
Analysis of how out-of-order or missing composition events disrupt editor state synchronization.
For CJK (Chinese, Japanese, Korean) languages, the Composition event lifecycle is as important as the Input event loop. Frameworks often “lock” their state during composition to prevent the browser’s intermediate DOM states from corrupting the internal model. If events fire out of order, or if isComposing flags are incorrectly set, the framework may prematurely “unlock” and perform a destructive sync.
In Safari, when committing with Enter, compositionend fires before the matching keydown. This clears the isComposing flag too early.
/* Expected Sequence */
// 1. keydown (key: Enter, isComposing: true)
// 2. compositionend
/* Safari Sequence */
// 1. compositionend (State unlocked!)
// 2. keydown (key: Enter, isComposing: false) -> Triggers newline/send!
OS-level features like iOS Dictation or macOS auto-correct (double-space period) often modify text by injecting characters directly, sometimes bypassing compositionupdate entirely.
compositionupdate events during rapid typing.keydown with keyCode 229 consistently, making it the most reliable to detect IME activity.Use a short timeout after compositionend before allowing keydown events to proceed normally.
let imeLock = false;
element.addEventListener('compositionstart', () => { imeLock = true; });
element.addEventListener('compositionend', () => {
setTimeout(() => { imeLock = false; }, 40); // Catch the Safari keydown
});
Reliably detect IME activity across engines by checking the deprecated but universally supported keyCode 229.
Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.
Each row is a concrete case for this scenario, with a dedicated document and playground.
| Case | OS | Device | Browser | Keyboard | Status |
|---|---|---|---|---|---|
| ce-0034-composition-events-missing | macOS Ubuntu 22.04 | Desktop or Laptop Any | Safari 120.0 | Chinese IME | draft |
| ce-0567-safari-composition-event-order | macOS 15.0 | Desktop Any | Safari 18.0 | Japanese IME | confirmed |
This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.
| Browser | macOS |
|---|---|
| Safari |
This scenario affects multiple languages. Cases are grouped by language/input method below.
OS: macOS Ubuntu 22.04 · Device: Desktop or Laptop Any · Browser: Safari 120.0
Open case →OS: macOS 15.0 · Device: Desktop Any · Browser: Safari 18.0
Open case →Other scenarios that share similar tags or category.
During IME composition or in certain browser/IME combinations, the beforeinput event may have a different inputType than the corresponding input event. For example, beforeinput may fire with insertCompositionText while input fires with deleteContentBackward. This mismatch can cause handlers to misinterpret the actual DOM change and requires storing beforeinput's targetRanges for use in input event handling.
The selection (window.getSelection()) in beforeinput events can differ from the selection in corresponding input events. This mismatch can occur during IME composition, text prediction, or when typing adjacent to formatted elements like links. The selection in beforeinput may include adjacent formatted text, while input selection reflects the final cursor position.
The getTargetRanges() method in beforeinput events may return an empty array or undefined in various scenarios, including text prediction, certain IME compositions, or specific browser/device combinations. When getTargetRanges() is unavailable, developers must rely on window.getSelection() as a fallback, but this may be less accurate.
When using IME to input CJK text in heading elements (H1, H2, etc.) in WebKit browsers, pressing Space to confirm composition causes both the raw Pinyin buffer AND the confirmed characters to appear together.
On Firefox with Windows 10 and Korean IME, specific key combination during IME composition causes the editor to crash. The crash occurs when typing certain sequences with the Korean IME.
Have questions, suggestions, or want to share your experience? Join the discussion below.