@@ -153,14 +153,20 @@ export const useSubgraphStore = defineStore('subgraph', () => {
153153 if ( ! force && this . isLoaded ) return await super . load ( { force } )
154154 const loaded = await super . load ( { force } )
155155 const st = loaded . activeState
156+ const rootNode = st . nodes [ 0 ]
157+ if ( ! rootNode ) {
158+ throw new TypeError (
159+ `Subgraph blueprint '${ this . filename } ' must contain a root node`
160+ )
161+ }
156162 const sg = ( st . definitions ?. subgraphs ?? [ ] ) . find (
157- ( sg ) => sg . id == st . nodes [ 0 ] . type
163+ ( sg ) => sg . id == rootNode . type
158164 )
159165 if ( ! sg )
160166 throw new Error (
161167 'Loaded subgraph blueprint does not contain valid subgraph'
162168 )
163- sg . name = st . nodes [ 0 ] . title = this . filename
169+ sg . name = rootNode . title = this . filename
164170
165171 // Copy blueprint metadata from workflow extra to subgraph extra
166172 // so it's available when editing via canvas.subgraph.extra
@@ -283,8 +289,12 @@ export const useSubgraphStore = defineStore('subgraph', () => {
283289 overrides : Partial < ComfyNodeDefV1 > = { } ,
284290 name : string = workflow . filename
285291 ) {
286- const subgraphNode = workflow . changeTracker . initialState
287- . nodes [ 0 ] as ComfyNode
292+ const subgraphNode = workflow . changeTracker . initialState . nodes [ 0 ]
293+ if ( ! subgraphNode ) {
294+ throw new TypeError (
295+ `Subgraph blueprint '${ name } ' must contain a root node`
296+ )
297+ }
288298 subgraphNode . inputs ??= [ ]
289299 subgraphNode . outputs ??= [ ]
290300 //NOTE: Types are cast to string. This is only used for input coloring on previews
0 commit comments