question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught (in promise) DOMException: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent.

See original GitHub issue

React version:

  • react@15.3.2
screen shot 2016-10-20 at 3 36 59 pm

preact-compat version:

  • preact@6.3.0
  • preact-compat@3.8.2
screen shot 2016-10-20 at 3 37 14 pm

Error:

VM12394:328 Uncaught (in promise) DOMException: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent.
    at Error (native)
    at renderComponent (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:328:71)
    at setComponentProps (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:281:103)
    at buildComponentFromVNode (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:362:13)
    at idiff (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:176:48)
    at innerDiffNode (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:231:21)
    at idiff (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:185:279)
    at diff (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:157:19)
    at renderComponent (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:323:32)
    at setComponentProps (eval at <anonymous> (http://localhost:5000/vendor.032262c576e185ee7774db6908b8649d.js:3238:1), <anonymous>:281:103)

Code:

const ChatWindow = props => {
  const emote = props.is_emote_open ? <EmoteSelector {...props} /> : null
  const options = props.is_options_open ? <ChatOptions {...props} /> : null
  return (
    <aside className={styles.root} >
      <ChatWindowHeader {...props} />
      <MessageWindow {...props} />
      <ComposeMessage {...props} />
      {emote}
      {options}
    </aside>
  )
}

ChatWindowHeader contains a button to control showing {options} or not. But it will cause DOMException in preact-compat version but works well in react version.

https://github.com/developit/preact/blob/master/src/vdom/component.js#L154-L157 The base and the parent are not correct in my case.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
developitcommented, Oct 20, 2016

Great! Since I have a minimal reproduction of that issue, it should be solved shortly. I’ll keep this open until it’s fixed! Thanks for the quick responses.

1reaction
developitcommented, Oct 20, 2016

By the way - you might find that adding keys to those conditional components or wrapping them in a div works as a workaround in the meantime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The new child element contains the parent - Stack Overflow
You can't append an element to itself. The error message itself is slightly confusing as it says "The new child element contains the...
Read more >
Failed to execute 'replaceChild' on 'Node': The new child ...
Uncaught (in promise) DOMException: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent. #229.
Read more >
Node.replaceChild() - Web APIs - MDN Web Docs
The replaceChild() method of the Node element replaces a child node within the given (parent) node. Syntax. replaceChild(newChild, oldChild)
Read more >
DOMNode::replaceChild - Manual - PHP
This function replaces the child child with the passed new node. ... The $parent variable now holds the new node as a document...
Read more >
uncaught domexception: failed to execute 'insertbefore' on 'node'
Your problem seems to happen because of the nested selectors ( .js-toprow ) that are later moved. Try replacing all the .find() (matches...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found