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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 37 additions and 22 deletions

View File

@ -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])