From 250433a91ac63b31942e8cb93c925ad4fe3a2e6a Mon Sep 17 00:00:00 2001 From: AustinMroz Date: Thu, 18 Sep 2025 16:56:49 -0700 Subject: [PATCH] Fix SaveAs (#5643) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementing subgraph blueprints (#5139) included changes to saving to ensure that SaveAs generates a new workflow of the correct type. However this code failed to utilize the pre-prepared state when performing the actual save. This produced a couple of problems with both failing to detach the workflow and failing to apply the correct state This error is only encountered when using Save As from a non temporary workflow (one loaded from the workflows sidebar tab). As this state calculation code is only used in this code path, it has been moved into the saveAs function of the workflowStore. Resolves #5592 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5643-Fix-SaveAs-2726d73d3650818faa7af449d1f13c26) by [Unito](https://www.unito.io) --- .../workflow/core/services/workflowService.ts | 9 +-------- .../workflow/management/stores/workflowStore.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/platform/workflow/core/services/workflowService.ts b/src/platform/workflow/core/services/workflowService.ts index bd16db53e..c4234cf45 100644 --- a/src/platform/workflow/core/services/workflowService.ts +++ b/src/platform/workflow/core/services/workflowService.ts @@ -17,7 +17,7 @@ import { downloadBlob } from '@/scripts/utils' import { useDialogService } from '@/services/dialogService' import { useDomWidgetStore } from '@/stores/domWidgetStore' import { useWorkspaceStore } from '@/stores/workspaceStore' -import { appendJsonExt, generateUUID } from '@/utils/formatUtil' +import { appendJsonExt } from '@/utils/formatUtil' export const useWorkflowService = () => { const settingStore = useSettingStore() @@ -112,13 +112,6 @@ export const useWorkflowService = () => { await renameWorkflow(workflow, newPath) await workflowStore.saveWorkflow(workflow) } else { - // Generate new id when saving existing workflow as a new file - const id = generateUUID() - const state = JSON.parse( - JSON.stringify(workflow.activeState) - ) as ComfyWorkflowJSON - state.id = id - const tempWorkflow = workflowStore.saveAs(workflow, newPath) await openWorkflow(tempWorkflow) await workflowStore.saveWorkflow(tempWorkflow) diff --git a/src/platform/workflow/management/stores/workflowStore.ts b/src/platform/workflow/management/stores/workflowStore.ts index bb70481f8..02b48c55b 100644 --- a/src/platform/workflow/management/stores/workflowStore.ts +++ b/src/platform/workflow/management/stores/workflowStore.ts @@ -20,7 +20,7 @@ import { parseNodeExecutionId, parseNodeLocatorId } from '@/types/nodeIdentification' -import { getPathDetails } from '@/utils/formatUtil' +import { generateUUID, getPathDetails } from '@/utils/formatUtil' import { syncEntities } from '@/utils/syncUtil' import { isSubgraph } from '@/utils/typeGuardUtil' @@ -320,12 +320,19 @@ export const useWorkflowStore = defineStore('workflow', () => { existingWorkflow: ComfyWorkflow, path: string ): ComfyWorkflow => { + // Generate new id when saving existing workflow as a new file + const id = generateUUID() + const state = JSON.parse( + JSON.stringify(existingWorkflow.activeState) + ) as ComfyWorkflowJSON + state.id = id + const workflow: ComfyWorkflow = new (existingWorkflow.constructor as any)({ path, modified: Date.now(), size: -1 }) - workflow.originalContent = workflow.content = existingWorkflow.content + workflow.originalContent = workflow.content = JSON.stringify(state) workflowLookup.value[workflow.path] = workflow return workflow }