Add guard against elements removed from the DOM

We can't guarantee that elements we stored a
reference to with `classesToPersist.remove` will
still exist so we need to guard against this.

Note: it checks for whether the node is still
attached to the DOM rather than whether it exists
because the standard way to delete a node just
detaches it from the DOM and relies on garbage
collection to delete it from memory.
This commit is contained in:
Tom Byers
2022-02-11 12:30:07 +00:00
parent 476ed1593c
commit 99df8542b4

View File

@@ -26,7 +26,11 @@
},
replace: function () {
this.classNames.forEach((className, index) => {
this.$els[index].addClass(className);
var $el = this.$els[index];
if (global.document.body.contains($el.get(0))) {
$el.addClass(className);
}
});
// remove references to elements