# A tour of how the Widget (Virtual DOM) code in Discourse works

**URL:** <https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347>\
**Category:** Development\
**Created:** [February 29, 2016, 8:18pm UTC](https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347 "2016-02-29T20:18:39Z")\
**Posts on this page:** 1\
**Showing post:** 45

<div class="post-metadata">

**Author:** ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)\
**Post date:** [June 25, 2016, 9:34pm UTC](https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347/45 "2016-06-25T21:34:25Z")

</div>

@eviltrout I may be missing something here, but it seems that it’s not possible for a widget to retain a state if it’s re-attached as part of a re-render.?

In other words, if you have a series of nested widgets (i.e. widgets attached to widgets), whenever one of the widgets triggers a re-render, the whole chain is re-rendered and any state in the child widgets is lost as they are newly re-attached. Is that correct?

For example when [widgetizing Babble](https://github.com/gdpelican/babble/pull/172), I tried to set a default view state for the [menu widget](https://github.com/gdpelican/babble/pull/172/files#diff-d07e8aa4f6a331b4fc1baf50a572d9a5R27) and then toggle it when the menu was toggled between a single chat stream and the list of chat streams, but found that the state would always remain at its `defaultState`. I surmised that the state was being reset when the menu widget was re-attached on a re-render.

I then tried to stop the ‘propagation’ of the re-render trigger, but wasn’t able to. I ended up using widget actions to send an updated state to the ultimate parent widget (i.e. the header) and retained the state in the header. [See here](https://github.com/gdpelican/babble/pull/172/files#diff-07023adacd31a9f2a582548d1c6fbcbbR103).

If my assumptions are correct, it would be useful to have a way to stop the propagation of the widget re-render trigger, or a way to ‘turn off’ the re-render triggers for certain widgets.

For example this would be useful for the [`search-term`](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6#L5) widget, which is currently triggering the entire header to be re-rendered on every keyup in the search input. It would also be useful in various ways for Babble.

---

_[View the full topic](https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347)._
