Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,13 @@ export class ComfyApp {
}

let reset_invalid_values = false
if (!graphData) {
// Use explicit validation instead of falsy check to avoid replacing
// valid but falsy values (empty objects, 0, false, etc.)
if (
!graphData ||
typeof graphData !== 'object' ||
Array.isArray(graphData)
) {
graphData = defaultGraph
reset_invalid_values = true
}
Expand Down Expand Up @@ -1432,6 +1438,37 @@ export class ComfyApp {
this.loadTemplateData({ templates })
}

// Check workflow first - it should take priority over parameters
// when both are present (e.g., in ComfyUI-generated PNGs)
if (workflow) {
let workflowObj: ComfyWorkflowJSON
try {
workflowObj =
typeof workflow === 'string' ? JSON.parse(workflow) : workflow
} catch (err) {
console.error('Failed to parse workflow:', err)
this.showErrorOnFileLoad(file)
return
}

// Validate workflow is a proper object
if (
!workflowObj ||
typeof workflowObj !== 'object' ||
Array.isArray(workflowObj)
) {
console.error('Invalid workflow structure')
this.showErrorOnFileLoad(file)
return
}

await this.loadGraphData(workflowObj, true, true, fileName, {
openSource
})
return
}

// Use parameters as fallback when no workflow exists
if (parameters) {
// Note: Not putting this in `importA1111` as it is mostly not used
// by external callers, and `importA1111` has no access to `app`.
Expand All @@ -1444,15 +1481,6 @@ export class ComfyApp {
return
}

if (workflow) {
const workflowObj =
typeof workflow === 'string' ? JSON.parse(workflow) : workflow
await this.loadGraphData(workflowObj, true, true, fileName, {
openSource
})
return
}

if (prompt) {
const promptObj = typeof prompt === 'string' ? JSON.parse(prompt) : prompt
this.loadApiJson(promptObj, fileName)
Expand Down