Skip to content
Bug reportDec 1, 2026· 0:28· 14 views

VueUse useSortable: drag to position 0 silently drops update — DOM diverges from reactive array

0:28 total

Comments · 0

Be the first to comment.

Bug reportby SceneRecap AI

high@vueuse/integrations useSortable onUpdate handler. The guard `if (!e.newIndex || !e.oldIndex) return` treats index 0 as missing, so moves to or from position 0 return early. Check for null/undefined instead, for example `e.newIndex == null || e.oldIndex == null`.
os: macOSdpr: 1locale: en-USbrowser: Chromium 151.0.7922.34package: @vueuse/integrations useSortable (vueuse/vueuse#5737 demo page)timezone: Europe/Berlinviewport: 1280x720sortablejs: 1.15.6 (from on-page header at 1.0s)

Repro steps

  1. 1.Open the VueUse #5737 useSortable demo page. The sortable list and the reactive array both show Item A, Item B, Item C, Item D.
  2. 2.Drag the last item, Item D, to the top of the sortable list (position 0).
  3. 3.Compare the sortable list (DOM order) with the reactive array (list.value).
  4. 4.Click the 'Simulate Vue re-render' button to reconcile the DOM with the array.

Expected

After Item D is dropped at the top, the reactive array updates to [Item D, Item A, Item B, Item C] to match the DOM. A later Vue re-render keeps Item D at the top.

Actual

SortableJS moves Item D to the top of the DOM, but the reactive array stays [Item A, Item B, Item C, Item D]. The page reports the two as diverged. After a Vue re-render, the DOM reverts to [Item A, Item B, Item C, Item D]. Item D returns to position 3 and the user's drag is lost without any error.

Evidence

visualInitial state: the sortable list and the reactive array both show Item A, Item B, Item C, Item D. The banner reads 'Drag Item D (last) to the top to demonstrate the bug.'
visualAfter the drag, the sortable list shows Item D, Item A, Item B, Item C. The reactive array still shows [0] Item A, [1] Item B, [2] Item C, [3] Item D.
consoleAfter drag: DOM: [Item D, Item A, Item B, Item C] | Array: [Item A, Item B, Item C, Item D] | diverged: true
visualA red banner shows 'DIVERGED' with DOM = [Item D, Item A, Item B, Item C] but Array = [Item A, Item B, Item C, Item D]. An overlay reads 'onUpdate: !e.newIndex === !0 === true → returned early'.
visualA code panel shows the onUpdate handler line 'if (!e.newIndex || !e.oldIndex) return // 0 is falsy → drag to top skipped'.
consoleAfter Vue re-render: DOM: [Item A, Item B, Item C, Item D] (DOM reverted; Item D flew back to position 3; user drag lost)
visualAfter the re-render, the DOM is back to Item A, Item B, Item C, Item D. An overlay reads 'User dragged D to top; drag was silently lost'.
consoleUnrelated warning: the SortableJS CDN script is loaded via document.write as a parser-blocking cross-site script.
Issue markdown (copy-paste ready)
## Summary
In `@vueuse/integrations` `useSortable`, dragging an item to index 0 does not update the reactive array. SortableJS still moves the DOM node, so the DOM and `list.value` diverge. The next Vue re-render reverts the DOM, and the user's drag is lost without any error.

## Environment
- Chromium 151.0.7922.34, macOS, 1280x720, dpr 1
- SortableJS 1.15.6 (from the page header at 1.0s)
- Demo page for vueuse/vueuse#5737

## Steps to reproduce
1. Open the demo page. The list and the array both show Item A, Item B, Item C, Item D (1.0s).
2. Drag Item D (last) to the top of the sortable list (7.9s).
3. Compare the DOM list with the reactive array (9.0s).
4. Click **Simulate Vue re-render** (17.5s).

## Expected
The array becomes `[Item D, Item A, Item B, Item C]`, and Item D stays at the top after a re-render.

## Actual
- DOM: `[Item D, Item A, Item B, Item C]`. Array: `[Item A, Item B, Item C, Item D]`, unchanged (9.0s).
- Console at 9.4s: `After drag, DOM: [Item D, Item A, Item B, Item C] | Array: [Item A, Item B, Item C, Item D] | diverged: true`
- The page shows a DIVERGED banner and the overlay `onUpdate: !e.newIndex === !0 === true → returned early` (11.0s).
- After the re-render, the DOM reverts to `[Item A, Item B, Item C, Item D]` (18.8s console, 19.0s visual). The drag is lost.

## Suspected cause
The onUpdate handler shown on the page (11.0s):
```js
if (!e.newIndex || !e.oldIndex) return // 0 is falsy, drag to top skipped
```
Index `0` is falsy, so any move to or from position 0 returns early. Suggested fix: check for missing indices with `e.newIndex == null || e.oldIndex == null`.

## Notes
The console warning at 0s about the SortableJS CDN script loading via `document.write` is unrelated to this bug.

*Recorded with SceneRecap.*

This report was written by SceneRecap from a screen recording. Try SceneRecap free

Turn a screen recording into a bug report like this one.

Repro steps, expected vs actual and the console and network evidence, each with a timestamp. On every plan, Free included.

Try SceneRecap free →
VueUse useSortable: drag to position 0 silently drops update — DOM diverges from reactive array · SceneRecap