Intent to ship: Dispatch `input` event before `compositionend`

162 views
Skip to first unread message

Masayuki Nakano

unread,
Jan 16, 2025, 2:15:44 AMJan 16
to dev-pl...@mozilla.org

Summary: There is a long standing issue about the event order of `compositionend` and `input` at committing composition. Gecko dispatches them as:

  1. `beforeinput` whose `isComposing` is `true`
  2. `compositionend`
  3. `input` whose `isComposing` is `false`

However, Chrome dispatches them as:

  1. `beforeinput` whose `isComposing` is `true`
  2. `input` whose `isComposing` is `true`
  3. `compositionend`

The reason why we cannot align this behavior to Chrome is, there is no `input` event whose `isComposing` is `false`. Therefore, web apps cannot handle `input` events only with `input` events to avoid to do something during IME composition, i.e., web apps needs to listen `compositionstart` and `compositionend` for doing that. So, once we align the behavior to Chrome as-is, we may need to rewrite our chrome JS code with more event listeners. Therefore, I filed a spec issue several years ago, but it's still not agreed between browser vendors.

However, now, we have a web-compat report which is caused by this event order difference. The web site explicitly sets `HTMLInputElement.value` at every `input` event except during IME composition. For supporting IME, they set the value from `compositionend` too with new value which is stored at the last `input` event. Therefore, they set previous composition on Firefox if the user selects a commit string from the candidate list without updating the composition string.

For avoiding the web-compat issue on the web site, I think Gecko can dispatch redundant `input` event before `compositionend`, so,

  1. `beforeinput` whose `isComposing` is `true`
  2. `input` whose `isComposing` is `true`
  3. `compositionend`
  4. `input` whose `isComposing` is `false`

So, the new behavior causes alone `input` event which is not following a corresponding `beforeinput` event, but I guess this does not cause new web-compat issue.

Bug: <https://bugzilla.mozilla.org/show_bug.cgi?id=1941973>

Specification: UI Events <https://w3c.github.io/uievents/#events-composition-input-events>

Platform coverage: All

Preference: `dom.input_events.dispatch_before_compositionend`

DevTools bug: N/A

web-platform-tests: N/A (cannot synthesize composition with TestDriver)

-- 
Masayuki Nakano <masa...@d-toybox.com>
Working on DOM, Events, editor and IME handling for Gecko
Reply all
Reply to author
Forward
0 new messages