Scenario

Duplicate beforeinput or input events during IME composition

Some browsers and keyboards emit duplicate composition-related input or beforeinput events—especially iOS Safari dictation paths and certain Android keyboards—so naive handlers that insert text on every input may double characters or corrupt state.

ime
Scenario ID
scenario-ime-composition-duplicate-events

Details

Some browsers and keyboards emit duplicate composition-related input or beforeinput events—especially iOS Safari dictation paths and certain Android keyboards—so naive handlers that insert text on every input may double characters or corrupt state.

Problem Overview

Frameworks often assume one input per user intent. IME and voice pipelines can replay or split events.

Observed Behavior

  • iOS Safari: extra input after dictation or composition end.
  • Android: first-word duplication with prediction enabled.

Impact

Duplicate text, broken undo, model–DOM drift in React-controlled editors.

Solutions

  • Deduplicate using a hash of (inputType, data, selection position) in a short window, or ignore input while a transaction is in flight.
  • Prefer beforeinput cancellation paths when you fully control insertion.

References

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-0096-ime-composition-duplicate-events-ios-safari iOS 17.0 iPhone or iPad Any Safari 17.0 Korean (IME) draft
ce-0577-android-first-word-duplication Android 14.0 Smartphone Any Chrome 131.0 Gboard (English/Korean) confirmed

Browser compatibility

This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.

Confirmed
Draft
No case documented

Cases

This scenario affects multiple languages. Cases are grouped by language/input method below.

Gboard (English/Korean)

1 case

Korean

1 case

Related Scenarios

Other scenarios that share similar tags or category.

Tags: ime, composition, input, ios, safari

Missing composition events on iOS (IME)

On some iOS Safari versions and keyboards, compositionstart or compositionupdate may not fire reliably for certain languages, while input events still fire—editors that only reconcile on composition boundaries can desync.

1 case
Tags: ime, beforeinput, input, ios, safari

iOS dictation triggers duplicate input events after completion

On iOS, when using voice dictation to input text into contenteditable elements, the system may fire duplicate beforeinput and input events after the initial dictation completes. The text is split into words and events are re-fired, causing synchronization issues. Composition events do not fire during dictation, making it difficult to distinguish dictation from keyboard input.

1 case
Tags: ime, composition, beforeinput, input

beforeinput and input events have different inputType values

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.

1 case
Tags: ime, composition, beforeinput, input

Selection mismatch between beforeinput and input events

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.

1 case
Tags: ime, composition, beforeinput, android

getTargetRanges() returns empty array in beforeinput events

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.

1 case

Comments & Discussion

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