Skip to content

Commit c6f0195

Browse files
committed
fix(tasks): guard handleNewTask against concurrent calls via ref lock
1 parent 57ca584 commit c6f0195

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ export const Sidebar = memo(function Sidebar() {
586586
}, [activeNavItemHref])
587587

588588
const createTaskMutation = useCreateTask(workspaceId)
589+
const isCreatingTaskRef = useRef(false)
589590
const deleteTaskMutation = useDeleteTask(workspaceId)
590591
const deleteTasksMutation = useDeleteTasks(workspaceId)
591592
const markTaskReadMutation = useMarkTaskRead(workspaceId)
@@ -1161,13 +1162,16 @@ export const Sidebar = memo(function Sidebar() {
11611162
}
11621163

11631164
const handleNewTask = useCallback(async () => {
1164-
if (!workspaceId) return
1165+
if (!workspaceId || isCreatingTaskRef.current) return
1166+
isCreatingTaskRef.current = true
11651167
try {
11661168
const { id } = await createTaskMutation.mutateAsync()
11671169
useMothershipDraftsStore.getState().clearDraft(`${workspaceId}:new`)
11681170
navigateToPage(`/workspace/${workspaceId}/task/${id}`)
11691171
} catch {
11701172
navigateToPage(`/workspace/${workspaceId}/home`)
1173+
} finally {
1174+
isCreatingTaskRef.current = false
11711175
}
11721176
}, [workspaceId, navigateToPage])
11731177

0 commit comments

Comments
 (0)