Editor.js: [Bug] Problem with editor.destroy() in 2.19

Created on 15 Oct 2020  路  4Comments  路  Source: codex-team/editor.js

const editor = new EditorJS()

editor.destroy(); // TypeError: null is not an object (evaluating 'this.flipper.deactivate')

Steps to reproduce:

  1. Go to example/example.html
  2. Call editor.destroy() from the console
  3. You'll see TypeError: null is not an object (evaluating 'this.flipper.deactivate')

Expected behavior:

The editor destroys correctly.

Device, Browser, OS:

Safari

Editor.js version:

2.19

bug important

Most helpful comment

Do you plan to create a release with this bugfix?

yes

All 4 comments

On editor destroy, we loop through moduleInstances and call destroy of each module.
https://github.com/codex-team/editor.js/blob/43032ebaac6a8b9a67c9bf2ada5adc0f8592d546/src/codex.ts#L85

moduleInstances contain both BlockSettings and Toolbar
https://github.com/codex-team/editor.js/blob/next/src/types-internal/editor-modules.d.ts

So when looping through the moduleInstances, we call BlockSettings destroy. Now as the loops continues, it reaches Toolbar and calls the destroy of it which agains attempts to destroy BlockSettings. This causes the editor to crash as BlockSettings was already destroyed. (Same with Toolbox)
https://github.com/codex-team/editor.js/blob/43032ebaac6a8b9a67c9bf2ada5adc0f8592d546/src/components/modules/toolbar/index.ts#L383

Is it ok to destroy an Editor level module from within another module? If yes, then should BlockSettings and Toolbox be contained within Toolbar and accessed only via Editor.Toolbar.BlockSettings?

Do you plan to create a release with this bugfix?

Do you plan to create a release with this bugfix?

yes

waiting for the release @neSpecc

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cossssmin picture cossssmin  路  3Comments

ar53n picture ar53n  路  3Comments

vsvanshi picture vsvanshi  路  4Comments

hata6502 picture hata6502  路  3Comments

talyguryn picture talyguryn  路  3Comments