wiris / html-integrations

The official JavaScript library for MathType, the leading formula editor and equation writer for the web by Wiris
https://wiris.com/solutions/integrations/html-editors/
MIT License
78 stars 53 forks source link

[CKEditor5] MathType plugin throws error when `editor.sourceElement` is not defined #829

Open DawidKossowski opened 1 year ago

DawidKossowski commented 1 year ago

Description

When using an editor that doesn't have the sourceElement property, the MathType plugin throws an error during the destroy process.

We utilize various versions of editors, such as the headless editor in our internal features or the Multi-root editor, which do not include the sourceElement property. This results in error since the thecurrentInstance variable in the theMathType plugin is not defined (the plugin attempts to destroy currentInstance, which is undefined).

Reference: https://github.com/wiris/html-integrations/blob/stable/packages/ckeditor5/src/plugin.js#L68C5-L68C20

It could be simply fixed by adding the if statement:

destroy() { // eslint-disable-line class-methods-use-this
    if( currentInstance ) {
        currentInstance.destroy();
    }
 }

Environment

Which version of MathType does this happen in?

Latest

What is the relevant software and their versions?

CKEditor5

Steps to reproduce

  1. Create multi-root editor.
  2. Add MathType to the editor plugins.
  3. Call editor.destroy().

Expected result

The editor should be destroyed without errors.

Actual result

The error is thrown. TypeError: Cannot read properties of undefined (reading 'removeEvents') at MathType.destroy

Mgsy commented 1 year ago

The same issue can be reproduced with the TrackChangesData plugin and calling one of its methods.