This is a problem caused by !7827. I was preparing a patch to fix it with a different approach, but this looks good too.
Also, there is an issue with the wayland driver entering an infinite IME message generation loop under certain conditions, which this MR fixes.