codex-team / editor.js

A block-style editor with clean JSON output
https://editorjs.io
Apache License 2.0
28.53k stars 2.08k forks source link

Vue component plugin unmount error #2459

Open andrei4002 opened 1 year ago

andrei4002 commented 1 year ago

Not sure if it's related to my previous issue, but there's a second problem happening when running my vue component as a plugin (I can only seem to reproduce it when the vue component plugin block is the first block, and in some conditions mentioned below)

I created a demo repo to illustrate the issue (use the vue-unmount-error branch) https://github.com/andrei4002/editorjs-test

The scenario is

  1. create the editor
  2. add some block data (example: DummyPlugin (must be first), text, text, DummyPlugin, DummyPlugin, text)
  3. (optional) hit save to have the data back on reload
  4. hit remove editor, the following error shows up:
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'nextSibling')
    at nextSibling (vue.js?v=cda635e8:9158:31)
    at removeFragment (vue.js?v=cda635e8:7675:14)
    at remove2 (vue.js?v=cda635e8:7646:9)
    at unmount (vue.js?v=cda635e8:7624:9)
    at unmountComponent (vue.js?v=cda635e8:7692:7)
    at unmount (vue.js?v=cda635e8:7593:7)
    at render2 (vue.js?v=cda635e8:7727:9)
    at Object.unmount (vue.js?v=cda635e8:5234:11)
    at VueComponentPlugin.destroy (createVueComponentPlugin.ts?t=1693215024860:17:21)
    at _F.destroy (@editorjs_editorjs.js?v=cda635e8:1774:128)

although this error comes up within vue i'm not sure entirely what part of the workflow causes it, if it's an editor issue or a vue issue, and why only when it's the first block (I'm only getting this vue error in the context of using the vue component in the editor)

a few other things i noticed:

bettysteger commented 2 months ago

I had the same error, but fixed it by having 1 single element in the vue component.

Vue allows only a single element as a template root. If multiple root elements are specified, unintended behaviors occur as follows: For single-file component with a . vue extension, Vue throws a compile error.

See https://deepscan.io/docs/rules/vue-multiple-template-root

Change your DummyPluginComponent.vue template to:

<template>
  <div>
    <div>[dummy plugin]</div>
    <input type="text">
  </div>
</template>