kommitters / editorjs-undo

Undo/Redo feature for Editor.js
https://www.npmjs.com/package/editorjs-undo
MIT License
165 stars 51 forks source link

Bug when editorjs has set 'paragraph: false' #202

Closed ARH3 closed 9 months ago

ARH3 commented 1 year ago

Precheck

Description

I keep getting this error and am having a really hard time figuring out why. It happens very frequently when I use CMD+Z to try and undo something. I am trying to find a pattern of when it happens, but it happens so frequently... for example if I open an existing editorjs json file, add one space somewhere, and then hit CMD+Z, it will throw this error and remove my entire editorjs div from the DOM... it's a very disruptive error.

Error:

Uncaught (in promise) TypeError: this.constructable is not a constructor
    at n.value (editorjs@latest:8:429396)
    at new w (editorjs@latest:8:87160)
    at a.value (editorjs@latest:8:196787)
    at a.value (editorjs@latest:8:197264)
    at Object.insert (editorjs@latest:8:160489)
    at editorjs-undo:7:7470

I have a custom block as my default, called song, and set paragraph: false because I don't want it. The error points at line 7470 in the undo plugin that has t.editor.blocks.insert("paragraph", {.

This leads me to believe that this plugin might be incompatible with Editorjs instances that set paragraph: false and/or set a custom default block? However I'm not certain.

Environment

Current behavior

Editorjs crashes when I try to use CMD+Z to undo something. Happens very frequently.

Expected behavior

When I use CMD+Z, I expect the most recent action to be undone without a crash.

Additional context

I am happy to provide any more information that would be helpful to resolve the issue. Thanks!

ARH3 commented 1 year ago

Hello - just checking in to see if anyone has had a chance to review this? Thank you!

miguelnietoa commented 1 year ago

@ARH3 Yes, this seems to happen with instances that set paragraph: false.

We'll let you know when we find a fix, but feel free to create a PR if you come up with a possible solution.

MarioRodriguezS commented 9 months ago

@ARH3 Thanks a lot for reporting the issue. It was solved and the solution is now available in v2.0.24. As we were testing, the paragraph: false option is unnecessary to set a default block in the editor. However, if you keep the option, the editorjs-undo does not fail.

Please let us know if this solution proves helpful to you.