Uncaught (in promise) DOMException: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent.
See original GitHub issueReact version:
- react@15.3.2
preact-compat version:
- preact@6.3.0
- preact-compat@3.8.2
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:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.