Quill: Custom blots cause a mutation error on undo/redo

Created on 15 Sep 2018  路  3Comments  路  Source: quilljs/quill

When I create custom blocks, no matter what tag name I use, I get the following error when doing things like undo and toggling formats:

quill.js:7166 Uncaught TypeError: Cannot read property 'mutations' of undefined

Steps for Reproduction

  1. Visit https://codepen.io/Ravenstine/pen/PdBxbw
  2. Select the text "dolor sit amet" and click the button that says foo.
  3. Select the text "sit" and click the button that says bar.
  4. Select the text "dolor sit amet" and delete it.
  5. Attempt to undo and redo the changes you made.

Expected behavior:
No mutation errors and the undo history remains intact.

Actual behavior:
Mutation error occurs and it seems like the undo history is often messed up once the error happens.

Platforms:

Chrome 69.0.3497.92 on macOS High Sierra.

Version:

1.3.6

Most helpful comment

@Ravenstine After having a look into the sources I found a dirty workaround that fixes the issue for me: I'm manually adding the new blot name of the inline element to the Inline.order array.

Inline.order.splice(Inline.order.indexOf('bold'), 0, 'foo');

see: https://github.com/quilljs/quill/blob/develop/blots/inline.js#L49-L59

All 3 comments

@Ravenstine After having a look into the sources I found a dirty workaround that fixes the issue for me: I'm manually adding the new blot name of the inline element to the Inline.order array.

Inline.order.splice(Inline.order.indexOf('bold'), 0, 'foo');

see: https://github.com/quilljs/quill/blob/develop/blots/inline.js#L49-L59

@Ravenstine try to add additional condition into if statement blot.domNode[Registry.DATA_KEY] &&
if (blot.domNode[Registry.DATA_KEY] && blot.domNode[Registry.DATA_KEY].mutations == null) { // @ts-ignore blot.domNode[Registry.DATA_KEY].mutations = []; }

I just had the same issue. It will be good to have a solution from the quill side.

@toao thanks for the workaround. It did the job for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CHR15- picture CHR15-  路  3Comments

GildedHonour picture GildedHonour  路  3Comments

scottfr picture scottfr  路  3Comments

Yves-K picture Yves-K  路  3Comments

rsdrsd picture rsdrsd  路  3Comments