Skip to content

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

@robertoalvarezalonso

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:

if (option.ref != null && option.ref.current) {

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersplaygroundpopoverIssues related to popover/menu code in the playground

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions