Skip to content
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

perf(core): if a transaction is a no-op do not attempt to re-apply it #4535 #5449

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-worms-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/core": patch
---

If a transaction results in the exact same editor state (either filtered out or failed to apply) then do not attempt to re-apply the same editor state and do not emit any events associated to the transaction
8 changes: 8 additions & 0 deletions packages/core/src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,17 @@ export class Editor extends EventEmitter<EditorEvents> {
return
}

const prevState = this.state
const state = this.state.apply(transaction)
const selectionHasChanged = !this.state.selection.eq(state.selection)

// The transaction did not change the editor’s state.
// It may have been filtered
if (prevState === state) {
// Skip the update
return
}

this.emit('beforeTransaction', {
editor: this,
transaction,
Expand Down