feat(naming): client-side unique duplicate names for blocks (standard '<Base> N', normalized collision-safe)#1302
Conversation
… normalized comparison; unify client naming via shared helper and wire into duplicate flows; keep server unchanged Co-authored-by: Capy <capy@capy.ai>
There was a problem hiding this comment.
Greptile Summary
This PR implements a client-side unique name generation system for duplicated workflow blocks, addressing confusing name collisions that can occur when different block names normalize to the same value (e.g., "My Agent" vs "myagent"). The changes introduce a centralized naming utility that standardizes duplicate naming to the pattern " N" and prevents normalized collisions within workflows.
The core implementation adds a new utility library at apps/sim/lib/naming.ts containing two key functions: normalizeBlockName() which performs lowercase conversion and space removal (mirroring server-side resolver logic), and generateUniqueBlockDuplicateName() which generates collision-safe duplicate names by checking against normalized existing names. This utility is integrated into both the collaborative workflow hook (use-collaborative-workflow.ts) and the local workflow store (store.ts), replacing previous regex-based approaches with a more robust solution.
The implementation ensures consistency across both duplication pathways (collaborative real-time and local store operations) by providing a single source of truth for naming logic. The updateBlockName function in the store also adopts the shared normalization function to maintain consistency. The changes are thoroughly tested with comprehensive coverage for various edge cases including whitespace handling, gap filling in numbering sequences, normalized collisions, and fallback scenarios.
This solution honors the product decision to handle uniqueness client-side only, avoiding server-side changes while maintaining synchronization with server-side normalization rules. The standardized naming approach provides predictable user experience and prevents the confusion that could arise from visually different names that would conflict after normalization.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it implements well-tested client-side improvements without affecting server behavior
- Score reflects thorough testing coverage and clear separation of concerns, though the complex normalization logic requires careful attention
- Pay close attention to the naming utility functions in
apps/sim/lib/naming.tsand their integration points in the workflow stores
4 files reviewed, 1 comment
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