Skip to content

[lexical-react] Bug Fix: Fall back to root node in NodeContextMenuPlugin when click target has no Lexical node#8385

Merged
etrepum merged 3 commits intofacebook:mainfrom
mayrang:fix/context-menu-empty-fallback
Apr 24, 2026
Merged

[lexical-react] Bug Fix: Fall back to root node in NodeContextMenuPlugin when click target has no Lexical node#8385
etrepum merged 3 commits intofacebook:mainfrom
mayrang:fix/context-menu-empty-fallback

Conversation

@mayrang
Copy link
Copy Markdown
Contributor

@mayrang mayrang commented Apr 23, 2026

Description

Fixes #8257

NodeContextMenuPlugin always calls preventDefault() on contextmenu events, but when right-clicking on "empty" editor chrome (placeholder, padding, or DOM that doesn't map to a Lexical node), $getNearestNodeFromDOMNode returns null. This results in an empty custom menu while the native context menu is suppressed.

As suggested by @etrepum in #8257, this falls back to $getRoot() when no node is found:

- const node = $getNearestNodeFromDOMNode(e.target as Element);
+ const node = $getNearestNodeFromDOMNode(e.target as Element) ?? $getRoot();

This means:

  • Right-clicking on text/blocks works exactly as before ($getRoot() fallback is never reached)
  • Right-clicking on empty areas now uses the root node for $showOn filtering, so items without $showOn (e.g. Paste) are shown instead of an empty menu
  • No changes to the plugin's public API

Test Plan

  1. Open the Lexical playground
  2. Right-click on text inside the editor → context menu shows items as before
  3. Right-click on the placeholder or empty padding below content → Before: empty menu appears, native menu suppressed. After: menu shows applicable items (e.g. Paste)

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 23, 2026

Hi @mayrang!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 24, 2026 4:38am
lexical-playground Ready Ready Preview, Comment Apr 24, 2026 4:38am

Request Review

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 23, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 23, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 23, 2026
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing pnpm run ci-check

@mayrang
Copy link
Copy Markdown
Contributor Author

mayrang commented Apr 23, 2026

Sorry, missed running Prettier before pushing. Fixed now.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Apr 24, 2026

As a first time contributor your checks don't run until a maintainer clicks an approval button, adding empty commits won't help anything.

@mayrang
Copy link
Copy Markdown
Contributor Author

mayrang commented Apr 24, 2026

Got it, thanks for letting me know! I wasn't aware that first-time contributors need manual approval for CI. Sorry for the unnecessary commit.

@etrepum etrepum added this pull request to the merge queue Apr 24, 2026
Merged via the queue into facebook:main with commit f252182 Apr 24, 2026
41 checks passed
@etrepum etrepum mentioned this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NodeContextMenuPlugin: empty menu when DOM target has no Lexical node; Paste unavailable

2 participants