Skip to content

[lexical-react] Bug Fix: Update the typeahead query during IME composition - #8942

Merged
etrepum merged 3 commits into
meta:mainfrom
hamo-o:fix/typeahead-ime-query
Aug 7, 2026
Merged

etrepum merged 3 commits into
meta:mainfrom
hamo-o:fix/typeahead-ime-query

Conversation

@hamo-o

@hamo-o hamo-o commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

LexicalTypeaheadMenuPlugin does not update its query while an IME composition is in progress, so the menu keeps showing results for the text that preceded the composition. Typing /한글 shows the results for /, and they only catch up once composition ends.

This is a follow-up to #7987 (fix for #7985). That PR stopped the menu from closing mid-composition by bailing out of the update listener entirely:

if (editor.isComposing()) {
  return;
}

The bail-out is wider than the problem it solves. Only the closing is undesirable during composition — the trigger match and onQueryChange are still meaningful, and skipping them is what leaves the menu stale.

What changed

packages/lexical-react

Test plan

  • Unit tests for composing: query reported, menu kept open when the trigger match is lost, menu closed once composition ends
  • Unmount the React root between tests — the menu portals into an anchor on document.body, so a test ending with it open leaked into later tests

Before

  • packages/lexical-react/src/tests/unit/LexicalTypeaheadMenuPlugin.test.tsx — 1 failed | 10 passed.
  • Of the three new IME composition tests, reports the query while composing without closing the menu fails (expected "vi.fn()" to be called with arguments: [ '햄' ] / Number of calls: 0), because the update listener returns early while editor.isComposing() is true and never computes the query.
  • The other two pass on main as well — they guard against the opposite regression, where the menu would close mid-composition.
image

After

  • packages/lexical-react/src/tests/unit/LexicalTypeaheadMenuPlugin.test.tsx — 11 passed.
image

Related: #7985, #7987

@vercel

vercel Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 7, 2026 6:15am
lexical-playground Ready Ready Preview Aug 7, 2026 6:15am

Request Review

@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 Aug 7, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Aug 7, 2026
@etrepum

etrepum commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

@mayrang do you have any thoughts on this one?

@mayrang

mayrang commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Looks good to me. The original isComposing() guard was too wide — it kept the menu from closing, but also froze the query. Wrapping just the close calls is the right fix.

During IME, lexical's RangeSelection.isCollapsed() stays true (anchor === focus after insertText), so the trigger match and onQueryChange path works fine without the early return. Leaving registerEditableListener calling closeTypeahead() directly also makes sense — going non-editable should close the menu regardless.

Unrelated to this PR but I noticed tryToPositionRange returns boolean while the check on line 247 is isRangePositioned !== null — always true. Before this change the path was unreachable during composition, now it runs. Probably worth a separate if (isRangePositioned) fix.

@etrepum
etrepum added this pull request to the merge queue Aug 7, 2026
Merged via the queue into meta:main with commit cdf7a92 Aug 7, 2026
52 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

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

3 participants