# setTimeout in inputrule compositionend

**URL:** <https://discuss.prosemirror.net/t/settimeout-in-inputrule-compositionend/3238>\
**Category:** Uncategorized\
**Created:** [November 1, 2020, 11:51am UTC](https://discuss.prosemirror.net/t/settimeout-in-inputrule-compositionend/3238 "2020-11-01T11:51:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhl](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/bhl/32/4074_2.png) [@bhl](https://discuss.prosemirror.net/u/bhl)\
**Post date:** [November 1, 2020, 11:51am UTC](https://discuss.prosemirror.net/t/settimeout-in-inputrule-compositionend/3238/1 "2020-11-01T11:51:45Z")

</div>

I was adding type annotations to a [slightly customized inputrules](https://discuss.prosemirror.net/t/trigger-inputrule-on-enter/1118/5) plugin when I noticed a type error from [https://github.com/ProseMirror/prosemirror-inputrules/blob/master/src/inputrules.js#L69-L72](https://github.com/ProseMirror/prosemirror-inputrules/blob/master/src/inputrules.js#L69-L72)

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

```

The [documentation](https://prosemirror.net/docs/ref/#view.EditorProps.handleDOMEvents) 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](https://github.com/ProseMirror/prosemirror-inputrules/commit/f9d415945a0884bf23cd4e1f754626e051dd229d).

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](https://stackoverflow.com/a/3580703/4241779).

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [November 1, 2020, 12:54pm UTC](https://discuss.prosemirror.net/t/settimeout-in-inputrule-compositionend/3238/2 "2020-11-01T12:54:25Z")

</div>

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.
