Skip to content

Commit

Permalink
fix(prev): prevent on cancel/handle drop accessing null props
Browse files Browse the repository at this point in the history
  • Loading branch information
amendx committed Sep 28, 2021
1 parent 99b5da7 commit 5949fc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/utils/container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,21 @@ function handleDrop ({ element, draggables, layout, getOptions }) {
) {
draggablesReset();
// if drop zone is valid => complete drag, else emit dropNotAllowed and everything will be reverted by draggablesReset()
if (!draggableInfo.cancelDrop) {
if (draggableInfo && !draggableInfo.cancelDrop) {
if (
draggableInfo.targetElement ||
getOptions().removeOnDropOut ||
forDispose
) {
const indexNotNull = (index) => index !== null;

const actualAddIndex =
addedIndex !== null
? removedIndex !== null && removedIndex < addedIndex
indexNotNull(addedIndex)
? indexNotNull(removedIndex) && removedIndex < addedIndex
? addedIndex - 1
: addedIndex
: null;

const dropHandlerParams = {
removedIndex,
addedIndex: actualAddIndex,
Expand Down
10 changes: 6 additions & 4 deletions src/utils/container/mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,12 @@ function cancelDrag () {
dragListeningContainers.forEach(container => {
container.handleDrag(outOfBoundsDraggableInfo);
});
draggableInfo.targetElement = null;
draggableInfo.cancelDrop = true;
onMouseUp();
isCanceling = false;
if (draggableInfo) {
draggableInfo.targetElement = null;
draggableInfo.cancelDrop = true;
onMouseUp();
isCanceling = false;
}
}
}
function Mediator () {
Expand Down

0 comments on commit 5949fc1

Please sign in to comment.