Skip to content

Conversation

@acjnn
Copy link

@acjnn acjnn commented Nov 11, 2025

This commit addresses a few issues with manual reordering in the space navigator that caused items to behave unpredictably during drag-and-drop operations.

Issues Fixed:
#443, #408, #160

  1. Sortable Logic Clarity (dragPath.ts line 89-94)

    • Added explicit comments explaining sortable determination
    • Fixed edge case where nextItem could be undefined
    • Made the boolean logic more readable and maintainable
  2. Type Coercion Bug (dropPath.ts lines 43-48, 67-70)

    • Removed dangerous 'boolean && number' pattern that caused false to coerce to 0
    • Added explicit validation to reject drops on non-sortable spaces
    • Users now receive clear feedback when dropping in unsorted folders
    • Prevents silent failures and unexpected behavior
  3. Optimistic UI Updates (SpaceTreeView.tsx lines 196-252, 614-657)

    • Implemented optimistic rendering to update UI immediately on drop
    • Prevents the 'snap-back' visual glitch some users reported
    • Added rollback mechanism if database write fails
    • Preserved previous tree state for calculations to avoid race conditions

… issues

Fixes Make-md#443, Make-md#408, Make-md#160

This commit addresses multiple critical issues with manual reordering in the
space navigator that caused items to snap back to their original positions
or behave unpredictably during drag-and-drop operations.

**Issues Fixed:**

1. **Sortable Logic Clarity** (dragPath.ts line 89-94)
   - Added explicit comments explaining sortable determination
   - Fixed edge case where nextItem could be undefined
   - Made the boolean logic more readable and maintainable

2. **Type Coercion Bug** (dropPath.ts lines 43-48, 67-70)
   - Removed dangerous 'boolean && number' pattern that caused false to coerce to 0
   - Added explicit validation to reject drops on non-sortable spaces
   - Users now receive clear feedback when dropping in unsorted folders
   - Prevents silent failures and unexpected behavior

3. **Optimistic UI Updates** (SpaceTreeView.tsx lines 196-252, 614-657)
   - Implemented optimistic rendering to update UI immediately on drop
   - Prevents the 'snap-back' visual glitch users experienced
   - Added rollback mechanism if database write fails
   - Preserved previous tree state for calculations to avoid race conditions
   - Significantly improves perceived performance and user experience

**Technical Details:**

- The snap-back occurred because the UI reset immediately while the async
  database write was queued, leaving users looking at stale data
- Type coercion bug allowed invalid index values (false = 0) to be passed
  to reordering functions, causing items to jump to unexpected positions
- Optimistic updates now provide instant visual feedback while the actual
  database operations complete in the background

**Testing Notes:**

- Manual drag-drop reordering should now feel instant and responsive
- Dropping into non-manually-sorted folders shows appropriate error message
- Failed reorders will rollback to previous state with notification
- Multiple rapid reorders are handled more gracefully
@acjnn acjnn force-pushed the fix/drag-drop-reordering-issues branch 2 times, most recently from 3b66fd3 to 77c1951 Compare November 12, 2025 14:23
@jp-cen
Copy link
Contributor

jp-cen commented Nov 12, 2025

Thanks for the effort into fixing this. I'm aware of the issue and it's prioritized into the next version. There are some good suggestions that were added here like optimistic reordering so the UI looks smoother, but the underlying issue with the ordering not saving is more related to a data refresh issue due to some other optimizations that were made recently.

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.

2 participants