From 9052a4d520b7bd77c953381182e2837d126cef00 Mon Sep 17 00:00:00 2001 From: Mark Croxton Date: Thu, 14 Dec 2023 19:12:34 +0000 Subject: [PATCH] Prevent references to nodes swapped out of the dom accumulating as detached elements in memory (#2091) * Prevent references to elements swapped out of the dom accumulating as detached nodes (memory leak). * Safely delete internal data when we tear down a node --- src/htmx.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 60c463e2..668148ec 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -961,10 +961,8 @@ return (function () { } }); } - if (internalData.initHash) { - internalData.initHash = null - } deInitOnHandlers(element); + forEach(Object.keys(internalData), function(key) { delete internalData[key] }); } function cleanUpElement(element) { @@ -988,7 +986,6 @@ return (function () { } else { newElt = eltBeforeNewContent.nextSibling; } - getInternalData(target).replacedWith = newElt; // tuck away so we can fire events on it later settleInfo.elts = settleInfo.elts.filter(function(e) { return e != target }); while(newElt && newElt !== target) { if (newElt.nodeType === Node.ELEMENT_NODE) {