cnu4 / vue-codemirror-lite

Lightweight Codemirror Component for Vue.js
https://cnu4.github.io/vue-codemirror-lite/
MIT License
281 stars 48 forks source link

TypeError: Cannot read property 'removeChild' of null #17

Closed yianpuodiaotu closed 6 years ago

yianpuodiaotu commented 6 years ago

when this component user with v-if:

<codemirror v-if="flag" :value="code" ></codemirror>

when the value of flag turns to false from true, the console of explorer prints error as follow:

app.js:101328 TypeError: Cannot read property 'removeChild' of null
    at CodeMirror$1.cm.toTextArea (app.js:19030)
    at VueComponent.beforeDestroy (app.js:3339)
    at callHook (app.js:102506)
    at VueComponent.Vue.$destroy (app.js:102288)
    at destroy (app.js:103721)
    at invokeDestroyHook (app.js:105258)
    at removeVnodes (app.js:105274)
    at updateChildren (app.js:105379)
    at patchVnode (app.js:105451)
    at updateChildren (app.js:105337)
cnu4 commented 6 years ago

The lifecycle function beforeDestroyed will be called after DOM of component was removed.

And I call function toTextArea to destroy the CodeMirror instance in beforeDestroyed. toTextArea will look for the parent node. But at that moment DOM of component was removed from document. So the error occurred.