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

This commit is contained in:
wangxiaolei
2026-02-04 19:32:36 +08:00
committed by GitHub
parent f584be9cf0
commit f686197589

View File

@@ -98,31 +98,46 @@ export const useNodesSyncDraft = () => {
) => { ) => {
if (getNodesReadOnly()) if (getNodesReadOnly())
return return
const postParams = getPostParams()
if (postParams) { // Get base params without hash
const { const baseParams = getPostParams()
setSyncWorkflowDraftHash, if (!baseParams)
setDraftUpdatedAt, return
} = workflowStore.getState()
try { const {
const res = await syncWorkflowDraft(postParams) setSyncWorkflowDraftHash,
setSyncWorkflowDraftHash(res.hash) setDraftUpdatedAt,
setDraftUpdatedAt(res.updated_at) } = workflowStore.getState()
callback?.onSuccess?.()
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) { const res = await syncWorkflowDraft(postParams)
error.json().then((err: any) => { setSyncWorkflowDraftHash(res.hash)
if (err.code === 'draft_workflow_not_sync' && !notRefreshWhenSyncError) setDraftUpdatedAt(res.updated_at)
handleRefreshWorkflowDraft() callback?.onSuccess?.()
}) }
} catch (error: any) {
callback?.onError?.() if (error && error.json && !error.bodyUsed) {
} error.json().then((err: any) => {
finally { if (err.code === 'draft_workflow_not_sync' && !notRefreshWhenSyncError)
callback?.onSettled?.() handleRefreshWorkflowDraft()
})
} }
callback?.onError?.()
}
finally {
callback?.onSettled?.()
} }
}, [workflowStore, getPostParams, getNodesReadOnly, handleRefreshWorkflowDraft]) }, [workflowStore, getPostParams, getNodesReadOnly, handleRefreshWorkflowDraft])