Closed mdafanasev closed 2 months ago
Using insertBefore with a comment node results in copying the target node instead of moving it
insertBefore
// Create container const container = document.createElement("div"); document.body.appendChild(container); // Create child const child = document.createElement("p"); child.textContent = "Hi"; container.appendChild(child); // Create comment node const comment = document.createComment(""); container.appendChild(comment); // Query nodes, it returns "['Hi']", as expected console.log(document.querySelectorAll("p").map(item => item.textContent)); // Try to move node container.insertBefore(child, comment); // Query nodes, "['Hi']" expected, but it returns "['Hi', 'Hi']" console.log(document.querySelectorAll("p").map(item => item.textContent));
Expected result:
The target node should be moved or remain untouched
Actual result:
The target node is duplicated
I have created a repository with a minimal reproduction of the issue
https://github.com/mdafanasev/happy-dom-insert-before-comment-issue
@happy-dom/global-registrator: 14.7.1
NodeJS: 20.11.0
Description
Using
insertBefore
with a comment node results in copying the target node instead of moving itSteps to reproduce
Expected result:
The target node should be moved or remain untouched
Actual result:
The target node is duplicated
Reproduction
I have created a repository with a minimal reproduction of the issue
https://github.com/mdafanasev/happy-dom-insert-before-comment-issue
Environment
@happy-dom/global-registrator: 14.7.1
NodeJS: 20.11.0