setTimeout in inputrule compositionend

I was adding type annotations to a slightly customized inputrules plugin when I noticed a type error from

      handleDOMEvents: {
        compositionend: (view) => {
          setTimeout(() => {
            let {$cursor} = view.state.selection
            if ($cursor) run(view, $cursor.pos, $cursor.pos, "", rules, plugin)

The documentation says that event handlers are supposed to return booleans, but in this case because it’s wrapped in a setTimeout, the return value is void.

What’s the reasoning the handler for compositionend is wrapped in a setTimeout, and is it safe to remove it?

The commit that added it is here.

Originally I thought with the delay parameter on setTimeout set to 0, it wouldn’t have any effect, but apparently it still removes the function from the execution queue.

Returning undefined is equivalent to returning false in this case, since the view converts the return value to a boolean before acting on it. Removing the setTimeout is definitely not a good idea here, since it’ll cause the code to dispatch a transaction before the view itself has finished handling the composition.