dispatch=undefined in createCan() results in dispatch attempts during can() #3025
Closed
2 tasks done
Labels
Type: Bug
The issue or pullrequest is related to a bug
What’s the bug you are facing?
I've hit a weird issue that requires a combination of three things:
a. It needs to have higher priority than
Paragraph
.editor.can().toggleBulletList()
(oreditor.can().toggleOrderedList()
)Which browser was this experienced in? Are any special extensions installed?
Latest Chrome on macOS, but unlikely to be browser-specific.
How can we reproduce the bug on our side?
Here's a sandbox those shows the issue: https://codesandbox.io/s/tiptap-dispatch-repro-gc54w8?file=/src/App.js
Try making a selection like this:
editor?.can().toggleBulletList()
will cause aRangeError
, specifically from here:tiptap/packages/core/src/commands/clearNodes.ts
Lines 41 to 45 in e2f8747
The
tr.setNodeMarkup
call throws:See relevant PM code. At the point of error,
type
is the NodeType forMyContainer
, andnode.content
is a fragment containing TextNode(s).Can you provide a CodeSandbox?
No response
What did you expect to happen?
I'm surprised that a
can()
call couldthrow
an error at all, regardless of the schema.clearNodes
checks for whether it should dispatch:tiptap/packages/core/src/commands/clearNodes.ts
Lines 20 to 22 in e2f8747
But in this case,
dispatch
is() => void 0
. That value comes fromCommandManager.buildProps
:tiptap/packages/core/src/CommandManager.ts
Lines 141 to 143 in e2f8747
shouldDispatch
is true. This is surprising to me. Here's the relevant part ofCommandManager.createCan
:tiptap/packages/core/src/CommandManager.ts
Lines 108 to 112 in e2f8747
dispatch
is set toundefined
. Even explicitly passedundefined
arguments are subject to defaults (today I learned :/ apparently JavaScript can still surprise me), which means thethis.buildProps(tr, dispatch)
call getsshouldDispatch
set to true.A year and a half ago in ca8d1a4 the
dispatch
value increateCan
was changed fromfalse
toundefined
:That led to this state of affairs, I think.
Anything to add? (optional)
The following appears to fix this issue, and all tests pass locally, so I'll open a PR:
Did you update your dependencies?
Are you sponsoring us?
The text was updated successfully, but these errors were encountered: