From d7509e6cddc1ae9bb4298bdddb2177635a001937 Mon Sep 17 00:00:00 2001 From: wangxiaolei Date: Thu, 22 Jan 2026 11:13:14 +0800 Subject: [PATCH] fix: fix visibilityState event handle (#31354) --- web/app/components/workflow/index.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/index.tsx b/web/app/components/workflow/index.tsx index 1543bce714..62516a797d 100644 --- a/web/app/components/workflow/index.tsx +++ b/web/app/components/workflow/index.tsx @@ -95,6 +95,7 @@ import { import SyncingDataModal from './syncing-data-modal' import { ControlMode, + WorkflowRunningStatus, } from './types' import { setupScrollToNodeListener } from './utils/node-navigation' import { WorkflowHistoryProvider } from './workflow-history-store' @@ -231,11 +232,20 @@ export const Workflow: FC = memo(({ const { handleRefreshWorkflowDraft } = useWorkflowRefreshDraft() const handleSyncWorkflowDraftWhenPageClose = useCallback(() => { - if (document.visibilityState === 'hidden') + if (document.visibilityState === 'hidden') { syncWorkflowDraftWhenPageClose() + return + } + + if (document.visibilityState === 'visible') { + const { isListening, workflowRunningData } = workflowStore.getState() + const status = workflowRunningData?.result?.status + // Avoid resetting UI state when user comes back while a run is active or listening for triggers + if (isListening || status === WorkflowRunningStatus.Running) + return - else if (document.visibilityState === 'visible') setTimeout(() => handleRefreshWorkflowDraft(), 500) + } }, [syncWorkflowDraftWhenPageClose, handleRefreshWorkflowDraft, workflowStore]) // Also add beforeunload handler as additional safety net for tab close