From 7325a106aff25fe77a0bcb6bc93e5f4d5c796dbc Mon Sep 17 00:00:00 2001 From: Ben Pate Date: Thu, 13 Aug 2020 19:46:19 -0600 Subject: [PATCH 1/2] Close connections on swapInnerHTML - connections were not being closed in all cases. This is a minimal patch to close connections when the InnerHTML is swapped out. --- src/htmx.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/htmx.js b/src/htmx.js index 7a5478b5..089d3056 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -481,8 +481,10 @@ return (function () { if (firstChild) { while (firstChild.nextSibling) { target.removeChild(firstChild.nextSibling); + closeConnections(firstChild.nextSibling) } target.removeChild(firstChild); + closeConnections(firstChild) } } From 3324532037bede824c4949a22e4eb3e3b98dd7c8 Mon Sep 17 00:00:00 2001 From: Ben Pate Date: Thu, 13 Aug 2020 19:56:55 -0600 Subject: [PATCH 2/2] Closing connections BEFORE removing nodes In some tests, the previous code triggered an htmx:swapError because the node had already been removed from the DOM before the closeConnections() function was called. I think it was a race condition that I didn't catch earlier. Switching the ordering of these two functions makes sense, and it looks like it's addressed the error. Sorry for the sloppy check-in. --- src/htmx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 089d3056..458e6e74 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -480,11 +480,11 @@ return (function () { insertNodesBefore(target, firstChild, fragment, settleInfo); if (firstChild) { while (firstChild.nextSibling) { - target.removeChild(firstChild.nextSibling); closeConnections(firstChild.nextSibling) + target.removeChild(firstChild.nextSibling); } - target.removeChild(firstChild); closeConnections(firstChild) + target.removeChild(firstChild); } }