fix: drag-and-drop screenshot creates LoadImage node instead of showing error (#8886)

## Summary

Fix drag-and-drop of local screenshots onto the canvas failing to create
a LoadImage node.

## Changes

- **What**: Replace `_.isEmpty(workflowData)` check in `handleFile` with
a check for workflow-relevant keys (`workflow`, `prompt`, `parameters`,
`templates`). PNG screenshots often contain non-workflow `tEXt` metadata
(e.g. `Software`, `Creation Time`) which made `_.isEmpty()` return
`false`, skipping the LoadImage fallback and showing an error instead.

## Review Focus

The root cause is that `getPngMetadata` extracts all `tEXt`/`iTXt` PNG
chunks indiscriminately. Rather than filtering at the parser level
(which could break extensions relying on arbitrary metadata), the fix
checks for workflow-relevant keys before deciding whether to treat the
file as a workflow or a plain image.

Fixes #7752

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8886-fix-drag-and-drop-screenshot-creates-LoadImage-node-instead-of-showing-error-3086d73d3650817d86c5f1386aa041c2)
by [Unito](https://www.unito.io)

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Christian Byrne
2026-02-14 22:25:59 -08:00
committed by GitHub
parent 2b896a722b
commit 066a1f1f11
3 changed files with 23 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB

View File

@@ -196,5 +196,25 @@ describe('ComfyApp', () => {
mockNode
)
})
it('should handle image files with non-workflow metadata by creating LoadImage node', async () => {
vi.mocked(getWorkflowDataFromFile).mockResolvedValue({
Software: 'gnome-screenshot'
})
const mockNode = createMockNode()
vi.mocked(createNode).mockResolvedValue(mockNode)
const imageFile = createTestFile('screenshot.png', 'image/png')
await app.handleFile(imageFile)
expect(createNode).toHaveBeenCalledWith(mockCanvas, 'LoadImage')
expect(pasteImageNode).toHaveBeenCalledWith(
mockCanvas,
expect.any(DataTransferItemList),
mockNode
)
})
})
})

View File

@@ -1513,7 +1513,9 @@ export class ComfyApp {
async handleFile(file: File, openSource?: WorkflowOpenSource) {
const fileName = file.name.replace(/\.\w+$/, '') // Strip file extension
const workflowData = await getWorkflowDataFromFile(file)
if (_.isEmpty(workflowData)) {
const { workflow, prompt, parameters, templates } = workflowData ?? {}
if (!(workflow || prompt || parameters || templates)) {
if (file.type.startsWith('image')) {
const transfer = new DataTransfer()
transfer.items.add(file)
@@ -1526,8 +1528,6 @@ export class ComfyApp {
return
}
const { workflow, prompt, parameters, templates } = workflowData
if (
templates &&
typeof templates === 'object' &&