fix: solve #5282 — pasting images into the new workspace prompt

Draft
GI
4mo ago
+79-10

Root cause

Pasting a clipboard image into the new-workspace "What do you want to do?" prompt did nothing, even though the paperclip upload worked and pasting worked elsewhere (the chat composer).

The paste handler in PromptInputTextarea (packages/ui/src/components/ai-elements/prompt-input.tsx) iterated the clipboard items with for...of:

for (const item of event.clipboardData.items) { ... }

event.clipboardData.items is a DataTransferItemList, which is array-like but not iterable — it has no Symbol.iterator. Against a real browser clipboard this throws TypeError: ... is not iterable inside the paste handler, so no files are ever added and the paste appears to do nothing.

The paperclip button works because it goes through the file-input onChange path, and the chat composer (TiptapPromptEditor) already reads items via Array.from(clipItems) — which is why pasting works there but not in the new-workspace modal.

The fix

Extract the file-collection logic into a small, exported, pure helper getFilesFromDataTransferItems(items) that reads the list with Array.from(...) (the length/index protocol) instead of for...of, matching the working chat composer. handlePaste now delegates to it.

export function getFilesFromDataTransferItems(items: DataTransferItemList): File[] {
  return Array.from(items)
    .filter((item) => item.kind === "file")
    .map((item) => item.getAsFile())
    .filter((file): file is File => file !== null);
}

Tests

Added prompt-input.test.tsx, which builds a mock that mirrors a real DataTransferItemList — indexed + length but deliberately without Symbol.iterator:

  • Reproduction: against the original for...of implementation the test threw TypeError: {} is not iterable, proving the bug.
  • After the fix: the helper extracts pasted image files correctly and ignores non-file (text) clipboard items. Both tests pass.

Closes #5282


Open in Stage

Summary by cubic

Enable pasting images into the new workspace "What do you want to do?" prompt by correctly reading clipboard items. Aligns paste behavior with the chat composer and fixes #5282.

  • Bug Fixes
    • Added getFilesFromDataTransferItems(items) to read DataTransferItemList via Array.from instead of for...of.
    • Updated paste handler to use the helper and attach pasted files.
    • Added tests to verify image extraction and ignoring non-file clipboard items.