IME composition causes duplicate Pinyin text in headings
OS: Windows 10/11 · Device: Desktop Any · Browser: Chrome 120+ · Keyboard: Chinese (IME) - Windows Chinese Input
Open case →Scenario
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.
When composing text with an IME (Input Method Editor) for Chinese or other CJK languages inside heading elements (<h1>, <h2>, etc.) in WebKit browsers, pressing Space to confirm the composition causes both the raw input buffer (e.g., Pinyin “nihao”) and the confirmed characters (e.g., “你好”) to appear together in the editor.
The issue occurs specifically when:
WebKit’s IME composition handling in heading elements appears to incorrectly maintain both:
When composition is confirmed with Space key, WebKit fails to properly clear the raw buffer from the DOM in heading elements.
Use paragraphs instead of headings:
<h2> with <p><strong> or use CSS styling instead of semantic headingsForce DOM cleanup after composition:
heading.addEventListener('compositionend', () => {
setTimeout(() => {
// Remove any raw Pinyin text that shouldn't be there
const text = heading.textContent.replace(/[a-z]+/g, '');
heading.textContent = text;
}, 0);
});
Intercept Space key during composition:
heading.addEventListener('keydown', (e) => {
if (isComposing && e.key === ' ') {
e.preventDefault();
// Let IME handle composition completion naturally
}
});
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-0233-chinese-ime-pinyin-heading-chrome-en | Windows 10/11 | Desktop Any | Chrome 120+ | Chinese (IME) - Windows Chinese Input | draft |
Open a case to see the detailed description and its dedicated playground.
OS: Windows 10/11 · Device: Desktop Any · Browser: Chrome 120+ · Keyboard: Chinese (IME) - Windows Chinese Input
Open case →Other scenarios that share similar tags or category.
In Safari desktop, when preventDefault() is called on keydown or beforeinput events for insertParagraph (Enter key), the IME composition state becomes corrupted. Subsequent text input fails to trigger proper input events, causing characters to not be inserted or composition to malfunction.
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.
Analysis of how out-of-order or missing composition events disrupt editor state synchronization.
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.
Have questions, suggestions, or want to share your experience? Join the discussion below.