-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: registerUpdateListener fires the function once more when the editor mounts or unmounts #7198
Comments
Why don’t you include a reference to the editor in your callback and ignore it if it doesn’t match the editor in your array? Using React’s key property correctly might also fix this for you |
You can also have a ref that tracks if the editor is unmounted and return from that debounced function body when that has happened. |
Thanks for the suggestions! We want to keep the debounced function whose timer has been started when the editor is unmounted, so that any changes made right before the editor’s removed get saved to our DB. That said, we’re still having issues with the debounced function running as the editor is being unmounted—it’s causing problems in our app. |
I've tried assigning a unique key for each editor, but it didn't work. |
Certainly passing the key through to your callback so you can verify that the update came from the editor you expected to should work. That said, if you can provide a runnable reproduction of this issue (e.g on stackblitz or codesandbox) I can look into it further. |
Lexical version: 0.24.0
Steps To Reproduce
Add an
registerUpdateListener
of aneditor
object fromuseLexicalComposerContext
in auseEffect
hook.Code example:
The current behavior
After updating lexical version from 0.18.0 to 0.24.0,
registerUpdateListener
fires the function passed as a parameter whenever the editor mounts or unmounts.This execution of the function happens before the cleaner of the
useEffect
runs, making it hard to handle the execution properly.The expected behavior
listener
function doesn't run whenever the editor mounts or unmounts.registerUpdateListener
to disable this functionalityImpact of fix
We are using an index-based approach to perform CRUD operations on an editor (in reality the parent of the editor).
When an editor is removed from the array, the index shifts and points to a different editor.
Since we are using
lodash.debounce
inside the update listener function, the debounced update from the removed editor ends up overwriting the data of a newly added editor in the DOM.We are unable to selectively cancel the debounced function when the editor unmounts.
The text was updated successfully, but these errors were encountered: