Lifecycle Methods in ProseMirror Custom Nodes and Transaction Efficiency

I’ve been working with ProseMirror and have defined custom nodes for my editor. While developing, I’ve encountered a challenge where I need to determine changes in a particular custom node. Initially, I tried using transactions to track these changes, but found it to be quite expensive and not as efficient as I’d hoped. In frameworks like React, there are component lifecycle methods that allow us to run logic when a component is created, updated, or deleted. Does ProseMirror offer similar lifecycle methods or hooks for its custom nodes? Specifically, I’m looking for a way to efficiently detect when a node is created, updated, or removed without heavily relying on transactions. Any insights, best practices, or alternative approaches related to node lifecycle in ProseMirror would be extremely helpful. Thank you!

When a node view is updated, for example if attributes or decorations on the node change, that goes through its update method. However, it changing position due to changes elsewhere in the document is not treated as an update—the node view is considered inert and left alone in that case. You can probably reframe your approach to not need to track nodes all the time, but just look up their position when you need them (either through a node view’s getPos when there is a direct interaction with the node view, or by scanning the document tree).