From fc93a30843e7755dd22c7638ea1edd0c79c0c330 Mon Sep 17 00:00:00 2001 From: Adam Gough Date: Fri, 30 May 2025 11:56:11 -0700 Subject: [PATCH] fix: added robust subblock status change --- .../hooks/use-deployment-change-detection.ts | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/sim/app/w/[id]/hooks/use-deployment-change-detection.ts b/apps/sim/app/w/[id]/hooks/use-deployment-change-detection.ts index 8adb8dcf3c..2f079729bb 100644 --- a/apps/sim/app/w/[id]/hooks/use-deployment-change-detection.ts +++ b/apps/sim/app/w/[id]/hooks/use-deployment-change-detection.ts @@ -41,6 +41,11 @@ export function useDeploymentChangeDetection(activeWorkflowId: string | null, is logger.debug(`Checking for changes in workflow ${requestedWorkflowId}`) try { + // Force immediate sync to ensure database has the latest subBlock values + // This is important because subBlock changes have a debounced sync delay + const { workflowSync } = await import('@/stores/workflows/sync') + await workflowSync.sync() + // Get the deployed state from the API const response = await fetch(`/api/workflows/${requestedWorkflowId}/status`) if (response.ok) { @@ -121,31 +126,18 @@ export function useDeploymentChangeDetection(activeWorkflowId: string | null, is // Subscribe to workflow store changes const workflowUnsubscribe = useWorkflowStore.subscribe(debouncedCheck) - // Also subscribe to subblock store changes - const subBlockUnsubscribe = useSubBlockStore.subscribe((state) => { - // Only check for the active workflow when it's deployed - if (!activeWorkflowId || !isDeployed) return - - // Skip if the workflow ID has changed since this effect started - if (effectWorkflowId !== activeWorkflowId) { - return - } - - // Only trigger when there is an update to the current workflow's subblocks - const workflowSubBlocks = state.workflowValues[effectWorkflowId] - if (workflowSubBlocks && Object.keys(workflowSubBlocks).length > 0) { - debouncedCheck() - } - }) + // Subscribe to subBlock store changes to detect subBlock value changes + const subBlockUnsubscribe = useSubBlockStore.subscribe(debouncedCheck) + // Cleanup function return () => { + workflowUnsubscribe() + subBlockUnsubscribe() if (debounceTimer) { clearTimeout(debounceTimer) } - workflowUnsubscribe() - subBlockUnsubscribe() } - }, [activeWorkflowId, isDeployed, needsRedeployment]) + }, [activeWorkflowId, isDeployed]) // Initial check on mount or when active workflow changes useEffect(() => {