diff --git a/lib/shared/dm-ops/dm-ops-queue-handler.react.js b/lib/shared/dm-ops/dm-ops-queue-handler.react.js --- a/lib/shared/dm-ops/dm-ops-queue-handler.react.js +++ b/lib/shared/dm-ops/dm-ops-queue-handler.react.js @@ -122,20 +122,25 @@ }, [dispatch, enqueue, queuedThreadOperations, threadInfos]); const messageInfos = useSelector(messageInfoSelector); - const prevMessageInfosRef = React.useRef({}); const queuedMessageOperations = useSelector( state => state.queuedDMOperations.messageQueue, ); - React.useEffect(() => { - const prevMessageInfos = prevMessageInfosRef.current; - prevMessageInfosRef.current = messageInfos; + const runningMessageOperations = React.useRef>(new Set()); + React.useEffect(() => { for (const messageID in queuedMessageOperations) { - if (!messageInfos[messageID] || prevMessageInfos[messageID]) { + if (!messageInfos[messageID]) { + continue; + } + + if (runningMessageOperations.current.has(messageID)) { continue; } + + runningMessageOperations.current.add(messageID); + enqueue([ ...queuedMessageOperations[messageID].map(item => ({ type: 'operation', @@ -150,6 +155,11 @@ }, }, }, + { + type: 'function', + itemFunction: () => + runningMessageOperations.current.delete(messageID), + }, ]); } }, [dispatch, enqueue, messageInfos, queuedMessageOperations]);