Skip to content

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

Closed

Description

@robertoalvarezalonso

Lexical version: v0.36.2+dev.esm (Playground)

Steps To Reproduce

  1. Open the Lexical Playground
  2. Enable mentions (@) and type the first letter to open the suggestion list.
  3. Move the cursor to the last entry (Arrow Down).
  4. Keep typing quickly so the list refreshes and shrinks before selectedIndex is reset. You can try with 'pooja'.
  5. Quickly press Arrow Down again

Or for a better success rate at reproducing it, have Hammerspoon doing it:

hs.hotkey.bind({"ctrl", "alt"}, "p", function()
    hs.eventtap.keyStrokes("@")

    hs.eventtap.keyStrokes("p")

    hs.eventtap.keyStroke({}, "down")
    hs.eventtap.keyStroke({}, "down")
    hs.eventtap.keyStroke({}, "down")
    hs.eventtap.keyStroke({}, "down")

    hs.timer.usleep(1000000)

    hs.eventtap.keyStrokes("ooj")

    hs.eventtap.keyStroke({}, "down")
end)

The current behavior

Crash in the browser console
Image

If I'm not mistaken, this is happening here: https://github.com/facebook/lexical/blob/8cbd7260914acbbdbc34c2e35cdda40023a63783/packages/lexical-react/src/shared/LexicalMenu.ts#L385

The expected behavior

The highlighted index should reset (or short-circuit) when the list shrinks so we never dereference a missing option.

Impact of fix

Prevents a crash under fast typing in typeahead/mentions flows used by any app relying on LexicalTypeaheadMenuPlugin

Activity

  1. added
    good first issue
    popover
    on Oct 1, 2025
  2. MRADULTRIPATHI commented on Oct 2, 2025

    @MRADULTRIPATHI
    Contributor

    Hi, just to update here:

    I’ve opened PR #7899 which addresses this issue.
    The PR already includes the requested changes from @etrepun (including formatting fixes) and all tests are passing, including the extended test suite.

    This should safely resolve the crash described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueplaygroundpopover

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions