# Rerendering on widget keyUp / keyDown?

**URL:** <https://meta.discourse.org/t/rerendering-on-widget-keyup-keydown/61461>\
**Category:** Development\
**Created:** [23 أبريل 2017، 2:02م UTC](https://meta.discourse.org/t/rerendering-on-widget-keyup-keydown/61461 "2017-04-23T14:02:30Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)\
**Post date:** [23 أبريل 2017، 2:02م UTC](https://meta.discourse.org/t/rerendering-on-widget-keyup-keydown/61461/1 "2017-04-23T14:02:30Z")

</div>

Hey Discourse team,

I’m currently investigating why Babble slows down user input so much while typing. I’ve traced it to the keyUp / keyDown hooks in my composer widget, which do things like listen for submit on enter, and escape to cancel, as well as sending notifications that the user is currently typing.

It looks like those events go into a `nodeCallback` function in `discourse/widgets/hooks`, which looks like this (NB that this is simplified a bit):

```plaintext
function nodeCallback(widget, keyDownFn) {
  widget.scheduleRerender(() => keyDownFn(widget));
}

```

Thing is… I _really_ don’t want to rerender the widget on each keystroke, especially because it triggers a rerender of the whole widget tree:

```plaintext
function scheduleRerender() {
  var widget = this;
  while (widget) {
    // rerender the widget if possible
    widget = widget.parentWidget
  }
}

```

I’m wondering if it’s preferable here to allow the widget to define which events it wants to rerender on, like so:

```plaintext
  createWidget('my-widget', {
    skipKeyUpRerender: true
  })

```

or whether we can simply turn off rerendering for keyUp / keyDown events, and have the developer manually call `scheduleRerender` on those if necessary (since they have the potential to be quite high-volume events)

(I haven’t found any existing Discourse code which utilizes the keyUp / keyDown hooks in widgets, so I guess I’m battle testing them 😛 ⚔ )

cc @eviltrout

---

_[View the full topic](https://meta.discourse.org/t/rerendering-on-widget-keyup-keydown/61461)._
