Trigger Listeners for Node subclasses #6075
aleksandr-lapushkin
started this conversation in
Ideas
Replies: 2 comments
-
A slight note on this: it seems like this behavior already exists for node transforms, just not mutation listeners: lexical/packages/lexical/src/LexicalEditor.ts Line 873 in b5fa87d I'll see if perhaps aligning the behaviors will yield the right results. |
Beta Was this translation helpful? Give feedback.
0 replies
-
FWIW: #6076 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
An issue I bumped into recently while building an editor using Lexical is that mutation and node transform listeners registered for nodes won't trigger for subclasses of the same node.
Specifically, this had to do with the Lexical Table plugin for React. The official plugin registers a few utilities via
applyHandlers
. As an example, this is done via a mutation listener here:lexical/packages/lexical-react/src/LexicalTablePlugin.ts
Line 143 in b5fa87d
I bumped into this issue when I had to extend and replace the default implementation of
TableNode
andTableCellNode
to augment the behavior ofexportDOM
. After registering my nodes and setting up replacements, all of the node-specific listeners won't fire for my custom nodes. To get around this I have to essentially copy-paste all of the setup code into my own custom plugin, which just seems extremely brittle.The actual reason why it doesn't trigger isn't the issue - listeners use the node's type, which is perfectly reasonable for most cases. However, extending default behavior feels unnecessarily complicated with the current mechanics. I cannot rely on existing official code and have to go and manually copy-paste code, which would then also prevent me from getting any future changes.
My initial reaction was to suggest that listeners trigger for subclasses too. However, I'm curious whether there's perhaps a better solution to this type of problem instead, seeing how this might be a pretty large (potentially breaking) change?
Beta Was this translation helpful? Give feedback.
All reactions