bigskysoftware / bigskysoftware/htmx
swapError when removing elements on htmx:beforeCleanupElement
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
Htmx version: 2.0.3
I use Htmx with a ui library (Kendo).
I listen to event `htmx:beforeCleanupElement` for kendo to clean nodes generated by the library.
An exception occurred in the function `swapInnerHTML` (line 1739):
**Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.**
```js
function swapInnerHTML(e, t, n) {
const r = e.firstChild;
if (insertNodesBefore(e, r, t, n),
r) {
for (; r.nextSibling; )
cleanUpElement(r.nextSibling), // this is where event htmx:beforeCleanupElement is raised
e.removeChild(r.nextSibling); // Exception here
cleanUpElement(r),
e.removeChild(r)
}
}
```
It seems that when I clean up on event, I destroy the `nextSibling` and the exception is raised.
---
Edit with the code found in the repo rather than the one found in my debugger:
```js
function swapInnerHTML(target, fragment, settleInfo) {
const firstChild = target.firstChild
insertNodesBefore(target, firstChild, fragment, settleInfo)
if (firstChild) {
while (firstChild.nextSibling) {
cleanUpElement(firstChild.nextSibling) // this is where event htmx:beforeCleanupElement is raised
target.removeChild(firstChild.nextSibling) // Exception here
}
cleanUpElement(firstChild)
target.removeChild(firstChild)
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.