tiptap: [Bug]: Mod-z Not Blocked When editor.isEditable Is False
Affected Packages
core, react, @tiptap/extension-history
Version(s)
2.6.6
Bug Description
- Edit the content
- Run editor.setEditable(false)
- Press CTRL + Z
- The undo operation is performed
However, this only happens for Undo but not for Redo.
Reproduce
I was also able to reproduce it by slightly adjusting the minimal setup: https://tiptap.dev/docs/examples/basics/minimal-setup
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'
import History from '@tiptap/extension-history'
function App() {
const editor = useEditor({
extensions: [
Document,
Paragraph,
Text,
History // <-- Added History
],
content: "<p>Tiptap content</p>",
})
return (
<div className="App">
<EditorContent editor={editor} />
<button onClick={() => editor.setEditable(!editor.isEditable)}>
Toggle isEdit
</button>
</div>
);
}
export default App;
You just need to edit some content and click the button to experience the bug for yourself.
Thank you very much in advance for your help!
Browser Used
Chrome
Code Example URL
No response
Expected Behavior
Mod + Z shouldn’t change the content when the editor is read-only.
Additional Context (Optional)
No response
Dependency Updates
- Yes, I’ve updated all my dependencies.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 26 (19 by maintainers)
Alright PR is merged. You’d need to update
prosemirror-historyto see the changes. Closing this one.Hey @Nantris #5731 doesn’t seem to be working.
Created #5745 to make sure that
setEditableoverrides the initial options provided touseEditor’seditableoption.Regarding the history related issue: We’ve found out that the Prosemirror’s history plugin allows undoing when the editor is not editable. We’ve looked into this with @nperez0111 and found out a workaround for it:
What this plugin does is blocking Prosemirror’s history’s default undo event when the editor is not editable.
@Nantris thanks for the reminder. I have just created a PR that aims to fix the issue.
@Nantris between @guarmo and I we decided that it was a little too hacky to incorporate into Tiptap itself. The bug has been there for a long time.
@guarmo was going to open an issue with prosemirror-history to see if we can get this resolved upstream since we identified it to be a 1 line fix in that package
@guarmo’s change is released with v2.9.0
Those are the events that prosemirror history listens to so it would at least be consistent with what prosemirror history does so it won’t undo in that case
I also tried the following quickfix. But strangely the Mod-z function is only called when the isEditable is true.