[lexical] Feature: LexicalEditor RootListener and EditableListener can return unregister callbacks#8219
Merged
etrepum merged 5 commits intofacebook:mainfrom Mar 14, 2026
Merged
Conversation
…n return unregister callbacks
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ivailop7
approved these changes
Mar 14, 2026
levensta
pushed a commit
to levensta/lexical
that referenced
this pull request
Mar 14, 2026
…n return unregister callbacks (facebook#8219)
etrepum
added a commit
to etrepum/lexical
that referenced
this pull request
Mar 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
LexicalEditor.registerRootListener and registerEditableListener can now optionally return an unregister callback that is called before each consecutive change and on unregister.
It's a common pattern to set up additional services that are only available based on the editor state, for example when it is attached to the DOM you may want to set up listeners on the root element or its containing document or window. It should also be easy to correctly clean up those listeners. The current pattern is something like this:
If the root listener is permitted to return an optional unregister directly, this becomes much less convoluted:
The inspiration from this comes from how effect() works with preact signals
Test plan
New unit tests, all existing unit and e2e tests pass with no change.