Skip to content

[lexical-react] Bug Fix: LexicalMenu guard against undefined option when list shrinks - #7899

Merged
etrepum merged 4 commits into
meta:mainfrom
MRADULTRIPATHI:fix/lexicalmenu-null-guard
Oct 2, 2025
Merged

etrepum merged 4 commits into
meta:mainfrom
MRADULTRIPATHI:fix/lexicalmenu-null-guard

Conversation

@MRADULTRIPATHI

Copy link
Copy Markdown
Contributor

Title

[lexical-react] Bug Fix: guard against undefined option when list shrinks

PR Types:

Bug Fix

Description

  • Current behavior:
    When navigating the typeahead menu with ArrowDown/ArrowUp, if the list shrinks (e.g. type @p, move down to last option, then continue typing @poo), options[newSelectedIndex] can become undefined.
    This causes a crash:
  • Behavior after fix:
    Added a guard for missing option before accessing .ref, and safely reset the highlighted index when the list shrinks.
    This prevents crashes and ensures stable keyboard navigation in the typeahead menu.

Closes #7897


Test plan

Before

Steps:

  1. Open Playground
  2. Type @p to open mention list
  3. Use ArrowDown to select the last item
  4. Continue typing quickly (poo) so that the list shrinks
  5. Press ArrowDown

❌ Crash occurs in console:

After

Steps:

  1. Open Playground
  2. Type @p to open mention list
  3. Use ArrowDown to select the last item
  4. Continue typing quickly (poo) so that the list shrinks
  5. Press ArrowDown

✅ No crash, console stays clean, and list resets correctly.

Screenshot:

image

@meta-cla

meta-cla Bot commented Oct 1, 2025

Copy link
Copy Markdown

Hi @MRADULTRIPATHI!

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 [email protected]. Thanks!

@vercel

vercel Bot commented Oct 1, 2025 •

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Oct 2, 2025 6:24am
lexical-playground Ready Ready Preview Comment Oct 2, 2025 6:24am

@MRADULTRIPATHI

Copy link
Copy Markdown
Contributor Author

I have signed the CLA ✅
Please let me know if anything else is required. 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 Oct 1, 2025
@meta-cla

meta-cla Bot commented Oct 1, 2025

Copy link
Copy Markdown

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

Co-authored-by: Bob Ippolito <[email protected]>
@MRADULTRIPATHI
MRADULTRIPATHI requested a review from etrepum October 2, 2025 06:11
@etrepum etrepum changed the title fix(LexicalMenu): guard against undefined option when list shrinks [lexical-react] Bug Fix: guard against undefined option when list shrinks Oct 2, 2025
@MRADULTRIPATHI

Copy link
Copy Markdown
Contributor Author

Thanks again @etrepum
All suggested changes have been applied and tests are now passing.
When convenient, could you please review and merge this PR?

@etrepum etrepum changed the title [lexical-react] Bug Fix: guard against undefined option when list shrinks [lexical-react] Bug Fix: LexicalMenu guard against undefined option when list shrinks Oct 2, 2025
@etrepum
etrepum added this pull request to the merge queue Oct 2, 2025
Merged via the queue into meta:main with commit e60b434 Oct 2, 2025
@etrepum etrepum mentioned this pull request Oct 11, 2025

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — c1748e8b Deployed Oct 2, 2025 by vercel[bot]
Preview – lexical — c1748e8b Deployed Oct 2, 2025 by vercel[bot]
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.

Bug: LexicalMenu reads option.ref when options[newSelectedIndex] is undefined

2 participants