Remove unnecessary copy of litegraph objects

This commit is contained in:
filtered
2025-05-12 18:06:10 +10:00
parent 77968fed6d
commit 99c7ecfa82
2 changed files with 12 additions and 8 deletions

View File

@@ -772,7 +772,8 @@ export class ComfyApp {
// Register the subgraph - adds type wrapper for Litegraph's `createNode` factory
this.graph.events.addEventListener('subgraph-created', (e) => {
try {
useSubgraphService().registerNewSubgraph(e.detail)
const { subgraph, data } = e.detail
useSubgraphService().registerNewSubgraph(subgraph, data)
} catch (err) {
console.error('Failed to register subgraph', err)
useToastStore().add({

View File

@@ -12,9 +12,6 @@ import { useNodeDefStore } from '@/stores/nodeDefStore'
import { useLitegraphService } from './litegraphService'
export const useSubgraphService = () => {
/** @todo Move to store */
const subgraphs = new Map<string, Subgraph>()
/** Loads a single subgraph definition and registers it with the node def store */
const deserialiseSubgraph = (
subgraph: Subgraph,
@@ -63,7 +60,7 @@ export const useSubgraphService = () => {
for (const subgraphData of graphData.definitions.subgraphs) {
const subgraph =
subgraphs.get(subgraphData.id) ??
comfyApp.graph.subgraphs.get(subgraphData.id) ??
comfyApp.graph.createSubgraph(subgraphData as ExportedSubgraph)
// @ts-expect-error Zod
@@ -72,10 +69,16 @@ export const useSubgraphService = () => {
}
/** Registers a new subgraph (e.g. user converted from nodes) */
const registerNewSubgraph = (subgraph: Subgraph) => {
subgraphs.set(subgraph.id, subgraph)
const registerNewSubgraph = (
subgraph: Subgraph,
exportedSubgraph: ExportedSubgraph
) => {
if (comfyApp.graph.subgraphs.has(subgraph.id)) {
console.debug(`Subgraph ${subgraph.id} already registered`)
return
}
deserialiseSubgraph(subgraph, subgraph.asSerialisable())
deserialiseSubgraph(subgraph, exportedSubgraph)
}
return {