Repository navigation
[lexical-rich-text] Feat: add pasteFileContentCheck config to let files win over incidental HTML on paste - #8902
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
34ced7e to
1573716
Compare
| state.getOutput().escapeFormatTriggers, | ||
| state.getOutput().pasteFileContentCheck, |
There was a problem hiding this comment.
This could be refactored to call getOutput once
| hasContent: (dataTransfer: DataTransfer) => boolean = dataTransfer => | ||
| dataTransfer.types.includes('text/html') || | ||
| dataTransfer.types.includes('text/plain'), |
There was a problem hiding this comment.
I don't think we need to define this default multiple times, it should be defined once and re-used
| event, | ||
| pasteFileContentCheck.peek(), | ||
| ); | ||
| if (files.length > 0 && !hasTextContent) { |
There was a problem hiding this comment.
I think this is the real predicate that matters for this use case, maybe this PR's approach is more complicated than it needs to be.
There was a problem hiding this comment.
Thanks for the feedback. you're right, this was more machinery than the problem needed. I've pushed a simpler version: instead of parameterizing eventFiles's internal hasContent check (which touches a shared utility used by 5 other call sites that don't care about it), I moved the actual decision up to registerRichText/RichTextExtension as a single shouldHandlePasteAsFiles(files, hasTextContent) predicate, with one default definition. lexical-utils is untouched now. Also fixed the double getOutput() call.
One tradeoff worth flagging: this predicate gets a precomputed boolean rather than the raw DataTransfer, so it can't distinguish text/html from text/plain specifically — that covers the issue's actual repro (browser copy-image), but let me know if you want the finer-grained version instead.
…es win over incidental HTML on paste
…de, and signal reactivity
…n point per review
1573716 to
b8a64b7
Compare
Fixes #8681
Problem
Browsers put both a
Filesentry and atext/htmlfallback on the clipboard when an image is copied via the right-click context menu.eventFiles()'shasContentcheck treats anytext/html/text/plainentry as "this is a content paste", which unconditionally blocksDRAG_DROP_PASTEfrom firing inregisterRichText'sPASTE_COMMANDhandler — so a browser-copied image is always routed through the HTML importer instead of being handed to the app as a file, even when the app would prefer the file.Fix
eventFiles()now takes an optionalhasContentpredicate (packages/lexical-utils), defaulting to the exact historicaltext/html/text/plaincheck, so every existing caller (drag/drop, dragstart, dragover) is unaffected.registerRichTextthreads a newpasteFileContentChecksignal parameter through to that call in thePASTE_COMMANDhandler, following the same signal-parameter pattern already used forescapeFormatTriggers.RichTextExtension's config gainspasteFileContentCheck(LexicalRichTextExtension.ts), reactive via the existingnamedSignals/effectwiring — no new plumbing needed.This follows the API shape suggested by @etrepum in the issue thread.
packages/lexical-rich-text/flow/LexicalRichText.js.flowand the extension list in the website docs.Test plan
PasteFileContentCheck.test.ts: default behavior preserved, override lets files win, override doesn't hijack a file-less HTML paste, file-only paste still works under the default, and the config is reactive via signal mutation.pnpm run test-unitpasses (excluding a pre-existing, unrelated timeout inFastPathCrossParent.test.ts).pnpm run tsc,flow,lint,prettierall clean.pnpm run test-e2e-chromiumon the fullCopyAndPastee2e suite(52 tests) passes, confirming default paste/drop behavior across
rich text, lists, tables, and HTML import is unaffected.