tiptap: [Bug]: onUpdate fires when no content update has occurred

Which packages did you experience the bug in?

core

What Tiptap version are you using?

2.1.12

What’s the bug you are facing?

This makes listening to the editor for updates extremely tedious and expensive in terms of both memory and CPU since we need to store an external reference and then compare against it.

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

onUpdate should not fire at editor creation time, but it does.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

It’s probably good practice and more accurate to look at the appended transactions. However, they’ve been ignored up until now so maybe it doesn’t matter and can wait until a major rev since the behavior of dispatchTransaction() will change.

My two cents:

  • Publish beforeTransactionevent
  • If the transactions field returned by state.applyTransaction() is empty, then the rootTr was filtered out and we can return there.
    • Maybe still publish the transaction event but with a flag that lets the caller know it was filtered out. Not sure if that’s useful to the caller.
  • Otherwise, publish the transaction event.
  • selectionUpdate can continue as is
  • We’ll then need to loop through the transactions array to determine of focus, and blur need to be published, since technically one transaction might undo a previous transaction’s changes.
  • Finally, it’s probably easier to compare states at this point in order to determine if update needs to be called rather than trying to figure that out while looping through the transactions array

There’s a question about how to publish any appended transactions. We can add an appendedTransactions field alongside the current transaction field, which would simply be transactions.slice(1). There’s an argument to be made for keeping the transactions together, but this way won’t be a breaking change to the event data interface. 🤷

This can be closed, I implemented it for v3

@jpobley that is definitely useful to know! Does beg the question of what to do with appended transactions, but will look into it more later

I think that adding a second argument false to the editor.setEditable fixes your problem.

repro: https://codesandbox.io/s/objective-fermi-wnyrj5?file=/src/App.js

Could you add more infos?

  • Do you use collab?
  • When do these onUpdate events occur?
  • Was this introduced at 2.1.12 or did you experienced this earlier?
  • Are there any new extensions you are using which could cause those update calls?

https://codesandbox.io/s/rough-butterfly-k2t855?file=/src/App.js

This minimal setup doesn’t seem to have any unnecessary onUpdate calls so I wonder if it’s an extension that was introduced.