NodeView destroy method is called when setting node attribute

Is it expected for an instance of NodeView to be destroyed when dispatching a transaction that sets an attribute on it using setNodeAttribute? Whenever that happens, the nodeView seems to be rebuilt and the destroy method is called. Is this due to the Prosemirror having ‘immutable’ data structures?

I can accomplish what I want by keeping track of NodeView positions and checking if they get deleted in onTransaction, but I’m wondering if this is the expected behavior since the destroy method would be a bit easier to use.

As an aside does anyone know a better way of getting the initial position of a NodeView after a transaction? getPos gives us the position when it gets created, but AFAICT there’s no way to quickly figure out what the position is after the whole transaction or what step in the transaction the getPos value refers to. I end up having to iterate through all the steps of a transaction to find the first step, and map the position through the remaining steps. Seems like there should be a more elegant way to accomplish that.

Yes, it is. Though if you define an update method you should be able to handle the change in that without redrawing the whole node view.