Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(deploy): clean up self-explanatory comments and fix unstable muta…
…tion 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)
  • Loading branch information
waleedlatif1 committed Mar 16, 2026
commit 2fa20f9f2fe9e59c22b3f528616d9102a3a2043c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ interface DeployProps {
className?: string
}

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

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

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

// Handle deployment operations
const { isDeploying, handleDeployClick } = useDeployment({
workflowId: activeWorkflowId,
isDeployed,
Expand All @@ -79,9 +72,6 @@ export function Deploy({ activeWorkflowId, userPermissions, className }: DeployP
}
}

/**
* Get tooltip text based on current state
*/
const getTooltipText = () => {
if (isEmpty) {
return 'Cannot deploy an empty workflow'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ export function useChangeDetection({
return vars
}, [workflowId, allVariables])

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

// Reset tracking when workflow changes — must run before the lastSaved effect
// to prevent spurious invalidation with a stale ref during workflow switches.
// Must run before the lastSaved effect to prevent stale-ref invalidation on workflow switch.
useEffect(() => {
workflowIdRef.current = workflowId
initialLastSavedRef.current = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ import {
type CustomTool as CustomToolDefinition,
useCustomTools,
} from '@/hooks/queries/custom-tools'
import { useDeploymentInfo, useDeployWorkflow } from '@/hooks/queries/deployments'
import {
useForceRefreshMcpTools,
useMcpServers,
useMcpToolsEvents,
useStoredMcpTools,
} from '@/hooks/queries/mcp'
import { useDeploymentInfo, useDeployWorkflow } from '@/hooks/queries/deployments'
import { useWorkflowState, useWorkflows } from '@/hooks/queries/workflows'
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
import { usePermissionConfig } from '@/hooks/use-permission-config'
Expand Down Expand Up @@ -196,9 +196,6 @@ function WorkflowInputMapperInput({
)
}

/**
* Badge component showing deployment status for workflow tools
*/
function WorkflowToolDeployBadge({
workflowId,
onDeploySuccess,
Expand All @@ -207,25 +204,24 @@ function WorkflowToolDeployBadge({
onDeploySuccess?: () => void
}) {
const { data, isLoading } = useDeploymentInfo(workflowId)
const deployMutation = useDeployWorkflow()
const { mutate, isPending: isDeploying } = useDeployWorkflow()
const userPermissions = useUserPermissionsContext()

const isDeployed = data?.isDeployed ?? null
const needsRedeploy = data?.needsRedeployment ?? false
const isDeploying = deployMutation.isPending

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

deployMutation.mutate(
mutate(
{ workflowId },
{
onSuccess: () => {
onDeploySuccess?.()
},
}
)
}, [isDeploying, workflowId, userPermissions.canAdmin, deployMutation, onDeploySuccess])
}, [isDeploying, workflowId, userPermissions.canAdmin, mutate, onDeploySuccess])

if (isLoading || (isDeployed && !needsRedeploy)) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@ import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/c
import type { WorkflowBlockProps } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/types'
import { useDeploymentInfo } from '@/hooks/queries/deployments'

/**
* Return type for the useChildWorkflow hook
*/
export interface UseChildWorkflowReturn {
/** The ID of the child workflow if configured */
childWorkflowId: string | undefined
/** Whether the child workflow is deployed */
childIsDeployed: boolean | null
/** Whether the child workflow needs redeployment due to changes */
childNeedsRedeploy: boolean
/** Whether the child deployment info is loading */
isLoadingChildVersion: boolean
}

/**
* Custom hook for managing child workflow information for workflow selector blocks.
* Uses the shared useDeploymentInfo query — the same source of truth as the
* editor header's Deploy button — for consistent deployment status detection.
*
* @param blockId - The ID of the block
* @param blockType - The type of the block
* @param isPreview - Whether the block is in preview mode
* @param previewSubBlockValues - The subblock values in preview mode
* @returns Child workflow configuration and deployment status
* Manages child workflow deployment status for workflow selector blocks.
* Uses the shared useDeploymentInfo query (same source of truth as the
* editor header's Deploy button) for consistent deployment detection.
*/
export function useChildWorkflow(
blockId: string,
Expand Down
Loading