Open verheyenkoen opened 6 months ago
As an alternative, the timeoutID from setTimeout
could be stored in the nodes' dataset, so we have a way to cancel the timeout before it fires using clearTimeout
, eg:
if (timing) {
elt.dataset.removeMeTimeout = setTimeout(function () {
elt.parentElement.removeChild(elt);
}, htmx.parseInterval(timing));
}
When the remove-me timeout fires, it will remove the node with the
remove-me
attribute from the DOM, like this: https://github.com/bigskysoftware/htmx/blob/adfd2c8bc8c710ee6935af7644de04e3081d099e/src/ext/remove-me.js#L6However, in some cases, this node may already have been removed before the timeout fires and this code errors with:
A use case where this could happen is a flash toast message that also includes a dismiss button/icon (or gesture) and also removes the same node (or a parent) from the DOM.
I suggest to fix this using the
Node.prototype.isConnected
property within the setTimeout callback. Since IE11 compatibility is required, that would also require the isConnected-polyfill to be added.