slab / parchment

Generalized state model for rich-text editors to interface with browser DOM
BSD 3-Clause "New" or "Revised" License
640 stars 146 forks source link

TypeError: Cannot read property 'mutations' of undefined #87

Open antonioribeiro opened 4 years ago

antonioribeiro commented 4 years ago

I believe we have traces of this problem happening in a lot of places, and it should be kind of easy to fix, but maybe not really to understand:

https://github.com/quilljs/parchment/issues/14 https://github.com/quilljs/quill/issues/2312 https://github.com/area17/twill/issues/458 https://github.com/quilljs/quill/issues/889

This error is occurring in Quill when the list of nodes are, somehow, problematic.

This is a simple console.log() of blot.domNode:

image

As you can see the error occurs while processing a <br>, on line 121:

image

Because that line is compiled to

if (blot.domNode[Registry.DATA_KEY].mutations == null) ...

But it could be prevented by just:

if (blot.domNode[Registry.DATA_KEY] && blot.domNode[Registry.DATA_KEY].mutations == null) ...

Because what happens is that this particular node doesn't exists, so a mutation property is, of course, undefined.

monkeyphysics commented 3 years ago

Is there any hotfix available?
It's hard to apply the change to the minified Quill code, and don't want to run unminified in production.

ackmanx commented 3 years ago

Although using that guard prevents Quill from crashing in this instance, I also noticed that it clears out the toolbar of selected formats and then when I try and delete any text I get a new error... 'leaf.position is not a function'.

ackmanx commented 3 years ago

This is my barebones example demonstrating the problem: https://codepen.io/ackmanx/pen/xxqzPyy?editors=1111

nghuuphuoc commented 2 years ago

I got the same issue. Subscribe to this!

parthibanloganathan commented 2 years ago

Same issue

wangziweng7890 commented 1 year ago

same issue

uniquejava commented 6 months ago

Same here, I hacked some Shift+Enter to insert LineBreak <br> tag(Not Easy but worked) and then new problem is coming, that is undo(Command+Z) throws me this Mutation Error, what a journey!