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
Document doesn't track lost child #456
Comments
Thank you for the detailed report. There was some error in the code sample you added, so I first had some trouble understanding it. But when I checked the stackblitz, I was able to understand it. There are two issues that are potentially related: #135 #145 As far as I can see at first glance, as soon as move 1 works correctly, move 2 should also work as expected. I will have to decide which of the two bugs you reported to handle first, but both are top prio now. |
which is slightly different from the checks required when inserting a node. fixes #455 (only on the master branch for now, I want to test if this also takes care of #456) https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity https://dom.spec.whatwg.org/#concept-node-replace
Something really strange happened: Today I finally had time to add your reproduction scenario as a testcase. So the good news it I just need to port the fix to the other versions, while the bad thing is, that could already have been done some days ago. |
which is slightly different from the checks required when inserting a node. Also fixes the missing `Document.ownerDocument`, which prevented proper deletion of childNodes from `Document`. fixes #455 (only on the master branch for now, I want to test if this also takes care of #456) https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity https://dom.spec.whatwg.org/#concept-node-replace
which is slightly different from the checks required when inserting a node. Also fixes the missing `Document.ownerDocument`, which prevented proper deletion of childNodes from `Document`. Also fixes properly disconnecting removed children from it's previous parent. fixes #455 (only on the master branch for now, I want to test if this also takes care of #456) https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity https://dom.spec.whatwg.org/#concept-node-replace
Versions 0.7.9 and 0.8.6 have been released with a fix for this bug |
In 0.8.6 this is not completely fixed! The (Error: Hierarchy request error: Only one element can be added and only after doctype) is still generated (in my case hundreds of times) greatly affecting performance.
This slightly modified code from the original above produces the error:
|
@ewrayjohnson thank you for reporting, I will have a closer look today, to decide if I need to reopen this issue or we should have a separate one. |
@ewrayjohnson the if you want to remove the first element you should be able to use If you want to provide a different example, which is closer to what you are trying do do, please report a new issue. |
Describe the bug
Since the 0.8.4 update, documents do not seem to realize that they've lost their (only) child when they get reparented.
To Reproduce
https://stackblitz.com/edit/js-xmldom-template-myg9ht?file=index.js
Expected behavior
newRoot.appendChild(oldRoot)
should change theoldRoot
's parent to be thenewRoot
, which should mean that the document loses its child. Running the above code in Chrome's console confirms this behavior. Instead I get:xmldom 0.8.4 instead says that the document still has 1 child after the first move, so the second move fails according to the new one-child-per-document rule. (
Error: Hierarchy request error: Only one element can be added and only after doctype
)xmldom 0.8.3 somehow says 1 child after both moves, which is why I didn't see this issue before, but it's still wrong (should be 0 after the first move).
Runtime & Version:
xmldom version: 0.8.4
runtime version: Node v18.7.0
other related software and version: WIndows 11
The text was updated successfully, but these errors were encountered: