fix(naming): client-side unique duplicate names for blocks#1273
fix(naming): client-side unique duplicate names for blocks#1273waleedlatif1 merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR implements a centralized client-side unique naming system for duplicated workflow blocks. The core change introduces two new utility functions in apps/sim/lib/naming.ts: normalizeBlockName() which converts names to lowercase and removes spaces (mirroring server-side normalization), and generateUniqueBlockDuplicateName() which creates unique names using the standardized " N" format.
The implementation addresses a UX issue where block duplication could create confusing name collisions, particularly when different naming variants normalize to the same string (e.g., "My Agent" vs "myagent"). The solution ensures consistency across both collaborative workflows (use-collaborative-workflow.ts) and local workflows (stores/workflows/workflow/store.ts) by replacing their separate naming logic with the shared utility.
The naming algorithm intelligently handles numeric suffixes - if a source name ends with whitespace and digits, it increments from that number; otherwise it starts from 1. It then loops through candidates until finding one that doesn't create a normalized collision. The updateBlockName function in the workflow store also now uses the shared normalizeBlockName to prevent drift between client and server validation rules.
Comprehensive test coverage validates edge cases including existing numeric suffixes, normalized collisions, gap filling in numbering sequences, whitespace handling, mixed case scenarios, and fallback behavior for empty names. This change maintains the product decision to handle uniqueness client-side only while keeping server behavior unchanged.
Confidence score: 4/5
- This PR is safe to merge with low risk of production issues
- Score reflects well-structured implementation with comprehensive tests, but complexity in naming logic warrants careful review
- Pay close attention to the naming utility functions in
apps/sim/lib/naming.tsfor potential edge cases
4 files reviewed, no comments
…d comparison; unify client naming via shared helper and wire into duplicate flows; keep server unchanged
7959958 to
3be69ab
Compare
Summary
Implements client-side unique name generation for duplicated blocks, standardizing to " N" and preventing normalized collisions within a workflow. This keeps resolver/store normalization rules in sync and avoids server-side changes.
Why
Changes
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.apps/sim/lib/naming.test.tscovering base/suffix cases, normalization collisions, gaps, whitespace-heavy names, mixed case, and empty names.Impact
QA
Notes