fix: pending drag effect calls stale handleSectionItemDragStart
The useEffect with [] deps captured handleSectionItemDragStart from initial render, which read an empty selectedItemIds. Added handleSectionItemDragStartRef that stays current across renders; the effect calls ref.current instead of the closure.
This commit is contained in:
@@ -6948,6 +6948,7 @@ const App = () => {
|
||||
const sweepTrackIdRef = useRef(null);
|
||||
const sweepSelectRef = useRef(null);
|
||||
const pendingDragRef = useRef(null); // { trackId, itemType, itemId, clickOffset, startX, startY }
|
||||
const handleSectionItemDragStartRef = useRef(null);
|
||||
const [localSelectionTrackId, setLocalSelectionTrackId] = useState(null);
|
||||
const [localSelectionStart, setLocalSelectionStart] = useState(null);
|
||||
const [localSelectionEnd, setLocalSelectionEnd] = useState(null);
|
||||
@@ -11758,6 +11759,7 @@ const App = () => {
|
||||
}
|
||||
setDraggedSectionItem({ trackId, itemType, itemId, clickOffset, multiIds });
|
||||
};
|
||||
handleSectionItemDragStartRef.current = handleSectionItemDragStart;
|
||||
|
||||
// ── Section / MIDI Item Resize Start ──
|
||||
const handleSectionItemResizeStart = (trackId, itemType, itemId, side, clickTime) => {
|
||||
@@ -11875,7 +11877,7 @@ const App = () => {
|
||||
var dx = e.clientX - pd.startX;
|
||||
if (Math.abs(dx) > 5) {
|
||||
pendingDragRef.current = null;
|
||||
handleSectionItemDragStart(pd.trackId, pd.itemType, pd.itemId, pd.clickOffset, true);
|
||||
if (handleSectionItemDragStartRef.current) handleSectionItemDragStartRef.current(pd.trackId, pd.itemType, pd.itemId, pd.clickOffset, true);
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousemove', handleMouseMove);
|
||||
|
||||
Reference in New Issue
Block a user