Skip to content

[lexical-react] Feature: optional async onClose for LexicalTypeaheadMenuPlugin#8489

Merged
etrepum merged 8 commits into
facebook:mainfrom
abhinavgautam01:fix/7521-typeahead-async-onclose
May 17, 2026
Merged

[lexical-react] Feature: optional async onClose for LexicalTypeaheadMenuPlugin#8489
etrepum merged 8 commits into
facebook:mainfrom
abhinavgautam01:fix/7521-typeahead-async-onclose

Conversation

@abhinavgautam01

@abhinavgautam01 abhinavgautam01 commented May 10, 2026

Copy link
Copy Markdown
Contributor

Closes #7521

[lexical-react] Feature: optional async onClose for LexicalTypeaheadMenuPlugin

Description

Current behavior: When the typeahead menu closed, resolution was cleared in a way that did not line up with how onClose might need to run (e.g. if callers need to finish async work like an exit animation before the menu is torn down). onClose was also easy to treat as always fire-and-forget.
This PR:

  • Types onClose as () => void | PromiseLike<void>.
  • Calls onClose when a menu was open, then clears resolution:
    • If onClose() returns a thenable, the plugin waits for it (.then(finish, finish)) before clearing resolution, so the menu can stay mounted until async work completes.
    • If it returns void / a non-thenable value, setResolution(null) runs in the same synchronous turn after onClose returns—keeping prior “sync close” timing for existing callers.
  • Adds unit tests using EditorRefPlugin, a compact root setup, and DELETE_CHARACTER_COMMAND (with a small Selection.prototype.modify shim in jsdom where needed).

Test plan

Before

  • No coverage ensuring async onClose completes before the menu unmounts; sync ordering was easy to regress.

After

  • pnpm exec vitest --project unit --no-watch run packages/lexical-react/src/__tests__/unit/LexicalTypeaheadMenuPlugin.test.tsx
  • pnpm run ci-check (after Prettier fix on the test file)

@vercel

vercel Bot commented May 10, 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, Comment May 15, 2026 5:17pm
lexical-playground Ready Ready Preview, Comment May 15, 2026 5:17pm

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 May 10, 2026

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a new feature, not a bug fix, so the title and description should reflect that.

For backwards compatibility the timing probably shouldn't change unless a promise is returned. Reordering setResolution after the callback should be is fine, but we should do it sync unless there's a promise to wait for.

Comment thread packages/lexical-react/src/__tests__/unit/LexicalTypeaheadMenuPlugin.test.tsx Outdated
Comment thread packages/lexical-react/src/__tests__/unit/LexicalTypeaheadMenuPlugin.test.tsx Outdated
Comment thread packages/lexical-react/src/__tests__/unit/LexicalTypeaheadMenuPlugin.test.tsx Outdated
Comment thread packages/lexical-react/src/LexicalTypeaheadMenuPlugin.tsx Outdated
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label May 11, 2026
@abhinavgautam01 abhinavgautam01 changed the title [@lexical/react] Bug Fix: Await async onClose before unmounting typeahead menu feat(react): optional async onClose for LexicalTypeaheadMenuPlugin May 11, 2026
@etrepum etrepum changed the title feat(react): optional async onClose for LexicalTypeaheadMenuPlugin [lexical-react] Feature: optional async onClose for LexicalTypeaheadMenuPlugin May 11, 2026
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

ping @etrepum

@etrepum

etrepum commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Pinging for review attention is not a good strategy, I can see perfectly fine which PRs are open and don’t need extra notifications. This kind of behavior has the opposite effect and will lower the priority.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Pinging for review attention is not a good strategy, I can see perfectly fine which PRs are open and don’t need extra notifications. This kind of behavior has the opposite effect and will lower the priority.

sorry for that...i will keep that in mind...

Comment thread packages/lexical-react/src/shared/LexicalMenu.tsx Outdated
Comment thread packages/lexical-react/src/LexicalTypeaheadMenuPlugin.tsx
Comment thread packages/lexical-react/src/LexicalTypeaheadMenuPlugin.tsx Outdated
Co-authored-by: Bob Ippolito <bob@redivi.com>
@etrepum etrepum added this pull request to the merge queue May 17, 2026
Merged via the queue into facebook:main with commit 5ba845b May 17, 2026
42 checks passed
@etrepum etrepum mentioned this pull request May 28, 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.

Feature: LexicalTypeaheadMenuPlugin: Allow for asynchronous onClose function

2 participants