[lexical-react] Feature: optional async onClose for LexicalTypeaheadMenuPlugin#8489
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
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.
|
ping @etrepum |
|
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... |
Co-authored-by: Bob Ippolito <bob@redivi.com>
Closes #7521
[lexical-react] Feature: optional async onClose for LexicalTypeaheadMenuPlugin
Description
Current behavior: When the typeahead menu closed,
resolutionwas cleared in a way that did not line up with howonClosemight need to run (e.g. if callers need to finish async work like an exit animation before the menu is torn down).onClosewas also easy to treat as always fire-and-forget.This PR:
onCloseas() => void | PromiseLike<void>.onClosewhen a menu was open, then clearsresolution:onClose()returns a thenable, the plugin waits for it (.then(finish, finish)) before clearingresolution, so the menu can stay mounted until async work completes.setResolution(null)runs in the same synchronous turn afteronClosereturns—keeping prior “sync close” timing for existing callers.EditorRefPlugin, a compact root setup, andDELETE_CHARACTER_COMMAND(with a smallSelection.prototype.modifyshim in jsdom where needed).Test plan
Before
onClosecompletes 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.tsxpnpm run ci-check(after Prettier fix on the test file)