Fix list reorder using wrong neighbours when non-list siblings present (#5997)

saveSorting() computed the new sort from ui.item.prev('.js-list') /
.next('.js-list'), which jQuery only matches when the sibling is *immediately*
adjacent. The lists container also renders the +addListForm composer and, when a
card is open, a +cardDetails element between lists, so an interspersed non-list
sibling made calculateIndex mis-detect the first/last position and compute a
wrong sort. The reordered list then landed somewhere other than where it was
dropped and looked like the new order was not persisted.

Use prevAll/nextAll('.js-list:not(.js-list-composer)').first() so the nearest
actual list neighbour is found regardless of interspersed elements.

Verified out-of-band that the server side persists correctly: a DDP call to
updateListSort reorders the lists collection and the sort:1 query returns the new
order, so the regression was in the client-side neighbour detection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lauri OjansivuandClaude Opus 4.8 committed 2026-06-22 06:03:32 +03:00
1 parent 0abaf03ba0
commit 1165c9b6db
1 file changed
+10 -2
+10 -2
View File
@@ -18,8 +18,16 @@ function saveSorting(ui) {
}
// To attribute the new index number, we need to get the DOM element
// of the previous and the following list -- if any.
const prevListDom = ui.item.prev('.js-list').get(0);
const nextListDom = ui.item.next('.js-list').get(0);
// Use prevAll/nextAll (not prev/next) so non-list siblings between lists do
// not break neighbour detection: the lists container also renders the
// +addListForm composer and, when a card is open, a +cardDetails element.
// jQuery's .prev('.js-list') only matches an *immediately* adjacent sibling,
// so an interspersed composer/cardDetails made calculateIndex mis-detect the
// first/last position and compute a wrong sort, so the reordered list landed
// elsewhere and looked like it did not persist. See
// https://github.com/wekan/wekan/issues/5997
const prevListDom = ui.item.prevAll('.js-list:not(.js-list-composer)').get(0);
const nextListDom = ui.item.nextAll('.js-list:not(.js-list-composer)').get(0);
const sortIndex = calculateIndex(prevListDom, nextListDom, 1);
const listDomElement = ui.item.get(0);