Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: fix visibilityState event handle (#31354)

wangxiaolei4e7c1f4f4495
diff --git a/web/app/components/workflow/index.tsx b/web/app/components/workflow/index.tsx
index 1543bce7147..62516a797d9 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<WorkflowProps> = 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