You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: DecoratorNode's component does not call useEffect cleanup until after remount #2993
DecoratorNode.decorate can return JSX element to render React components. Surprisingly, when you delete a DecoratorNode, useEffect cleanup functions are not called. Even more surprisingly, when you undo the delete, the useEffect cleanup function is called.
Not sure where your React 18 comment went but I tested with React 18 in the repro and same issue. Will have a look at LexicalUpdates code and see if I can make sense of it :)
I had hard time a few days ago with the decorator node deletion. At some point, in my app, some decorator nodes were deleted whereas it should not be deleted, It was then rendered again. I don't have bandwith for now to setup a reproducer, but though useful to mention that. That behavior can be reproduced in the playground if you console.log in the cleanup function fo a useEffect.
And yes, I have seen that pendingDecorators was in the picture (the first deleted decorator node was removed, then the cleanup functions were called on the second decorator node delettion, with potentially other non deleted nodes by the user being deleted and directly re-rendered (which in my case was giving issues to the state I was maintaining in the decorator nodes).
Activity
trueadm commentedon Sep 12, 2022
Ah, I think I might know why this is happening.
https://github.com/facebook/lexical/blob/main/packages/lexical/src/LexicalUpdates.ts#L511
We are capturing the
pendingDecoratorsbefore we garbage collect any decorators. Doh.We should probably move this line down to where we actually use it.
https://github.com/facebook/lexical/blob/main/packages/lexical/src/LexicalUpdates.ts#L566
Feel free to put up a PR if you'd like to contribute to Lexical :) thanks for finding the issue too!
adri1wald commentedon Sep 12, 2022
Not sure where your React 18 comment went but I tested with React 18 in the repro and same issue. Will have a look at LexicalUpdates code and see if I can make sense of it :)
echarles commentedon Sep 12, 2022
I had hard time a few days ago with the decorator node deletion. At some point, in my app, some decorator nodes were deleted whereas it should not be deleted, It was then rendered again. I don't have bandwith for now to setup a reproducer, but though useful to mention that. That behavior can be reproduced in the playground if you console.log in the cleanup function fo a useEffect.
And yes, I have seen that pendingDecorators was in the picture (the first deleted decorator node was removed, then the cleanup functions were called on the second decorator node delettion, with potentially other non deleted nodes by the user being deleted and directly re-rendered (which in my case was giving issues to the state I was maintaining in the decorator nodes).
trueadm commentedon Sep 12, 2022
I believe the changes I mentioned above should help in both your cases. I’m on parental leave right now and on my phone otherwise I’d put up a PR.