Skip to content

Commit 066a1f1

Browse files
christian-byrnegithub-actions
andauthored
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>
1 parent 2b896a7 commit 066a1f1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed
596 Bytes
Loading

src/scripts/app.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,25 @@ describe('ComfyApp', () => {
196196
mockNode
197197
)
198198
})
199+
200+
it('should handle image files with non-workflow metadata by creating LoadImage node', async () => {
201+
vi.mocked(getWorkflowDataFromFile).mockResolvedValue({
202+
Software: 'gnome-screenshot'
203+
})
204+
205+
const mockNode = createMockNode()
206+
vi.mocked(createNode).mockResolvedValue(mockNode)
207+
208+
const imageFile = createTestFile('screenshot.png', 'image/png')
209+
210+
await app.handleFile(imageFile)
211+
212+
expect(createNode).toHaveBeenCalledWith(mockCanvas, 'LoadImage')
213+
expect(pasteImageNode).toHaveBeenCalledWith(
214+
mockCanvas,
215+
expect.any(DataTransferItemList),
216+
mockNode
217+
)
218+
})
199219
})
200220
})

src/scripts/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,9 @@ export class ComfyApp {
15131513
async handleFile(file: File, openSource?: WorkflowOpenSource) {
15141514
const fileName = file.name.replace(/\.\w+$/, '') // Strip file extension
15151515
const workflowData = await getWorkflowDataFromFile(file)
1516-
if (_.isEmpty(workflowData)) {
1516+
const { workflow, prompt, parameters, templates } = workflowData ?? {}
1517+
1518+
if (!(workflow || prompt || parameters || templates)) {
15171519
if (file.type.startsWith('image')) {
15181520
const transfer = new DataTransfer()
15191521
transfer.items.add(file)
@@ -1526,8 +1528,6 @@ export class ComfyApp {
15261528
return
15271529
}
15281530

1529-
const { workflow, prompt, parameters, templates } = workflowData
1530-
15311531
if (
15321532
templates &&
15331533
typeof templates === 'object' &&

0 commit comments

Comments
 (0)