Append Transaction infinite loops

I’ve got a couple of plugins that do some post transaction cleanup that mostly includes setting attributes, but in one case inserts a node if it isn’t present in the document.

For some reason when both of them fire on the same change they start calling each other over and over again until the browser runs out of memory and crashes.

I think I’ve got my access to CodePen et al resolved and will try to put together a repeatable example, but thought I’d ask here in case this was an obvious no no on my part.

Sorry for so many posts lately, I’m trying to get some new features in front of my users while they’re all stuck producing newscasts and podcasts from home.

Each plugin will get a chance to append another transaction for the transactions appended by other plugins, so yes, if they aren’t careful to avoid creating a transaction when it isn’t necessary (or actively keep inverting each other’s effects), you will get an infinite loop. Usually this can be solved by thinking a bit harder about when you can avoid appending a new transaction.

That does seem to have been the trick here. I’m going back through now and adding better checks by diffing my planned attrs against the nodes I’m modifying. Is there a simple way to see what nodes a step applies to that I’m missing?

Also, would it be possible/reasonable to add a check to Steps/Transactions to bail if they make no change to their document (such as applying attrs that haven’t changed to a Node)?

You can iterate over the range it touches with nodesBetween (but if there are multiple steps that’s a little more tricky, since you have to map the positions from earlier steps forward).

No, that’s the responsibility of the code creating the steps/transactions.

OK, probably safest to do what I’m doing which is check the whole doc and then compare attrs before firing off my transaction. So far it seems to perform well and it seems less likely to miss a trick.

That’s what I figured, but wouldn’t have minded being wrong :slightly_smiling_face: