ComfyUI_frontend icon indicating copy to clipboard operation
ComfyUI_frontend copied to clipboard

Adjust the logic in handleFile function of app.ts

Open mirabarukaso opened this issue 5 months ago • 3 comments

Prerequisites

  • [x] I am running the latest version of ComfyUI
  • [x] I have searched existing issues to make sure this isn't a duplicate
  • [x] I have tested with all custom nodes disabled (see how)

What happened?

In the current logic, the parameters are positioned too early. This causes images saved using the Image Saver node with A1111 compatibility to fail to load the workflow correctly. Since the code first detects the presence of the parameters, it attempts to read them in A1111 compatibility mode instead of using the prompt correctly to load the workflow.

It is recommended that the priority of parameters is lowered to the very end so that compatibility mode is only used for evaluation if all preceding checks fail.

I traced back through the versions and discovered that, although this issue has probably been present for long time, bug it appeared after today I updated to latest ComfyUI.

https://github.com/Comfy-Org/ComfyUI_frontend/blob/c57ceaf8265fd9b7f6b180967652cdbef8722c27/src/scripts/app.ts#L1421

  async handleFile(file: File, openSource?: WorkflowOpenSource) {
    const fileName = file.name.replace(/\.\w+$/, '') // Strip file extension
    const workflowData = await getWorkflowDataFromFile(file)
    if (!workflowData) {
      this.showErrorOnFileLoad(file)
      return
    }

    const { workflow, prompt, parameters, templates } = workflowData

    if (templates) {
      this.loadTemplateData({ templates })
    }

    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)
      return
    }
	
	if (parameters) {
      // Note: Not putting this in `importA1111` as it is mostly not used
      // by external callers, and `importA1111` has no access to `app`.
      useWorkflowService().beforeLoadNewGraph()
      importA1111(this.graph, parameters)
      useWorkflowService().afterLoadNewGraph(
        fileName,
        this.graph.serialize() as unknown as ComfyWorkflowJSON
      )
      return
    }

    this.showErrorOnFileLoad(file)
  }

Steps to Reproduce

  1. Update to latest start comfyui
  2. Load 2025-11-27-150211_3065179543.png in to comfyui
  3. Shows the A1111 workflow
  4. Load 2025-11-27-150211_3065179543 - Copy.png which has simply change parameters in tExt to marameters
  5. Shows the correct workflow
Image Image

Incorrect Workflow

2025-11-27-150211_3065179543.png 2025-11-27-150211_3065179543.png

Image

Correct Workflow

2025-11-27-150211_3065179543 - Copy.png 2025-11-27-150211_3065179543 - Copy.png

Image

How is this affecting you?

Feature doesn't work as expected

ComfyUI Frontend Version

1.34.0

Browser

Edge

Console Errors


Logs

System Info

Checkpoint files will always be loaded safely.
Total VRAM 24576 MB, total RAM 130756 MB
pytorch version: 2.9.0+cu130
Enabled fp16 accumulation.
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA TITAN RTX : cudaMallocAsync
Enabled pinned memory 58840.0
working around nvidia conv3d memory bug.
Using sage attention
Python version: 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)]
ComfyUI version: 0.3.75
ComfyUI frontend version: 1.34.0
[Prompt Server] web root: C:\Users\oOkami\AppData\Roaming\Python\Python313\site-packages\comfyui_frontend_package\static
Total VRAM 24576 MB, total RAM 130756 MB
pytorch version: 2.9.0+cu130
Enabled fp16 accumulation.
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA TITAN RTX : cudaMallocAsync
Enabled pinned memory 58840.0

Additional Context

No response

┆Issue is synchronized with this Notion page by Unito

mirabarukaso avatar Nov 27 '25 06:11 mirabarukaso

Hi @mirabarukaso! I'm Dosu and I’m helping the ComfyUI_frontend team.

The bug is caused by the handleFile function checking for 'parameters' before 'workflow' and 'prompt', which triggers A1111 compatibility mode even when a proper workflow or prompt is present. To fix this, move the 'parameters' check after both 'workflow' and 'prompt' checks so compatibility mode is only used if other data is absent. This change is safe—there are no dependencies or side effects elsewhere in the codebase that require the current order, and all relevant logic is self-contained in handleFile source.

Here's how the corrected logic should look:

async handleFile(file: File, openSource?: WorkflowOpenSource) {
  const fileName = file.name.replace(/\.\w+$/, '')
  const workflowData = await getWorkflowDataFromFile(file)
  if (!workflowData) {
    this.showErrorOnFileLoad(file)
    return
  }

  const { workflow, prompt, parameters, templates } = workflowData

  if (templates) {
    this.loadTemplateData({ templates })
  }

  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)
    return
  }

  if (parameters) {
    useWorkflowService().beforeLoadNewGraph()
    importA1111(this.graph, parameters)
    useWorkflowService().afterLoadNewGraph(
      fileName,
      this.graph.serialize() as unknown as ComfyWorkflowJSON
    )
    return
  }

  this.showErrorOnFileLoad(file)
}

This ensures workflows and prompts are loaded correctly, and A1111 compatibility mode is only used as a fallback.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Open in Cursor Join Discord Share on X

dosubot[bot] avatar Nov 27 '25 06:11 dosubot[bot]

Bugged after https://github.com/Comfy-Org/ComfyUI_frontend/commit/31e405abc8dd1adcc8246a5eedf594ca78abae79

mirabarukaso avatar Nov 27 '25 07:11 mirabarukaso

Wow, I knew that one day we would be punished for not decoding png the proper way. Thanks for all this debugging.

christian-byrne avatar Nov 27 '25 07:11 christian-byrne