-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: onUpdate fires when no content update has occurred #4535
Comments
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 |
Thanks for the speedy reply and the codesandbox @bdbch. It's quite strange.
I also thought it might be due to I'll have to loop back on this I guess. Thanks again for the speedy reply! |
Indeed I cannot repro this today. I don't know what the issue was. I'll re-open if I discover actionable details. In the meantime I'm using this alternative:
|
Whoops a flaw in my testing. I seem to have discovered the cause. Running Here's a repro: https://codesandbox.io/s/zealous-kate-d6s224?file=/src/App.js |
I think that adding a second argument repro: |
Ah jeez I didn't notice that in the docs. Thanks @akucinskii I really don't think that it makes sense to default that to |
This can occur in other cases, but I'm not really clear on the nature of those. It seems like if modifications are made to the document that don't actually affect the serializable content it still fires. I guess this is the intended behavior but the docs could use an update. Maybe it just checks for |
|
So this is the function that handles the update events: tiptap/packages/core/src/Editor.ts Lines 449 to 457 in b012471
I think we can make a relatively easy optimization here, if the editor.state is equal to the editor.state from before, that means none of the transactions could be applied and we can just skip calling the rest of the function. But to be clear, this event is emitted only when the transaction does have changes or when setEditable is modified without the second parameter: tiptap/packages/core/src/Editor.ts Line 183 in b012471
For that reason, I don't think that the original issue is valid I made a draft of this here: #5449 |
We don't even need to compare the states. If we use const {state, transactions} = this.state.applyTransaction(transaction)
const trWasApplied = transactions.includes(transaction)
if (!trWasApplied) {
return
} |
@jpobley that is definitely useful to know! |
Would we need to keep track of all appended transactions and check for all of them to be included in the transactions array then? |
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 My two cents:
There's a question about how to publish any appended transactions. We can add an |
Appreciate the thorough thoughts on this. We are actually planning on a tiptap v3 so if we want to make a breaking change I think it'd better fit there than mess with it in the maintenance version. If you would like, feel free to make a PR with your suggestions otherwise I'll throw this in a backlog of tasks for V3 and we can get to it eventually |
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?
Are you sponsoring us?
The text was updated successfully, but these errors were encountered: