sim
sim copied to clipboard
fix(naming): client-side unique duplicate names for blocks
Summary
Implements client-side unique name generation for duplicated blocks, standardizing to "<Base> N" and preventing normalized collisions within a workflow. This keeps resolver/store normalization rules in sync and avoids server-side changes.
Why
- Avoids confusing name collisions after duplicate, especially across variants that normalize equal (e.g., "My Agent" vs "myagent").
- Ensures consistent UX across both duplicate entry points (collaborative and local store) with a single source of truth.
- Honors product decision to rely on client-side uniqueness only; server behavior unchanged.
Changes
- Added helper at
apps/sim/lib/naming.ts:-
normalizeBlockName(name)– lowercase + strip spaces (parity with resolver/store). -
generateUniqueBlockDuplicateName(existingNames, sourceName)– produces "Base N"; starts at suffix+1 when source ends with whitespace+digits, otherwise 1; loops until normalized-unique.
-
-
hooks/use-collaborative-workflow.ts→collaborativeDuplicateBlocknow uses the helper with current workflow block names. -
stores/workflows/workflow/store.ts→duplicateBlocknow uses the helper. -
updateBlockNamein store now imports the sharednormalizeBlockNameto avoid drift. - Tests:
apps/sim/lib/naming.test.tscovering base/suffix cases, normalization collisions, gaps, whitespace-heavy names, mixed case, and empty names.
Impact
- Client-only change; server endpoints and duplication behavior remain unchanged.
- Rename validation continues to prevent normalized collisions; no regressions expected.
QA
- Create blocks: "Agent", "Agent 1". Duplicate "Agent" → expect "Agent 2".
- Create "Agent 3". Duplicate "Agent 2" → expect "Agent 4".
- Create "agent1" (if allowed). Duplicate "Agent" → should skip to next free beyond normalized collisions.
- Names with multiple spaces: "My Agent" duplicates to "My Agent 1"; if a normalized collision exists, increments accordingly.
Notes
- No server behavior changed; resolver normalization remains the source of truth we mirrored.
- Keeps naming behavior consistent whether duplication originates locally or via collaboration.