Skip to content

fix(checklist): respect drop position when reordering subitems#518

Open
reniko wants to merge 1 commit into
fccview:developfrom
reniko:fix/subitem-reorder-position
Open

fix(checklist): respect drop position when reordering subitems#518
reniko wants to merge 1 commit into
fccview:developfrom
reniko:fix/subitem-reorder-position

Conversation

@reniko
Copy link
Copy Markdown
Contributor

@reniko reniko commented May 22, 2026

Summary

Dragging a subitem and dropping it between two siblings always inserted
it at the top of the parent's children list, ignoring the drop position.
Top-level reordering was unaffected.

Steps to reproduce

  1. Create a checklist item A with subitems A1, A2, A3.
  2. Drag A3 and drop it between A1 and A2.
  3. Expected order: A1, A3, A2. Actual order: A3, A1, A2.

Reproduces on develop in Firefox, Edge and Brave.

Root cause

handleDragEnd in app/_hooks/useChecklist.tsx decides whether to drop
before or after the target by matching the drop-zone id prefix
"drop-after::". Top-level drop indicators use that prefix, but subitem
drop indicators use "drop-after-child::" (see NestedChecklistItem.tsx).

"drop-after-child::…".startsWith("drop-after::") is false, so the
check never matched for subitems and position always fell back to
"before" — inserting the dragged item before the target instead of
after it.

The same check is used both for the optimistic local update and for the
position value sent to the reorderItems server action, so the wrong
result was consistent and persisted to disk.

Fix

Match the prefix "drop-after" (without the trailing ::) at both call
sites, so it matches drop-after:: and drop-after-child:: alike. This
mirrors the isDropIndicator check a few lines above, which already uses
the "drop-after" / "drop-before" prefixes. drop-before /
drop-before-child indicators still correctly fall through to "before".

Two-line change, no other files. The server action was already correct —
it just consumes the position it receives.

Tests done

  • Subitem A3 dropped between A1 and A2A1, A3, A2
  • Subitem dropped after the last sibling → lands last
  • Subitem dropped before the first sibling → lands first
  • Top-level reorder still works (drop before/after top-level items)
  • Reload the page — the new order persists

Subitem drag-and-drop always inserted the dragged item before the drop
target instead of at the indicated position, so it landed at the top of
the parent's children.

The before/after check in handleDragEnd matched the drop-zone id prefix
"drop-after::", but subitem drop indicators use the prefix
"drop-after-child::". The check never matched for subitems, so position
always fell back to "before". Top-level reorder was unaffected because
its indicators do use "drop-after::".

Match the prefix "drop-after" so both top-level and subitem indicators
resolve correctly, consistent with the isDropIndicator check that
already uses that prefix.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant