From 95e86727b3e4eab14f78205474be2dd46260f5a6 Mon Sep 17 00:00:00 2001 From: Sahinur Date: Tue, 13 Oct 2026 10:33:22 +0600 Subject: [PATCH] Exclude the fallback ghost from toArray() (#2456) With forceFallback the ghost is a clone of dragEl, including its data-id, and is appended to the list itself unless fallbackOnBody is set. toArray() therefore reported the dragged item twice for the whole drag (e.g. in onStart). Skip Sortable.ghost there, the same way lastChild() and getChild() already do. --- src/Sortable.js | 3 ++- tests/Sortable.test.js | 15 +++++++++++++++ tests/fallback.html | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/fallback.html diff --git a/src/Sortable.js b/src/Sortable.js index 72f571c82..99fdcb28a 100644 --- a/src/Sortable.js +++ b/src/Sortable.js @@ -1603,7 +1603,8 @@ Sortable.prototype = /** @lends Sortable.prototype */ { for (; i < n; i++) { el = children[i]; - if (closest(el, options.draggable, this.el, false)) { + // The fallback ghost is a clone of dragEl that may live inside the list (#2456) + if (el !== Sortable.ghost && closest(el, options.draggable, this.el, false)) { order.push(el.getAttribute(options.dataIdAttr) || _generateId(el)); } } diff --git a/tests/Sortable.test.js b/tests/Sortable.test.js index 59ce11f46..c0d3fa923 100644 --- a/tests/Sortable.test.js +++ b/tests/Sortable.test.js @@ -384,3 +384,18 @@ test('Do not insert into empty list if outside emptyInsertThreshold', async brow }) .expect(dragStartPosition.innerText).eql(dragEl.innerText); }); + + +fixture `Fallback` + .page `./fallback.html`; + +test('toArray does not include the fallback ghost', async browser => { + const dragEl = await list1.child(0)(); + const target = await list1.child(2)(); + + await browser + .dragToElement(dragEl, target) + .expect(list1.child(2).innerText).eql(dragEl.innerText) + .expect(browser.eval(() => window.orderOnStart)).eql(['a', 'b', 'c', 'd', 'e']) + .expect(browser.eval(() => window.orderOnEnd)).eql(['b', 'c', 'a', 'd', 'e']); +}); diff --git a/tests/fallback.html b/tests/fallback.html new file mode 100644 index 000000000..44fb8a281 --- /dev/null +++ b/tests/fallback.html @@ -0,0 +1,36 @@ + + + + + + + + +
+
Item 1.1
+
Item 1.2
+
Item 1.3
+
Item 1.4
+
Item 1.5
+
+ + + + + + + +