[Cleanup] Remove ComfyApp.serializeGraph (#3383)

This commit is contained in:
Chenlei Hu
2025-04-10 11:50:27 -04:00
committed by GitHub
parent 261f671ef0
commit 27c8389b9f
3 changed files with 11 additions and 19 deletions

View File

@@ -33,7 +33,7 @@ const toast = useToast()
const workflowStore = useWorkflowStore()
const migrateToLitegraphReroute = () => {
const workflowJSON = app.serializeGraph() as unknown as WorkflowJSON04
const workflowJSON = app.graph.serialize() as unknown as WorkflowJSON04
const migratedWorkflowJSON = migrateLegacyRerouteNodes(workflowJSON)
app.loadGraphData(
migratedWorkflowJSON,

View File

@@ -18,7 +18,7 @@ export function useWorkflowPersistence() {
const persistCurrentWorkflow = () => {
if (!workflowPersistenceEnabled.value) return
const workflow = JSON.stringify(comfyApp.serializeGraph())
const workflow = JSON.stringify(comfyApp.graph.serialize())
localStorage.setItem('workflow', workflow)
if (api.clientId) {
sessionStorage.setItem(`workflow:${api.clientId}`, workflow)

View File

@@ -1147,24 +1147,13 @@ export class ComfyApp {
)
await useWorkflowService().afterLoadNewGraph(
workflow,
// @ts-expect-error zod types issue. Will be fixed after we enable ts-strict
this.graph.serialize()
this.graph.serialize() as unknown as ComfyWorkflowJSON
)
requestAnimationFrame(() => {
this.graph.setDirtyCanvas(true, true)
})
}
/**
* Serializes a graph using preferred user settings.
* @param graph The litegraph to serialize.
* @returns A serialized graph (aka workflow) with preferred user settings.
*/
serializeGraph(graph: LGraph = this.graph) {
const sortNodes = useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
return graph.serialize({ sortNodes })
}
async graphToPrompt(graph = this.graph) {
return graphToPrompt(graph, {
sortNodes: useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
@@ -1276,8 +1265,10 @@ export class ComfyApp {
// by external callers, and `importA1111` has no access to `app`.
useWorkflowService().beforeLoadNewGraph()
importA1111(this.graph, pngInfo.parameters)
// @ts-expect-error zod type issue on ComfyWorkflowJSON. Should be resolved after enabling ts-strict globally.
useWorkflowService().afterLoadNewGraph(fileName, this.serializeGraph())
useWorkflowService().afterLoadNewGraph(
fileName,
this.graph.serialize() as unknown as ComfyWorkflowJSON
)
} else {
this.showErrorOnFileLoad(file)
}
@@ -1479,9 +1470,10 @@ export class ComfyApp {
app.graph.arrange()
// @ts-expect-error zod type issue on ComfyWorkflowJSON. ComfyWorkflowJSON
// is stricter than LiteGraph's serialisation schema.
useWorkflowService().afterLoadNewGraph(fileName, this.serializeGraph())
useWorkflowService().afterLoadNewGraph(
fileName,
this.graph.serialize() as unknown as ComfyWorkflowJSON
)
}
/**