Comfy-Org / Comfy-Org/ComfyUI_frontend

refactor: unify clipboard-to-file construction logic between context menu paste path and paste-event path

Open
#10,048 0 comments 0 reactions 1 assignee Claimed by @christian-byrne View on GitHub
area:context-menus developer experience
Dominant language
TypeScript
Stars
2k
Forks
699
Avg merge
1d 7h
Merged PRs (30d)
490

Description

## Summary

Currently, there are two separate code paths that convert clipboard data into files and pass them to a node:

1. **Context menu path** – `pasteClipboardImageToNode` in `src/utils/clipboardUtil.ts` uses `navigator.clipboard.read()`, constructs a single `File` with a hardcoded filename, and calls `node.pasteFile` / `node.pasteFiles`.
2. **Paste-event path** – `pasteItemsOnNode` in `src/composables/usePaste.ts` iterates over `DataTransfer` items and calls `node.pasteFiles()`.

The two paths have subtly different behavior (e.g. hardcoded filename, only the first image processed, different `File` construction). Unifying the shared file-construction logic would keep behavior consistent and reduce duplication.

## Suggested follow-up

- Extract the file-construction step (Blob → File with proper filename/MIME) into a shared utility.
- Reuse that utility in both `pasteClipboardImageToNode` and the DataTransfer-based paste path.
- Ensure both paths call `node.pasteFile` and `node.pasteFiles` consistently (mirroring what `usePaste.ts` already does).

## Context

- Introduced in PR #10021 (feat: add Paste Image option to Load Image node context menu)
- Raised by @christian-byrne in review comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/10021#discussion_r2939392139

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-10048-refactor-unify-clipboard-to-file-construction-logic-between-context-menu-paste-path--3256d73d3650818fbd51fa9605723b13) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.