Commit 77c1951
committed
fix(navigator): resolve drag-drop reordering snap-back and validation issues
Fixes #443, #408, #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 gracefully1 parent 1929944 commit 77c1951
3 files changed
+117
-9
lines changedLines changed: 94 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
192 | 254 | | |
193 | 255 | | |
194 | 256 | | |
| |||
613 | 675 | | |
614 | 676 | | |
615 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
616 | 702 | | |
617 | 703 | | |
618 | 704 | | |
619 | 705 | | |
620 | 706 | | |
621 | 707 | | |
622 | | - | |
| 708 | + | |
623 | 709 | | |
624 | 710 | | |
625 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
626 | 718 | | |
627 | 719 | | |
628 | 720 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | 40 | | |
43 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
60 | 72 | | |
61 | | - | |
62 | | - | |
| 73 | + | |
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
66 | 77 | | |
67 | 78 | | |
68 | 79 | | |
69 | | - | |
| 80 | + | |
70 | 81 | | |
71 | 82 | | |
72 | 83 | | |
| |||
0 commit comments