Skip to content

Commit d171597

Browse files
authored
Register frontend only node defs (#468)
* Register frontend only node defs * nit * nit
1 parent 49a910d commit d171597

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/scripts/app.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,12 +1964,37 @@ export class ComfyApp {
19641964
// Load node definitions from the backend
19651965
const defs = await api.getNodeDefs()
19661966
await this.registerNodesFromDefs(defs)
1967+
await this.#invokeExtensionsAsync('registerCustomNodes')
19671968
if (this.vueAppReady) {
1969+
// Frontend only nodes registered by custom nodes.
1970+
// Example: https://github.com/rgthree/rgthree-comfy/blob/dd534e5384be8cf0c0fa35865afe2126ba75ac55/src_web/comfyui/fast_groups_bypasser.ts#L10
1971+
const rawDefs = Object.fromEntries(
1972+
Object.entries(LiteGraph.registered_node_types).map(([name, _]) => [
1973+
name,
1974+
{
1975+
name,
1976+
display_name: name,
1977+
category: '__frontend_only__',
1978+
input: { required: {}, optional: {} },
1979+
output: [],
1980+
output_name: [],
1981+
output_is_list: [],
1982+
python_module: 'custom_nodes.frontend_only',
1983+
description: `Frontend only node for ${name}`
1984+
}
1985+
])
1986+
)
1987+
1988+
const allNodeDefs = {
1989+
...rawDefs,
1990+
...defs,
1991+
...SYSTEM_NODE_DEFS
1992+
}
1993+
19681994
const nodeDefStore = useNodeDefStore()
1969-
nodeDefStore.updateNodeDefs([...Object.values(defs), ...SYSTEM_NODE_DEFS])
1995+
nodeDefStore.updateNodeDefs(Object.values(allNodeDefs))
19701996
nodeDefStore.updateWidgets(this.widgets)
19711997
}
1972-
await this.#invokeExtensionsAsync('registerCustomNodes')
19731998
}
19741999

19752000
getWidgetType(inputData, inputName) {

src/stores/nodeDefStore.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ export class ComfyNodeDefImpl {
190190
}
191191
}
192192

193-
export const SYSTEM_NODE_DEFS: ComfyNodeDef[] = [
194-
{
193+
export const SYSTEM_NODE_DEFS: Record<string, ComfyNodeDef> = {
194+
PrimitiveNode: {
195195
name: 'PrimitiveNode',
196196
display_name: 'Primitive',
197197
category: 'utils',
@@ -202,7 +202,7 @@ export const SYSTEM_NODE_DEFS: ComfyNodeDef[] = [
202202
python_module: 'nodes',
203203
description: 'Primitive values like numbers, strings, and booleans.'
204204
},
205-
{
205+
Reroute: {
206206
name: 'Reroute',
207207
display_name: 'Reroute',
208208
category: 'utils',
@@ -213,7 +213,7 @@ export const SYSTEM_NODE_DEFS: ComfyNodeDef[] = [
213213
python_module: 'nodes',
214214
description: 'Reroute the connection to another node.'
215215
},
216-
{
216+
Note: {
217217
name: 'Note',
218218
display_name: 'Note',
219219
category: 'utils',
@@ -224,7 +224,7 @@ export const SYSTEM_NODE_DEFS: ComfyNodeDef[] = [
224224
python_module: 'nodes',
225225
description: 'Node that add notes to your project'
226226
}
227-
]
227+
}
228228

229229
function sortedTree(node: TreeNode): TreeNode {
230230
// Create a new node with the same label and data

0 commit comments

Comments
 (0)