Skip to content

Commit d8ad8a4

Browse files
committed
fix(mothership): guard sendNow against double-click duplicate sends
1 parent 3f17446 commit d8ad8a4

File tree

1 file changed

+10
-3
lines changed
  • apps/sim/app/workspace/[workspaceId]/home/hooks

1 file changed

+10
-3
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,20 @@ export function useChat(
10061006
[setMessageQueue]
10071007
)
10081008

1009+
const sendNowProcessingRef = useRef<string | null>(null)
10091010
const sendNow = useCallback(
10101011
async (id: string) => {
1012+
if (sendNowProcessingRef.current === id) return
10111013
const msg = messageQueueRef.current.find((m) => m.id === id)
10121014
if (!msg) return
1013-
await stopGeneration()
1014-
setMessageQueue((prev) => prev.filter((m) => m.id !== id))
1015-
await sendMessage(msg.content, msg.fileAttachments, msg.contexts)
1015+
sendNowProcessingRef.current = id
1016+
try {
1017+
await stopGeneration()
1018+
setMessageQueue((prev) => prev.filter((m) => m.id !== id))
1019+
await sendMessage(msg.content, msg.fileAttachments, msg.contexts)
1020+
} finally {
1021+
sendNowProcessingRef.current = null
1022+
}
10161023
},
10171024
[stopGeneration, sendMessage, setMessageQueue]
10181025
)

0 commit comments

Comments
 (0)