Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

On duplicating trigger block should not point at old webhook row.

Type of Change

  • Bug fix

Testing

Tested manually with @waleedlatif1

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Nov 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 1, 2025 2:09am

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Fixed a bug where duplicating trigger blocks would cause the duplicate to reference the original webhook database row, leading to incorrect webhook associations.

The fix introduces a constant WEBHOOK_SUBBLOCK_FIELDS containing ['webhookId', 'triggerPath'] and filters these fields out in three key locations:

  • Duplication flow (use-collaborative-workflow.ts): Excludes webhook fields when creating duplicate block payload and merging subblock values
  • Collaborative operations (use-collaborative-workflow.ts): Prevents webhook fields from being applied when receiving 'add' and 'duplicate' socket operations
  • State merging (utils.ts, server-utils.ts): Skips webhook fields in both client and server-side merge operations

This ensures duplicated trigger blocks generate new webhooks instead of pointing to the original block's webhook.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is surgical and targeted - it consistently excludes webhook-specific fields across all relevant code paths using a well-defined constant. The implementation is defensive (using includes() checks) and follows the existing patterns in the codebase. The changes were manually tested and don't introduce any breaking changes to existing functionality.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/hooks/use-collaborative-workflow.ts 5/5 Added filtering logic to exclude webhookId and triggerPath fields when duplicating blocks and applying subblock values, preventing duplicated trigger blocks from referencing the original webhook
apps/sim/stores/workflows/server-utils.ts 5/5 Added webhook field exclusion to mergeSubblockState function to prevent webhook-specific fields from being persisted during server-side operations
apps/sim/stores/workflows/utils.ts 5/5 Added webhook field filtering to both sync and async versions of mergeSubblockState, ensuring webhook-specific fields are excluded from state merging operations

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as Workflow UI
    participant Hook as useCollaborativeWorkflow
    participant SubBlockStore
    participant WorkflowStore
    participant Socket as Socket Server

    User->>UI: Duplicate trigger block
    UI->>Hook: duplicateBlock(sourceId)
    
    Note over Hook: Get source block & subblock values
    Hook->>SubBlockStore: Get subblock values for sourceId
    SubBlockStore-->>Hook: All subblock values (including webhookId, triggerPath)
    
    Note over Hook: Filter webhook-specific fields
    Hook->>Hook: Filter out webhookId & triggerPath from subBlockValues
    Hook->>Hook: Delete webhookId & triggerPath from mergedSubBlocks
    
    Note over Hook: Create duplicate with new ID
    Hook->>Socket: Emit 'duplicate' operation
    Socket->>WorkflowStore: Create new block (without webhook fields)
    Socket->>SubBlockStore: Set subblock values (excluding webhook fields)
    
    Note over Socket: Apply subblock values (collaborative)
    Socket->>SubBlockStore: Skip webhookId & triggerPath during setValue
    
    WorkflowStore-->>UI: New block created
    Note over UI: Duplicated block has no webhook reference<br/>New webhook will be created when saved
Loading

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit 86b3570 into staging Nov 1, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/trigger-duplicate-fix branch November 6, 2025 01:25
@waleedlatif1 waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants