Skip to content

Commit 1add4ca

Browse files
Apply suggestion from @gemini-code-assist[bot]
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent c192f00 commit 1add4ca

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

packages/agentflow/src/infrastructure/store/AgentflowContext.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ export function AgentflowStateProvider({ children, initialFlow }: AgentflowState
6767

6868
// Helper function to generate unique copy IDs
6969
const getUniqueCopyId = useCallback((baseId: string, nodes: FlowNode[]): string => {
70+
const existingIds = new Set(nodes.map((node) => node.id))
7071
let i = 1
71-
let newId: string
72-
do {
73-
newId = `${baseId}_copy_${i}`
72+
while (true) {
73+
const newId = `${baseId}_copy_${i}`
74+
if (!existingIds.has(newId)) {
75+
return newId
76+
}
7477
i++
75-
} while (nodes.some((node) => node.id === newId))
76-
return newId
78+
}
7779
}, [])
7880

7981
// Helper function to synchronize state updates between context and ReactFlow

0 commit comments

Comments
 (0)