The new child element contains the parent.
See original GitHub issueI have one component that should conditionally wrap another component (one it’s an app, the other is something like a mockup
for better visuals).
I was initializing them like:
const appContainer = document.createElement('DIV')
new App({ target: appContainer })
new POS({
target: root,
slots: {
default: appContainer,
},
})
And started receiving the error: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.
However, if you replace the createElement
with a createDocumentFragment
it works 100%.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
The new child element contains the parent - Stack Overflow
Part of the problem is that you are assigning both the <td> and the <img> the exact same id. You can't do that....
Read more >How to return true if the parent element ... - Tutorialspoint
In this tutorial, we are going to look at how we can return true if the parent element contains the child element in...
Read more >JavaScript: Return true if the parent element contains the child ...
Use Node.contains() to check if the parent element contains the child element. Sample Solution: JavaScript Code: //#Source https://bit.
Read more >Node.appendChild() - Web APIs - MDN Web Docs
Node.appendChild() ... The appendChild() method of the Node interface adds a node to the end of the list of children of a specified...
Read more >How to return true if the parent element ... - GeeksforGeeks
In order to check whether the parent element (say x) contains a child element (say y), we can use the children property to...
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 Free
Top 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
@ekhaled I see! Thank you so much for your insights 😁
Programmatic
slots
are not a public api. Svelte uses eitherappendNode
orinsertNode
depending on whether it has to render slot content conditionally.In OP’s case… if you set the
condition
to betrue
to start with (in Machine.html’sdata
), you will notice that it works perfectly.Fortunately, using a fragment works for both
insertNode
andappendNode