Mismatched transaction error #6097
-
These errors are the bane of my existence when using TipTap . I find it extremely difficult to understand the transaction flow, especially when chaining and using the With a simple function like this: createRule:
(attrs: RuleAttrs) =>
({ editor }) => {
if (!editor) return false;
const { from, to } = editor.state.selection;
return editor
.chain()
// removed previous chain commands for simplicity (still get the error)
.command(({ tr, dispatch }) => {
let replaced = false;
tr.doc.nodesBetween(from, to, (node, pos) => {
const nodeEnd = pos + node.nodeSize - 1;
if (!node.isText) {
return;
}
if (
(from > pos && from < nodeEnd) ||
(to > pos && to < nodeEnd)
) {
const type = editor.schema.nodes.inlineRuleNode;
const content = tr.doc.slice(from, to);
const node = type.create(attrs, content.content);
// This is the problem transaction here
tr.replaceRangeWith(from, to, node);
replaced = true;
return false;
}
});
return replaced;
})
.focus()
.run();
}, The errorIt is thrown from
Inspecting the ie. it has no steps, no mappings The transaction has the "After" state ie. the doc has my newly inserted What I've tried
Other informationThis command is called from a bubble menu in my editor, which then opens a drawer. This drawer takes the users focus from the editor, and when they press the "Save" button, it runs the command. So my theory now is that this focus shift is causing the problem, ie. when the focus returns to the editor - Tip tap/ PM is sending a selection transaction, and this transaction is out of sync with the EditorState? Versions
Update:Okay i am going to raise a bug, because this occurs with something as trivial as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Okay I have found the source of the issue.. You cannot use ie. --- createRule:
--- (attrs: RuleAttrs) =>
--- ({ editor }) => {
--- const { from, to } = editor.state.selection;
+++ createRule:
+++ (attrs: RuleAttrs) =>
+++ ({ chain, tr, state }) => {
+++ const { from, to } = tr.selection;
This is extremely annoying behaviour, and I have no clue why those two aren't equivalent, nor why this is not documented. |
Beta Was this translation helpful? Give feedback.
Okay I have found the source of the issue..
You cannot use
editor
from the commandie.
This is extremely annoying behaviour, and I have no clue why those two aren't equivalent, nor why this is not documented.