-
Notifications
You must be signed in to change notification settings - Fork 3.3k
improvement(workflow): remove useEffect anti-patterns #3030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR refactors React patterns by removing unnecessary Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant WorkflowUI as Workflow Component
participant Store as Workflow Store
participant Blocks as Block State
Note over WorkflowUI,Store: useEffect Anti-pattern Removal
User->>WorkflowUI: Delete blocks (batchRemoveBlocks)
WorkflowUI->>Store: batchRemoveBlocks(blockIds)
Note over Store: OLD: orphan cleanup in useEffect
Note over Store: NEW: orphan cleanup in batchRemoveBlocks
Store->>Store: Remove blocks and descendants
Store->>Store: Filter edges connected to removed blocks
rect rgb(240, 240, 255)
Note over Store: Orphan Cleanup Logic
Store->>Store: Check remaining blocks for invalid parentId
Store->>Blocks: Look up parent in currentBlocks
Store->>Store: Calculate absolute position with container offsets
Store->>Store: Clear parentId and extent properties
end
Store->>Blocks: Update blocks state
Store-->>WorkflowUI: State updated
Note over WorkflowUI: Ref Sync Pattern Improvement
User->>WorkflowUI: Toggle auto-connect
WorkflowUI->>WorkflowUI: autoConnectRef.current = isAutoConnectEnabled (during render)
Note over WorkflowUI: OLD: useEffect to sync ref<br/>NEW: direct assignment during render
Note over WorkflowUI: Diff Blocks Ref Pattern
WorkflowUI->>WorkflowUI: blocks state changes
WorkflowUI->>WorkflowUI: Check if blocks !== diffBlocksRef.current
WorkflowUI->>WorkflowUI: Update diffBlocksRef.current = blocks
alt blocks changed AND hasActiveDiff
WorkflowUI->>WorkflowUI: reapplyDiffMarkers()
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
|
@greptile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
Remove redundant functions superseded by collaborative workflow patterns: - duplicateBlock (superseded by collaborative paste flow) - toggleBlockAdvancedMode (superseded by setBlockAdvancedMode) - updateLoopCollection (redundant wrapper) - setBlockTriggerMode (unused) - generateLoopBlocks/generateParallelBlocks methods (called directly as utils) Also removes ~160 lines of related tests and cleans up unused imports.
When a block's parent is removed, properly clear both parentId and extent properties from block.data, matching the pattern used in batchUpdateBlocksWithParent.
…nested blocks Three related fixes for blocks inside containers (loop/parallel): 1. regenerateBlockIds now preserves parentId when the parent exists in the current workflow, not just when it's in the copy set. This keeps duplicated blocks inside their container. 2. calculatePasteOffset now uses simple offset for nested blocks instead of viewport-center calculation. Since nested blocks use relative positioning, the viewport-center offset would place them incorrectly. 3. Use CONTAINER_DIMENSIONS constants instead of hardcoded magic numbers in orphan cleanup position calculation.
|
@greptile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Outdated
Show resolved
Hide resolved
|
@greptile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Line: 2323:2323
Comment:
`syncPanelWithSelection` is used inside the callback but not included in the dependency array
```suggestion
[blocks, syncPanelWithSelection]
```
How can I resolve this? If you propose a fix, please make it concise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| } else { | ||
| nextBlocks[id] = block | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orphan cleanup in replaceWorkflowState doesn't convert position
Medium Severity
The newly added orphan handling in replaceWorkflowState clears parentId for blocks whose parent doesn't exist in the incoming state, but doesn't convert the position from relative to absolute. Child blocks store positions relative to their parent container (with header and padding offsets). When parentId is cleared without updating the position, the block appears at its relative position interpreted as an absolute position, causing it to display in the wrong location on the canvas. Compare with batchRemoveBlocks (lines 455-480) which correctly calculates absolute position by traversing the parent chain.
| WorkflowBuilder, | ||
| } from '@sim/testing' | ||
| import { beforeEach, describe, expect, it } from 'vitest' | ||
| import { useWorkflowRegistry } from '@/stores/workflows/registry/store' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test file documentation no longer matches test coverage
Low Severity
The header comment claims tests cover "Block operations (add, remove, duplicate, update)" and "Mode switching (basic/advanced)", but the tests for duplicateBlock, toggleBlockAdvancedMode, and the mode switching section were removed in this PR. The documentation no longer accurately describes the test coverage.
Summary
Type of Change
Testing
Tested manually - copy/paste, delete blocks, diff view
Checklist