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

Unhandled rejection Error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node #55

Closed
LELOG opened this issue Oct 23, 2018 · 13 comments
Assignees
Labels

Comments

@LELOG
Copy link

LELOG commented Oct 23, 2018

err

@LELOG
Copy link
Author

LELOG commented Oct 23, 2018

Rendering errors in the react

@dungcodelynx
Copy link

I also suffers from this error. The interesting part is that there is another bug making dragging item display other HTMLElement #1380 . So I guess there is must be a relation with this bug.

@owen-m1
Copy link
Member

owen-m1 commented Nov 19, 2018

Could you please create a JSBin or provide access to a live program that produces this error?

@owen-m1 owen-m1 transferred this issue from SortableJS/Sortable Dec 16, 2018
@owen-m1
Copy link
Member

owen-m1 commented Dec 16, 2018

@cheton I saw this issue occurs in the last example of your demo when moving an item from the left list to the right list

@cheton
Copy link
Collaborator

cheton commented Dec 16, 2018

So far I cannot figure out a way to easily reproduce this issue, but sometimes this will happen when calling unmountHostComponent within react-dom, as shown below:

image

When the exception occurrs in removeChild(currentParent, node.stateNode), it shows that the parentInstance is on the left side:

screenshot 2018-12-16 17 05 09

However, the child node itself is actually on the right:

screenshot 2018-12-16 17 05 54

I believe the way we manipulate the DOM may cause unexpexcted behaviour to React, but I'm not sure what actions will affect React's Virtual DOM in this case.

@owen-m1
Copy link
Member

owen-m1 commented Dec 16, 2018

@cheton It only happens if you move an item from the left to the right on the demo above the last one.. and then when you do the same thing on the last demo it causes the error.

It has to do with line 64.

@cheton
Copy link
Collaborator

cheton commented Dec 16, 2018

@owen-m1 The removeChild exception is occurred within react-dom when calling unmountHostComponent in React v16 (Fiber) (or processUpdates in DOMChildrenOperation with React v15), not the line #64 in src/Sortable.jsx as you mentioned:

image

So even remove the line of removeChild from the code will not help, I just removed the line and can confirm this issue still happened.

@owen-m1
Copy link
Member

owen-m1 commented Dec 16, 2018

@cheton Yeah you're right.. I wasn't using the debugger. Could it be that when you are changing the state of the list on the left, react DOM sees it needs to remove the list item you dragged to the right, but when it tries to remove it, it cannot because Sortable has already moved it to the other list.

@gmasci-ca
Copy link

any news?

@gmasci-ca
Copy link

I've the same problem

@jkrasnay
Copy link

You can fix this by moving the DOM element back to its original position in your onAdd handler and letting React handle its removal. This is how they do it in the react-sortablejs module:

const referenceNode = (store.nextSibling && store.nextSibling.parentNode !== null) ? store.nextSibling : null;
evt.from.insertBefore(evt.item, referenceNode);

You might be able to get away with passing null instead of tracking the reference node, which adds the node back as its parent's last child. You probably have to have a key property on the child nodes, though.

@ultralabed
Copy link
Collaborator

Currently, this can be reproduce by following steps

  1. Select item from Uncontrolled list on the left, then drag it to the right.
  2. Select item from Controlled list on the left, then drag it to the right.
  3. You will see error in the console

Below is an gif console logging the event handler from the sortable.js and reproduces of the this bug.

unhandledrejectionerrorfaile

@cheton
Copy link
Collaborator

cheton commented Feb 18, 2019

Thank @ultralabed for fixing this issue. It's fixed in v1.5.1 and was published to npm. Please let us know whether you are still facing this issue.

@cheton cheton closed this as completed Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants