Skip to content
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

insertBefore with a comment node causes duplication of node #1406

Closed
mdafanasev opened this issue Apr 13, 2024 · 0 comments · Fixed by #1407
Closed

insertBefore with a comment node causes duplication of node #1406

mdafanasev opened this issue Apr 13, 2024 · 0 comments · Fixed by #1407
Labels
bug Something isn't working

Comments

@mdafanasev
Copy link
Contributor

Description

Using insertBefore with a comment node results in copying the target node instead of moving it

// 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));

Steps to reproduce

  1. Create a DOM element and add it to the container
  2. Create a comment node and add it to the same container
  3. Attempt to move the element using insertBefore, using the comment node as the reference node

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

@mdafanasev mdafanasev added the bug Something isn't working label Apr 13, 2024
@mdafanasev mdafanasev changed the title Call of insertBefore with a comment node causes duplication of node insertBefore with a comment node causes duplication of node Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant