[lexical-clipboard] Bug Fix: Update Lexical Clipboard with Empty Selection#7835
Merged
etrepum merged 3 commits intofacebook:mainfrom Sep 20, 2025
Merged
[lexical-clipboard] Bug Fix: Update Lexical Clipboard with Empty Selection#7835etrepum merged 3 commits intofacebook:mainfrom
etrepum merged 3 commits intofacebook:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Sep 19, 2025
Collaborator
etrepum
left a comment
There was a problem hiding this comment.
I don't think changing the semantics of $getLexicalContent is the correct fix. This is part of the public API and it's not clear why it should change.
The fix should probably be closer to the problem, probably in setLexicalClipboardDataTransfer. Maybe just a call to clipboardData.clearData() before the updates.
The clipboard often has data from the prior selection. We should clear it as we might not be overwriting all the same data types there were present previously, which would leave stale data in the clipboard.
Contributor
Author
|
Ah, good idea. That is much simpler and handles other stale data cases outside Lexical as well. I confirmed it still fixes the issue in my repo as well. If this looks good I can try to write a quick test. |
etrepum
reviewed
Sep 20, 2025
etrepum
approved these changes
Sep 20, 2025
Contributor
Author
|
Looks good, thanks for cleaning up and merging. |
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
$copyToClipboardEventupdates aClipboardEventbased on the current selection - however returning null for an absent or empty selection will prevent the Lexical content from getting cleared for an empty selection. This means the 'text/plain' and 'text/html' contents will update to empty strings, but the 'application/x-lexical-editor' will still have whatever stale value was present previously.An alternative fix to the one committed already is to delete the content when null, rather than skipping, i.e.
This would preserve the
nullreturn for$getLexicalContent, though it doesn't look like anything in the repo depends on it.Test plan
No affected tests - though I could probably add one if desired.