fix(triggers): fix triggers in subflows#1883
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile OverviewGreptile SummaryPrevents triggers from being added to loop or parallel subflows through multiple validation layers. Key Changes:
Notes:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Toolbar/Drop
participant Workflow.tsx
participant Store/Hook
participant TriggerUtils
participant Dialog
Note over User,Dialog: Scenario 1: Drop trigger into container
User->>Workflow.tsx: Drop block into container
Workflow.tsx->>Workflow.tsx: Check if containerInfo exists
Workflow.tsx->>Workflow.tsx: Check if block is trigger<br/>(category='triggers' OR triggers.enabled OR enableTriggerMode)
alt Is trigger block
Workflow.tsx->>TriggerUtils: getDefaultTriggerName(type)
TriggerUtils-->>Workflow.tsx: Return trigger name
Workflow.tsx->>Dialog: Show TRIGGER_IN_SUBFLOW warning
Dialog-->>User: Display "Triggers not allowed in subflows"
Note over Workflow.tsx: Early return - block not added
else Not trigger block
Workflow.tsx->>Workflow.tsx: Add block to container
end
Note over User,Dialog: Scenario 2: Drag existing trigger into container
User->>Workflow.tsx: Drag block over container
Workflow.tsx->>Workflow.tsx: onNodeDragStop with potentialParentId
Workflow.tsx->>Workflow.tsx: Get block from blocks[node.id]
Workflow.tsx->>TriggerUtils: isTriggerBlock(block)
TriggerUtils-->>Workflow.tsx: true/false
alt Is trigger block
Workflow.tsx->>TriggerUtils: getDefaultTriggerName(block.type)
TriggerUtils-->>Workflow.tsx: Return trigger name
Workflow.tsx->>Dialog: Show TRIGGER_IN_SUBFLOW warning
Dialog-->>User: Display "Triggers not allowed in subflows"
Workflow.tsx->>Workflow.tsx: Reset drag state (no parent update)
else Not trigger block
Workflow.tsx->>Workflow.tsx: Update parent relationship
end
Note over User,Dialog: Scenario 3: Toggle trigger mode on block in subflow
User->>Store/Hook: Toggle trigger mode
Store/Hook->>Store/Hook: Check if newTriggerMode is true
Store/Hook->>Store/Hook: Check if block.data.parentId exists
Store/Hook->>Store/Hook: Get parent block
alt Parent is loop or parallel
Store/Hook->>Store/Hook: Log warning (store only)
alt In collaborative hook
Store/Hook->>Workflow.tsx: Dispatch 'show-trigger-warning' event
Workflow.tsx->>Dialog: Show TRIGGER_IN_SUBFLOW warning
Dialog-->>User: Display "Triggers not allowed in subflows"
end
Note over Store/Hook: Early return - mode not changed
else Parent not loop/parallel or no parent
Store/Hook->>Store/Hook: Toggle trigger mode
Store/Hook->>Store/Hook: Remove incoming edges if enabling
end
|
Comment on lines
+574
to
+594
| static isBlockInSubflow<T extends { id: string; data?: { parentId?: string } }>( | ||
| blockId: string, | ||
| blocks: T[] | Record<string, T> | ||
| ): boolean { | ||
| const blockArray = Array.isArray(blocks) ? blocks : Object.values(blocks) | ||
| const block = blockArray.find((b) => b.id === blockId) | ||
|
|
||
| if (!block || !block.data?.parentId) { | ||
| return false | ||
| } | ||
|
|
||
| // Check if the parent is a loop or parallel block | ||
| const parent = blockArray.find((b) => b.id === block.data?.parentId) | ||
| if (!parent) { | ||
| return false | ||
| } | ||
|
|
||
| // Type-safe check: parent must have a 'type' property | ||
| const parentWithType = parent as T & { type?: string } | ||
| return parentWithType.type === 'loop' || parentWithType.type === 'parallel' | ||
| } |
Contributor
There was a problem hiding this comment.
style: Unused utility - isBlockInSubflow is never called. The same logic is duplicated inline in use-collaborative-workflow.ts:977 and store.ts:1057. Consider either using this utility or removing it to reduce code duplication.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/workflows/triggers.ts
Line: 574:594
Comment:
**style:** Unused utility - `isBlockInSubflow` is never called. The same logic is duplicated inline in `use-collaborative-workflow.ts:977` and `store.ts:1057`. Consider either using this utility or removing it to reduce code duplication.
How can I resolve this? If you propose a fix, please make it concise.
waleedlatif1
pushed a commit
that referenced
this pull request
Nov 12, 2025
waleedlatif1
pushed a commit
that referenced
this pull request
Nov 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents adding triggers to subflows
Type of Change
Testing
Manual
Checklist