Skip to content

Commit

Permalink
Nullify unreachable references to dom nodes inside setTimeout(), to a…
Browse files Browse the repository at this point in the history
…llow garbage collection. (#1330)
  • Loading branch information
croxton authored Mar 28, 2023
1 parent 5a5ebd7 commit 8cd3a48
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ return (function () {
function removeElement(elt, delay) {
elt = resolveTarget(elt);
if (delay) {
setTimeout(function(){removeElement(elt);}, delay)
setTimeout(function(){
removeElement(elt);
elt = null;
}, delay);
} else {
elt.parentElement.removeChild(elt);
}
Expand All @@ -480,7 +483,10 @@ return (function () {
function addClassToElement(elt, clazz, delay) {
elt = resolveTarget(elt);
if (delay) {
setTimeout(function(){addClassToElement(elt, clazz);}, delay)
setTimeout(function(){
addClassToElement(elt, clazz);
elt = null;
}, delay);
} else {
elt.classList && elt.classList.add(clazz);
}
Expand All @@ -489,7 +495,10 @@ return (function () {
function removeClassFromElement(elt, clazz, delay) {
elt = resolveTarget(elt);
if (delay) {
setTimeout(function(){removeClassFromElement(elt, clazz);}, delay)
setTimeout(function(){
removeClassFromElement(elt, clazz);
elt = null;
}, delay);
} else {
if (elt.classList) {
elt.classList.remove(clazz);
Expand Down Expand Up @@ -3410,6 +3419,7 @@ return (function () {
};
setTimeout(function () {
triggerEvent(body, 'htmx:load', {}); // give ready handlers a chance to load up before firing this event
body = null; // kill reference for gc
}, 0);
})

Expand Down

0 comments on commit 8cd3a48

Please sign in to comment.