-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
swapError when removing elements on htmx:beforeCleanupElement #3046
Comments
I think if you use the It may be possible to try adding if (bodyContains(r.nextSibling)) { e.removeChild(r.nextSibling) } to check if it exists before removing it. From the documentation for this event it says
which implies htmx is is likely to be removing this item from the DOM so ideally you should let it do its thing because by removing it early yourself it could prevent htmx from cleaning up its impacts as well. So ideally you should use this event to help de-init any listeners or other effects etc on the element you may have scripted in but leave the node itself for any further cleanup. |
I made further investigations. The exception is raised when, listening to the event This is because the property It also means that as of today when I delete the node concerned by the event, the next one will be deleted without receiving the event So, I guess the fix is more something like : function swapInnerHTML(target, fragment, settleInfo) {
const firstChild = target.firstChild
insertNodesBefore(target, firstChild, fragment, settleInfo)
if (firstChild) {
while (firstChild.nextSibling) {
const tmpSibling = firstChild.nextSibling;
cleanUpElement(tmpSibling)
if (target.contains(tmpSibling))
target.removeChild(tmpSibling)
}
cleanUpElement(firstChild)
target.removeChild(firstChild)
}
} |
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'.
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:
The text was updated successfully, but these errors were encountered: