@@ -76,6 +76,7 @@ export function useDndPersistedKeys(selectionManager: MultipleSelectionManager,
76
76
if ( dropState . target . dropPosition === 'after' ) {
77
77
// Normalize to the "before" drop position since we only render those to the DOM.
78
78
let nextKey = dropState . collection . getKeyAfter ( dropTargetKey ) ;
79
+ let lastDescendantKey : Key | null = null ;
79
80
if ( nextKey != null ) {
80
81
let targetLevel = dropState . collection . getItem ( dropTargetKey ) ?. level ?? 0 ;
81
82
// Skip over any rows that are descendants of the target ("after" position should be after all children)
@@ -85,16 +86,26 @@ export function useDndPersistedKeys(selectionManager: MultipleSelectionManager,
85
86
if ( ! node ) {
86
87
break ;
87
88
}
88
- // Stop once we find a node at the same level or higher
89
+ // Skip over non-item nodes (e.g., loaders) since they can't be drop targets.
90
+ // eslint-disable-next-line max-depth
91
+ if ( node . type !== 'item' ) {
92
+ nextKey = dropState . collection . getKeyAfter ( nextKey ) ;
93
+ continue ;
94
+ }
95
+
96
+ // Stop once we find an item at the same level or higher
89
97
// eslint-disable-next-line max-depth
90
98
if ( ( node . level ?? 0 ) <= targetLevel ) {
91
99
break ;
92
100
}
101
+
102
+ lastDescendantKey = nextKey ;
93
103
nextKey = dropState . collection . getKeyAfter ( nextKey ) ;
94
104
}
95
105
}
96
106
97
- dropTargetKey = nextKey ?? dropTargetKey ;
107
+ // If nextKey is null (end of collection), use the last descendant
108
+ dropTargetKey = nextKey ?? lastDescendantKey ?? dropTargetKey ;
98
109
}
99
110
}
100
111
0 commit comments