Skip to content

Commit 2fa20f9

Browse files
committed
fix(deploy): clean up self-explanatory comments and fix unstable mutation dep
- Remove self-explanatory comments in deploy.tsx, tool-input.tsx, use-child-workflow.ts - Tighten non-obvious comments in use-change-detection.ts - Destructure mutate/isPending in WorkflowToolDeployBadge to avoid unstable mutation object in useCallback deps (TanStack Query no-unstable-deps pattern)
1 parent b6a2255 commit 2fa20f9

File tree

4 files changed

+9
-38
lines changed

4 files changed

+9
-38
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/deploy.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ interface DeployProps {
1919
className?: string
2020
}
2121

22-
/**
23-
* Deploy component that handles workflow deployment
24-
* Manages deployed state, change detection, and deployment operations
25-
*/
2622
export function Deploy({ activeWorkflowId, userPermissions, className }: DeployProps) {
2723
const [isModalOpen, setIsModalOpen] = useState(false)
2824
const hydrationPhase = useWorkflowRegistry((state) => state.hydration.phase)
@@ -32,7 +28,6 @@ export function Deploy({ activeWorkflowId, userPermissions, className }: DeployP
3228
hydrationPhase === 'state-loading'
3329
const { hasBlocks } = useCurrentWorkflow()
3430

35-
// Get deployment status from registry
3631
const deploymentStatus = useWorkflowRegistry((state) =>
3732
state.getWorkflowDeploymentStatus(activeWorkflowId)
3833
)
@@ -44,7 +39,6 @@ export function Deploy({ activeWorkflowId, userPermissions, className }: DeployP
4439
{ enabled: isDeployed && !isRegistryLoading }
4540
)
4641

47-
// Fetch deployed state snapshot for change detection and modal
4842
const isDeployedStateEnabled = Boolean(activeWorkflowId) && isDeployed && !isRegistryLoading
4943
const { data: deployedStateData, isLoading: isLoadingDeployedState } = useDeployedWorkflowState(
5044
activeWorkflowId,
@@ -60,7 +54,6 @@ export function Deploy({ activeWorkflowId, userPermissions, className }: DeployP
6054
isServerLoading: isLoadingDeploymentInfo,
6155
})
6256

63-
// Handle deployment operations
6457
const { isDeploying, handleDeployClick } = useDeployment({
6558
workflowId: activeWorkflowId,
6659
isDeployed,
@@ -79,9 +72,6 @@ export function Deploy({ activeWorkflowId, userPermissions, className }: DeployP
7972
}
8073
}
8174

82-
/**
83-
* Get tooltip text based on current state
84-
*/
8575
const getTooltipText = () => {
8676
if (isEmpty) {
8777
return 'Cannot deploy an empty workflow'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks/use-change-detection.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ export function useChangeDetection({
5555
return vars
5656
}, [workflowId, allVariables])
5757

58-
// Track initial lastSaved to detect saves after load.
59-
// Debounced to avoid redundant API calls during rapid auto-saves.
58+
// Tracks the lastSaved timestamp at mount to distinguish real saves from initial hydration.
6059
const initialLastSavedRef = useRef<number | undefined>(undefined)
6160
const workflowIdRef = useRef(workflowId)
6261

63-
// Reset tracking when workflow changes — must run before the lastSaved effect
64-
// to prevent spurious invalidation with a stale ref during workflow switches.
62+
// Must run before the lastSaved effect to prevent stale-ref invalidation on workflow switch.
6563
useEffect(() => {
6664
workflowIdRef.current = workflowId
6765
initialLastSavedRef.current = undefined

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ import {
5353
type CustomTool as CustomToolDefinition,
5454
useCustomTools,
5555
} from '@/hooks/queries/custom-tools'
56+
import { useDeploymentInfo, useDeployWorkflow } from '@/hooks/queries/deployments'
5657
import {
5758
useForceRefreshMcpTools,
5859
useMcpServers,
5960
useMcpToolsEvents,
6061
useStoredMcpTools,
6162
} from '@/hooks/queries/mcp'
62-
import { useDeploymentInfo, useDeployWorkflow } from '@/hooks/queries/deployments'
6363
import { useWorkflowState, useWorkflows } from '@/hooks/queries/workflows'
6464
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
6565
import { usePermissionConfig } from '@/hooks/use-permission-config'
@@ -196,9 +196,6 @@ function WorkflowInputMapperInput({
196196
)
197197
}
198198

199-
/**
200-
* Badge component showing deployment status for workflow tools
201-
*/
202199
function WorkflowToolDeployBadge({
203200
workflowId,
204201
onDeploySuccess,
@@ -207,25 +204,24 @@ function WorkflowToolDeployBadge({
207204
onDeploySuccess?: () => void
208205
}) {
209206
const { data, isLoading } = useDeploymentInfo(workflowId)
210-
const deployMutation = useDeployWorkflow()
207+
const { mutate, isPending: isDeploying } = useDeployWorkflow()
211208
const userPermissions = useUserPermissionsContext()
212209

213210
const isDeployed = data?.isDeployed ?? null
214211
const needsRedeploy = data?.needsRedeployment ?? false
215-
const isDeploying = deployMutation.isPending
216212

217213
const deployWorkflow = useCallback(() => {
218214
if (isDeploying || !workflowId || !userPermissions.canAdmin) return
219215

220-
deployMutation.mutate(
216+
mutate(
221217
{ workflowId },
222218
{
223219
onSuccess: () => {
224220
onDeploySuccess?.()
225221
},
226222
}
227223
)
228-
}, [isDeploying, workflowId, userPermissions.canAdmin, deployMutation, onDeploySuccess])
224+
}, [isDeploying, workflowId, userPermissions.canAdmin, mutate, onDeploySuccess])
229225

230226
if (isLoading || (isDeployed && !needsRedeploy)) {
231227
return null

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-child-workflow.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,17 @@ import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/c
22
import type { WorkflowBlockProps } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/types'
33
import { useDeploymentInfo } from '@/hooks/queries/deployments'
44

5-
/**
6-
* Return type for the useChildWorkflow hook
7-
*/
85
export interface UseChildWorkflowReturn {
9-
/** The ID of the child workflow if configured */
106
childWorkflowId: string | undefined
11-
/** Whether the child workflow is deployed */
127
childIsDeployed: boolean | null
13-
/** Whether the child workflow needs redeployment due to changes */
148
childNeedsRedeploy: boolean
15-
/** Whether the child deployment info is loading */
169
isLoadingChildVersion: boolean
1710
}
1811

1912
/**
20-
* Custom hook for managing child workflow information for workflow selector blocks.
21-
* Uses the shared useDeploymentInfo query — the same source of truth as the
22-
* editor header's Deploy button — for consistent deployment status detection.
23-
*
24-
* @param blockId - The ID of the block
25-
* @param blockType - The type of the block
26-
* @param isPreview - Whether the block is in preview mode
27-
* @param previewSubBlockValues - The subblock values in preview mode
28-
* @returns Child workflow configuration and deployment status
13+
* Manages child workflow deployment status for workflow selector blocks.
14+
* Uses the shared useDeploymentInfo query (same source of truth as the
15+
* editor header's Deploy button) for consistent deployment detection.
2916
*/
3017
export function useChildWorkflow(
3118
blockId: string,

0 commit comments

Comments
 (0)