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.

Unhandled Rejection (NotFoundError): Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

See original GitHub issue

I have a component <ComponentWithVideo /> that contains a list of tracks that are being rendered in a single <video/> element.

That I rendered with <InPortal /> and displayed to <OutPortal />

This error occurs when I add another track and <ComponentWithVideo(s) /> re-renders.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pimterrycommented, Mar 30, 2022

That would work, and it’s a nice quick workaround you can use to fix this today.

It does affect the DOM structure though in a way that could affect styles (e.g. direct descendent selectors) which I’d like to avoid.

Using an empty text node doesn’t have that problem, and should work equally well as a proper fix, so while an extra div is good as a quick workaround, I’d like to avoid implementing that as the real solution.

0reactions
pimterrycommented, Apr 1, 2022

Oooh, that’s really interesting, and yes that’s a complicated case that’s not handled well right now.

Any idea what the actual DOM transformations React is doing there are? The insertBefore in the previous case made sense, and seemed easy enough to handle, but it sounds like this is doing something different.

In the meantime, you can probably handle this (and many other similar cases) by using key to force React to re-render the OutPortal during this update, instead of moving it. That way, React will first call componentWillUnmount on the OutPortal (triggering the logic here that resets the placeholders), then it will mutate the DOM with placeholders everywhere as it expects, then it will mount a new OutPortal, and React-Reverse-Portal can then kick in and put the portal node content back. Since the actual DOM content lives inside your portalNode, making the OutPortal effectively stateless, that should be very cheap and totally invisible as a user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught NotFoundError: Failed to execute 'insertBefore' on ...
I'm getting this error message: Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be ......
Read more >
Failed to execute 'insertBefore' on 'Node': The node ... - GitHub
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this...
Read more >
Failed to execute 'insertBefore' on 'Node' - Vue Forum
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this...
Read more >
error domexception: failed to execute 'insertbefore' on 'node'
React NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child...
Read more >
VIBE BP 1.4.6 and console errors - wplms
DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of...
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