# הבנת מחזור החיים של אובייקט DOM

**URL:** <https://meta.discourse.org/t/understanding-dom-object-lifecycle/211545>\
**Category:** Development\
**Created:** [8 בדצמבר,‏ 2021,‏ 8:57pm UTC](https://meta.discourse.org/t/understanding-dom-object-lifecycle/211545 "2021-12-08T20:57:04Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![rmccown](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rmccown/32/155375_2.png) [@rmccown](https://meta.discourse.org/u/rmccown)\
**Post date:** [8 בדצמבר,‏ 2021,‏ 8:57pm UTC](https://meta.discourse.org/t/understanding-dom-object-lifecycle/211545/1 "2021-12-08T20:57:04Z")

</div>

Hi folks. Trying to puzzle out a problem with what I think is DOM object lifecycle. I’ve read through this thread [A tour of how the Widget (Virtual DOM) code in Discourse works](https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347) but it still doesn’t help answer my question, or at least point me in a direction to try and solve my problem. I’m having trouble wrapping my head around it.

I’ve written a very basic plugin as a wrapper for an external service (Rumbletalk chat engine, to be precise) The plugin works as I would like, the chat works, etc, _except_ if you navigate away from the chat to some other part of my site, and then back to chat. I get an error from their included javascript that I’m trying to create a duplicate chat.

The plugin is a simple hbs/widget that creates the following HTML

```plaintext
<div style="height: 500px;">
  <div id="$MY_ID"></div>
  <script src="https://rumbletalk.com/client/?$MY_OTHER_ID"></script>
</div>

```

And has some log-in javscript as well.

I’m assuming that somewhere in the DOM, the rendered HTML is still around, and when this script tag loads and runs again, it detects it. When I debug in the dev console, I am seeing the error throw from the javascript from the script tag, not the login code.

I’ve reached out to the staff at Rumbletalk, but have had no reply as of yet. Does anyone have a suggestion as to what I can look at next? The only thing I’ve managed to do is add a `window.onerror` handler and then do a `location.reload()`. This obviously isn’t a good solution. Is there a way for me to ‘flush’ the chat engine DOM objects when the page goes out of focus?

Thanks for any help

-=Bob

---

_[View the full topic](https://meta.discourse.org/t/understanding-dom-object-lifecycle/211545)._
