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
- perf(core): if a transaction is a no-op do not attempt to re-apply it #4535 — committed to ueberdosis/tiptap by nperez0111 2 years ago
- perf(core): if a transaction is a no-op do not attempt to re-apply it #4535 — committed to ueberdosis/tiptap by nperez0111 2 years ago
- perf(core): if a transaction is a no-op do not attempt to re-apply it #4535 — committed to ueberdosis/tiptap by nperez0111 2 years ago
- perf(core): if a transaction is a no-op do not attempt to re-apply it #4535 (#5449) — committed to ueberdosis/tiptap by nperez0111 2 years ago
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:
beforeTransactioneventtransactionsfield returned bystate.applyTransaction()is empty, then therootTrwas filtered out and we can return there.transactionevent but with a flag that lets the caller know it was filtered out. Not sure if that’s useful to the caller.transactionevent.selectionUpdatecan continue as istransactionsarray to determine offocus, andblurneed to be published, since technically one transaction might undo a previous transaction’s changes.updateneeds to be called rather than trying to figure that out while looping through thetransactionsarrayThere’s a question about how to publish any appended transactions. We can add an
appendedTransactionsfield alongside the currenttransactionfield, which would simply betransactions.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
falseto theeditor.setEditablefixes your problem.repro: https://codesandbox.io/s/objective-fermi-wnyrj5?file=/src/App.js
Could you add more infos?
https://codesandbox.io/s/rough-butterfly-k2t855?file=/src/App.js
This minimal setup doesn’t seem to have any unnecessary
onUpdatecalls so I wonder if it’s an extension that was introduced.