Skip to content

fix: keep macro action order in sync after drag and drop - #3067

Merged
mondalaci merged 1 commit into
masterfrom
fix-macro-drag-and-drop-reorder
Oct 14, 2026
Merged

mondalaci merged 1 commit into
masterfrom
fix-macro-drag-and-drop-reorder

Conversation

@mondalaci

Copy link
Copy Markdown
Member

Fixes #3065.

Problem

Reordering macro actions moved the actual list DOM nodes, which put the DOM out of sync with the view order Angular tracks for *ngFor. The reordered model was then rendered against that desynced view order, so actions were duplicated or left in place instead of moving.

Fix

  • DragAndDropDirective now records the container's child order on pointerdown and restores it in onPointerUp (after computing the reordered model, before emitting). The live drag preview is unchanged; the DOM is handed back to Angular in the order its view container expects, so Angular renders the emitted model consistently.
  • MacroListComponent drops the obsolete isMacroReordering content-based trackBy workaround and uses a plain index trackBy. That workaround was only needed for the previous dragula-based flow (which left the DOM moved); with the restore it made Angular move views against the stale DOM order and reintroduced the bug. Normal editing still uses index keys, so the in-line command editor keeps its focus.

Verification

Built uhk-web and drove the real app in Chromium with synthetic pointer events:

  • Issue steps (drag 2nd item to 3rd place, then drag 1st item anywhere): displayed order matches the model order at every step.
  • 150 randomized drags: 0 mismatches/desyncs (data-index order stays 0,1,2 and visible order equals model order).
  • Before the trackBy change the same harness reproduced the desync (1,2,0 / 2,0,1).

ng lint passes with 0 errors (one pre-existing unrelated warning) and npm test passes 33/33.

Moving the list items changed the DOM order behind Angular's *ngFor view
order, so the reordered model was rendered against a desynced view order,
duplicating or misplacing macro actions (issue #3065).

Restore the pre-drag DOM order in DragAndDropDirective before emitting the
reordered model so Angular re-renders it consistently, and drop the
obsolete isMacroReordering content-based trackBy hack that made Angular
move views against the stale DOM order.
@mondalaci
mondalaci merged commit eecbfdf into master Oct 14, 2026
6 checks passed
@mondalaci
mondalaci deleted the fix-macro-drag-and-drop-reorder branch October 14, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in Macro drag and drop actions

1 participant