Skip to content

Commit 83f0449

Browse files
fix: don't use registry when only checking for presence of missing nodes (#6965)
Changes the client-side validation of whether a graph has missing nodes to use a simpler check (is the node name in the node defs from `/object_info`), rather than using the Comfy Node Registry API (api.comfy.org). The Registry API is still needed to get full metadata/info about missing nodes, but that can be deferred until the user actually needs that info. This also fixes an issue where a node you coded yourself locally which is neither a core node nor a node in the registry would be considered "missing." ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6965-fix-don-t-use-registry-when-only-checking-for-presence-of-missing-nodes-2b76d73d365081e7b8fbcb3f2a1c4502) by [Unito](https://www.unito.io)
1 parent c5fe617 commit 83f0449

File tree

4 files changed

+166
-4
lines changed

4 files changed

+166
-4
lines changed

src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ import { useI18n } from 'vue-i18n'
4444
4545
import { isCloud } from '@/platform/distribution/types'
4646
import { useTelemetry } from '@/platform/telemetry'
47+
import { app } from '@/scripts/app'
4748
import { useCommandStore } from '@/stores/commandStore'
49+
import { useNodeDefStore } from '@/stores/nodeDefStore'
4850
import { useQueueSettingsStore } from '@/stores/queueStore'
4951
import { useWorkspaceStore } from '@/stores/workspaceStore'
50-
import { useMissingNodes } from '@/workbench/extensions/manager/composables/nodePack/useMissingNodes'
52+
import { graphHasMissingNodes } from '@/workbench/extensions/manager/utils/graphHasMissingNodes'
5153
5254
import BatchCountEdit from '../BatchCountEdit.vue'
5355
5456
const workspaceStore = useWorkspaceStore()
5557
const { mode: queueMode, batchCount } = storeToRefs(useQueueSettingsStore())
5658
57-
const { hasMissingNodes } = useMissingNodes()
59+
const nodeDefStore = useNodeDefStore()
60+
const hasMissingNodes = computed(() =>
61+
graphHasMissingNodes(app.graph, nodeDefStore.nodeDefsByName)
62+
)
5863
5964
const { t } = useI18n()
6065
const queueModeMenuItemLookup = computed(() => {

src/components/breadcrumb/SubgraphBreadcrumbItem.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ import {
6464
ComfyWorkflow,
6565
useWorkflowStore
6666
} from '@/platform/workflow/management/stores/workflowStore'
67+
import { app } from '@/scripts/app'
6768
import { useDialogService } from '@/services/dialogService'
6869
import { useCommandStore } from '@/stores/commandStore'
70+
import { useNodeDefStore } from '@/stores/nodeDefStore'
6971
import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
7072
import { appendJsonExt } from '@/utils/formatUtil'
71-
import { useMissingNodes } from '@/workbench/extensions/manager/composables/nodePack/useMissingNodes'
73+
import { graphHasMissingNodes } from '@/workbench/extensions/manager/utils/graphHasMissingNodes'
7274
7375
interface Props {
7476
item: MenuItem
@@ -79,7 +81,10 @@ const props = withDefaults(defineProps<Props>(), {
7981
isActive: false
8082
})
8183
82-
const { hasMissingNodes } = useMissingNodes()
84+
const nodeDefStore = useNodeDefStore()
85+
const hasMissingNodes = computed(() =>
86+
graphHasMissingNodes(app.graph, nodeDefStore.nodeDefsByName)
87+
)
8388
8489
const { t } = useI18n()
8590
const menu = ref<InstanceType<typeof Menu> & MenuState>()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { unref } from 'vue'
2+
import type { MaybeRef } from 'vue'
3+
4+
import type {
5+
LGraph,
6+
LGraphNode,
7+
Subgraph
8+
} from '@/lib/litegraph/src/litegraph'
9+
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
10+
import { collectAllNodes } from '@/utils/graphTraversalUtil'
11+
12+
export type NodeDefLookup = Record<string, ComfyNodeDefImpl | undefined>
13+
14+
const isNodeMissingDefinition = (
15+
node: LGraphNode,
16+
nodeDefsByName: NodeDefLookup
17+
) => {
18+
const nodeName = node?.type
19+
if (!nodeName) return false
20+
return !nodeDefsByName[nodeName]
21+
}
22+
23+
export const collectMissingNodes = (
24+
graph: LGraph | Subgraph | null | undefined,
25+
nodeDefsByName: MaybeRef<NodeDefLookup>
26+
): LGraphNode[] => {
27+
if (!graph) return []
28+
const lookup = unref(nodeDefsByName)
29+
return collectAllNodes(graph, (node) => isNodeMissingDefinition(node, lookup))
30+
}
31+
32+
export const graphHasMissingNodes = (
33+
graph: LGraph | Subgraph | null | undefined,
34+
nodeDefsByName: MaybeRef<NodeDefLookup>
35+
) => {
36+
return collectMissingNodes(graph, nodeDefsByName).length > 0
37+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import type {
4+
LGraph,
5+
LGraphNode,
6+
Subgraph
7+
} from '@/lib/litegraph/src/litegraph'
8+
import {
9+
collectMissingNodes,
10+
graphHasMissingNodes
11+
} from '@/workbench/extensions/manager/utils/graphHasMissingNodes'
12+
import type { NodeDefLookup } from '@/workbench/extensions/manager/utils/graphHasMissingNodes'
13+
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
14+
15+
type NodeDefs = NodeDefLookup
16+
17+
let nodeIdCounter = 0
18+
const mockNodeDef = {} as ComfyNodeDefImpl
19+
20+
const createGraph = (nodes: LGraphNode[] = []): LGraph => {
21+
return { nodes } as Partial<LGraph> as LGraph
22+
}
23+
24+
const createSubgraph = (nodes: LGraphNode[]): Subgraph => {
25+
return { nodes } as Partial<Subgraph> as Subgraph
26+
}
27+
28+
const createNode = (
29+
type?: string,
30+
subgraphNodes?: LGraphNode[]
31+
): LGraphNode => {
32+
return {
33+
id: nodeIdCounter++,
34+
type,
35+
isSubgraphNode: subgraphNodes ? () => true : undefined,
36+
subgraph: subgraphNodes ? createSubgraph(subgraphNodes) : undefined
37+
} as unknown as LGraphNode
38+
}
39+
40+
describe('graphHasMissingNodes', () => {
41+
it('returns false when graph is null', () => {
42+
expect(graphHasMissingNodes(null, {})).toBe(false)
43+
})
44+
45+
it('returns false when graph is undefined', () => {
46+
expect(graphHasMissingNodes(undefined, {})).toBe(false)
47+
})
48+
49+
it('returns false when graph has no nodes', () => {
50+
expect(graphHasMissingNodes(createGraph(), {})).toBe(false)
51+
})
52+
53+
it('returns false when every node has a definition', () => {
54+
const graph = createGraph([createNode('FooNode'), createNode('BarNode')])
55+
const nodeDefs: NodeDefs = {
56+
FooNode: mockNodeDef,
57+
BarNode: mockNodeDef
58+
}
59+
60+
expect(graphHasMissingNodes(graph, nodeDefs)).toBe(false)
61+
})
62+
63+
it('returns true when at least one node is missing', () => {
64+
const graph = createGraph([
65+
createNode('FooNode'),
66+
createNode('MissingNode')
67+
])
68+
const nodeDefs: NodeDefs = {
69+
FooNode: mockNodeDef
70+
}
71+
72+
expect(graphHasMissingNodes(graph, nodeDefs)).toBe(true)
73+
})
74+
75+
it('checks nodes nested in subgraphs', () => {
76+
const graph = createGraph([
77+
createNode('ContainerNode', [createNode('InnerMissing')])
78+
])
79+
const nodeDefs: NodeDefs = {
80+
ContainerNode: mockNodeDef
81+
}
82+
83+
const missingNodes = collectMissingNodes(graph, nodeDefs)
84+
expect(missingNodes).toHaveLength(1)
85+
expect(missingNodes[0]?.type).toBe('InnerMissing')
86+
})
87+
88+
it('ignores nodes without a type', () => {
89+
const graph = createGraph([
90+
createNode(undefined),
91+
createNode(null as unknown as string)
92+
])
93+
94+
expect(graphHasMissingNodes(graph, {})).toBe(false)
95+
})
96+
97+
it('traverses deeply nested subgraphs', () => {
98+
const deepGraph = createGraph([
99+
createNode('Layer1', [
100+
createNode('Layer2', [
101+
createNode('Layer3', [createNode('MissingDeep')])
102+
])
103+
])
104+
])
105+
const nodeDefs: NodeDefs = {
106+
Layer1: mockNodeDef,
107+
Layer2: mockNodeDef,
108+
Layer3: mockNodeDef
109+
}
110+
111+
const missingNodes = collectMissingNodes(deepGraph, nodeDefs)
112+
expect(missingNodes).toHaveLength(1)
113+
expect(missingNodes[0]?.type).toBe('MissingDeep')
114+
})
115+
})

0 commit comments

Comments
 (0)