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.
Moving focus away from the editor while composing text (Chinese, Japanese, Korean) can cancel composition, commit partial text, or leave the IME candidate window out of sync. Safari often shows distinct behavior for Japanese; Chrome behavior for Chinese/Korean is covered in related cases.
User scrolling the page or scrollable editor while the IME candidate window is open may cancel composition or move the caret out of sync—reported on iOS Safari with Japanese IME and Android Chrome with Chinese IME when scroll containers move the editing context.
Tab moves focus by default. During IME composition, Tab may cancel composition, cycle candidates, or be captured by the editor for indentation—behavior differs for Chinese, Thai, and Safari vs Firefox.
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.
Have questions, suggestions, or want to share your experience? Join the discussion below.