Repository navigation
[lexical-rich-text] Bug Fix: forward dropped files when the drop point has no caret - #9076
Merged
Merged
Conversation
…t has no caret The DROP_COMMAND handler only dispatched DRAG_DROP_PASTE when caretFromPoint returned a range, but it called preventDefault and returned true either way. When the browser cannot resolve a caret for the drop coordinates the dropped files were silently discarded. PASTE_COMMAND already dispatches DRAG_DROP_PASTE unconditionally, so this also makes the two paths agree.
nithin42
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 19, 2026 17:30
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
|
A lint rule changed since this PR was opened so you'll need to apply pnpm run lint:fix to this in order to pass integrity checks |
etrepum
approved these changes
Aug 29, 2026
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
registerRichText'sDROP_COMMANDhandler only dispatchesDRAG_DROP_PASTEwhencaretFromPoint()manages to resolve a caret for the drop coordinates:The
preventDefault()andreturn trueare outside thatif, so whencaretFromPoint()returnsnullthe handler still swallows the drop but never forwards the files. From the user's point of view they drop an image onto the editor and absolutely nothing happens, with no error.caretFromPoint()returnsnullin real situations, not just theoretical ones: the browser gives back no caret position for points that do not land on text (dropping onto the editor's padding or a gutter is the easy one to hit), and the final fallback in that function returnsnulloutright when neithercaretRangeFromPointnorcaretPositionFromPointis available.The
PASTE_COMMANDhandler a bit further down in the same file already dispatchesDRAG_DROP_PASTEunconditionally once it has files, so the two paths disagree today. This change makes drop behave like paste.Fix
Hoist the
dispatchCommand(DRAG_DROP_PASTE, files)call out of theif (eventRange !== null)block. Setting the selection from the drop point stays conditional, since that genuinely needs a resolved caret; when there is none the files are inserted at the current selection instead of being thrown away.Test plan
Added
packages/lexical-rich-text/src/__tests__/unit/RichTextDropFiles.test.tswith two cases:DRAG_DROP_PASTE(fails onmain, passes with this change)Before the change the first test fails with
expected null not to be null. After it, both pass. Thelexical-rich-text,lexical-clipboardandlexical-plain-textunit suites are green (21 files, 170 tests).prettierandeslintare clean on both files.