preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.91k stars 1.95k forks source link

onCompositionStart, onCompositionEnd, and onCompositionUpdate are bound to the wrong case-sensitive event name. #3003

Open xorgy opened 3 years ago

xorgy commented 3 years ago

Reproduction

Steps to reproduce

Expected Behavior

The onCompositionStart handler should be called.

Actual Behavior

The onCompositionStart handler doesn't get called because Preact binds it to "CompositionStart" rather than "compositionstart"

The same applies for "compositionend" and "compositionupdate".

xorgy commented 3 years ago

I think this is an issue with the way Preact decides whether to case-fold events: it checks whether the element has a property named the case-folded version of the property starting with 'on', but even where "compositionstart" and "compositionend" are supported, they do not expose properties on the element, so Preact does not case fold.

xorgy commented 3 years ago

I have a branch https://github.com/xorgy/preact/tree/fix-composition-events with our workaround, obviously there's some golf to be done around this.

brainlessbadger commented 3 years ago

Same applies to focusin, focusout, beforeinput and probably some other events.

marvinhagemeister commented 3 years ago

Need to look into it more in depth what's up with the casing. Regardless, Preact has always and will always support attaching event handlers with the exact casing defined in the HTML/DOM specs. That is the lowercase variants all work:

<input onfocusin={...} />
xorgy commented 3 years ago

Probably the type definitions on the JSX should never have been camelCased to begin with. Attaching props not in that type can make things look funny in tooling for TypeScript, though you are correct that it can be done. @marvinhagemeister

JoviDeCroock commented 2 weeks ago

I wonder whether we can make the condition here more elaborate to cover these cases https://github.com/preactjs/preact/blob/main/src/diff/props.js#L72-L74