bevacqua / dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/dragula/
MIT License
22.01k stars 1.97k forks source link

In some cases, a `drop` is misidentified as a `cancel`. #563

Open Hypercubed opened 6 years ago

Hypercubed commented 6 years ago

I've been able to identify and reproduce a bug where, in some cases, a drop is misidentified as a cancel.

A plunkr is here: https://embed.plnkr.co/9RBLky9DWbE2Inhp4sI1/.

However, the issue is difficult to produce. Here (https://www.screencast.com/t/cfMdBtDrOQ3) is a video showing the bug happening. You will notice that each time the item moves "drop" is logged. When a "cancel" event is emitted the nodes parent element must be the source container. You will notice that in the last "drop" a cancel event is emitted instead of a "drop" event even though the item has indead moved. The error can be identified in the event callback by a cancel event where the node's parent is not the source container.

A fix, and one we are using for now in @swimlane/ngx-dnd, is to check for this invalid state here: https://github.com/bevacqua/dragula/blob/master/dragula.js#L258 using something like isInitialPlacement(target) && item.parentNode === target.