I have split the IME general fixes to https://gitlab.winehq.org/wine/wine/-/merge_requests/3115, with more fixes to the composition string updates.
I only kept the XIM call sequence breakage here, and although !3115 makes it a little bit less visible, X11 event merging is still causing an inversion and missing composition strings.
This is the case for instance when typing Japanese "nihongo no", when 'n' is entered after the ' ' it is sometimes missing, because the result string is committed from a delayed X11DRV_KeyEvent call, after the preedit update has already been received from the XFilterEvent call.