Emoji selector crashes the message editor in Android / Chrome

Ok, I’ve looked into this again today and managed to repro after switching the virtual keyboard on my phone to Gboard. Gboard sometimes fires keydown and keyup events twice for a single key press and if that happens for the last key you press before selecting an emoji from autocomplete, you’ll get a crash.

I’m not sure what causes Gboard to fire these events twice, but it seems to depend on what you’ve typed and your Gboard settings.

The double events cause a crash due to the way our autocomplete library is designed. So the library listens to both keydown and keyup events, and on keydown it clears the autocomplete suggestions and on keyup it offers new suggestions based on the new autocomplete term.

However, there is a small guard/optimization to protect the library from doing duplicate work when the term has not changed since the previous suggestions, and this where the issue occurs. The first pair of keydown and keyup events clears the old suggestions and offers new ones as expected, but the second erroneous pair will clear the suggestions again on keydown but won’t offer new ones on keyup because the autocomplete term has not changed.

The only least hacky “fix” that I can think of is removing the guard/optimization so the library always offers new suggestions on keyup, but I’m not sure if this is desired or worth it.

I know that we want to rewrite our autocomplete library at some point (it’s some of the oldest code in the codebase and desperately needs a rewrite), so maybe this bug could wait until we get to the rewrite?

4 Likes