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.

feat: use latest hash to sync draft (#31924)

wangxiaoleif686197589fc
diff --git a/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts b/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts
index 5d394bab1e3..f3538a5abbf 100644
--- a/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts
+++ b/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts
@@ -98,31 +98,46 @@ export const useNodesSyncDraft = () => {
) => {
if (getNodesReadOnly())
return
- const postParams = getPostParams()
- if (postParams) {
- const {
- setSyncWorkflowDraftHash,
- setDraftUpdatedAt,
- } = workflowStore.getState()
- try {
- const res = await syncWorkflowDraft(postParams)
- setSyncWorkflowDraftHash(res.hash)
- setDraftUpdatedAt(res.updated_at)
- callback?.onSuccess?.()
- }
- catch (error: any) {
- if (error && error.json && !error.bodyUsed) {
- error.json().then((err: any) => {
- if (err.code === 'draft_workflow_not_sync' && !notRefreshWhenSyncError)
- handleRefreshWorkflowDraft()
- })
- }
- callback?.onError?.()
+ // Get base params without hash
+ const baseParams = getPostParams()
+ if (!baseParams)
+ return
+
+ const {
+ setSyncWorkflowDraftHash,
+ setDraftUpdatedAt,
+ } = workflowStore.getState()
+
+ try {
+ // IMPORTANT: Get the LATEST hash right before sending the request
+ // This ensures that even if queued, each request uses the most recent hash
+ const latestHash = workflowStore.getState().syncWorkflowDraftHash
+
+ const postParams = {
+ ...baseParams,
+ params: {
+ ...baseParams.params,
+ hash: latestHash || null, // null for first-time, otherwise use latest hash
+ },
}
- finally {
- callback?.onSettled?.()
+
+ const res = await syncWorkflowDraft(postParams)
+ setSyncWorkflowDraftHash(res.hash)
+ setDraftUpdatedAt(res.updated_at)
+ callback?.onSuccess?.()
+ }
+ catch (error: any) {
+ if (error && error.json && !error.bodyUsed) {
+ error.json().then((err: any) => {
+ if (err.code === 'draft_workflow_not_sync' && !notRefreshWhenSyncError)
+ handleRefreshWorkflowDraft()
+ })
}
+ callback?.onError?.()
+ }
+ finally {
+ callback?.onSettled?.()
}
}, [workflowStore, getPostParams, getNodesReadOnly, handleRefreshWorkflowDraft])