htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Remove-me extension should check if DOM node is still connected

Open verheyenkoen opened this issue 2 months ago • 1 comments

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#L6

However, in some cases, this node may already have been removed before the timeout fires and this code errors with:

Uncaught TypeError: Cannot read properties of null (reading 'removeChild')

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.

verheyenkoen avatar Apr 19 '24 09:04 verheyenkoen