perf(DraggableList): skip update if dnd to the same position (#9255)

This commit is contained in:
one
2025-08-17 21:34:37 +08:00
committed by GitHub
parent e652c1d783
commit 0b8c6ee536
3 changed files with 10 additions and 8 deletions

View File

@@ -157,8 +157,7 @@ describe('DraggableList', () => {
// 模拟拖拽到自身
window.triggerOnDragEnd({ source: { index: 1 }, destination: { index: 1 } }, {})
expect(onUpdate).toHaveBeenCalledTimes(1)
expect(onUpdate.mock.calls[0][0]).toEqual(list)
expect(onUpdate).toHaveBeenCalledTimes(0)
})
})
@@ -175,8 +174,7 @@ describe('DraggableList', () => {
// 拖拽自身
window.triggerOnDragEnd({ source: { index: 0 }, destination: { index: 0 } }, {})
expect(onUpdate).toHaveBeenCalledTimes(1)
expect(onUpdate.mock.calls[0][0]).toEqual(list)
expect(onUpdate).toHaveBeenCalledTimes(0)
})
it('should not crash if callbacks are undefined', () => {

View File

@@ -38,8 +38,10 @@ const DraggableList: FC<Props<any>> = ({
if (result.destination) {
const sourceIndex = result.source.index
const destIndex = result.destination.index
const reorderAgents = droppableReorder(list, sourceIndex, destIndex)
onUpdate(reorderAgents)
if (sourceIndex !== destIndex) {
const reorderAgents = droppableReorder(list, sourceIndex, destIndex)
onUpdate(reorderAgents)
}
}
}

View File

@@ -82,8 +82,10 @@ function DraggableVirtualList<T>({
if (onUpdate && result.destination) {
const sourceIndex = result.source.index
const destIndex = result.destination.index
const reorderAgents = droppableReorder(list, sourceIndex, destIndex)
onUpdate(reorderAgents)
if (sourceIndex !== destIndex) {
const reorderAgents = droppableReorder(list, sourceIndex, destIndex)
onUpdate(reorderAgents)
}
}
}