From f686197589fcd2897dd04795c4711b4db6c3e7ea Mon Sep 17 00:00:00 2001 From: wangxiaolei Date: Wed, 4 Feb 2026 19:32:36 +0800 Subject: [PATCH] feat: use latest hash to sync draft (#31924) --- .../hooks/use-nodes-sync-draft.ts | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) 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 5d394bab1e..f3538a5abb 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?.() + // 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 + }, } - 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?.() + + 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])