Skip to content

Commit a8a97fe

Browse files
Ensure layouts recomputed correctly in relation to other effects.
Without this, issues could occur where collisions were detected against stale positions and items moved incorrectly as a result. In addition, layouts might not have been recomputed correctly on drag end if adjustments were made by custom `onDragEnd` handlers. Now, core behaviour such as `recomputeLayouts` and `detectCollisions` is called explicitly as part of `dragStart` and `dragEnd` to ensure correct ordering. For #55
1 parent bf19f7e commit a8a97fe

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
### Fixed
66

7+
- Ensure layouts recomputed before other effects on drag start. Without this,
8+
issues could occur where collisions were detected against stale positions and
9+
items moved incorrectly as a result. In addition, layouts might not have been
10+
recomputed correctly on drag end if adjustments were made by custom
11+
`onDragEnd` handlers. Now, core behaviour such as `recomputeLayouts` and
12+
`detectCollisions` is called explicitly as part of `dragStart` and `dragEnd`
13+
to ensure correct ordering.
14+
715
- Don't apply redundant adjustment transformer when a drag overlay is used.
816

917
## [0.7.0] - 2022-09-07

src/drag-drop-context.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,14 @@ const DragDropProvider: ParentComponent<DragDropContextProps> = (
637637
},
638638
};
639639

640+
recomputeLayouts();
641+
640642
batch(() => {
641643
setState("active", "draggableId", draggableId);
642644
addTransformer("draggables", draggableId, transformer);
643645
});
646+
647+
detectCollisions();
644648
};
645649

646650
const dragEnd: DragDropActions["dragEnd"] = () => {
@@ -651,6 +655,8 @@ const DragDropProvider: ParentComponent<DragDropContextProps> = (
651655
}
652656
setState("active", ["draggableId", "droppableId"], null);
653657
});
658+
659+
recomputeLayouts();
654660
};
655661

656662
const onDragStart: DragDropActions["onDragStart"] = (handler) => {
@@ -715,12 +721,7 @@ const DragDropProvider: ParentComponent<DragDropContextProps> = (
715721
);
716722
};
717723

718-
onDragStart(() => {
719-
recomputeLayouts();
720-
detectCollisions();
721-
});
722724
onDragMove(() => detectCollisions());
723-
onDragEnd(() => recomputeLayouts());
724725

725726
props.onDragStart && onDragStart(props.onDragStart);
726727
props.onDragMove && onDragMove(props.onDragMove);

0 commit comments

Comments
 (0)