`Uncaught TypeError: Cannot read property 'insertBefore' of null` when (mis?)use `v-if` with 3rd-party JS library
Version
3.1.4
Reproduction link
Steps to reproduce
Take library Choices.js for example:
- Use
v-if
in<option>
(This is what the doc of choices.js ask user to do)
<template>
<select>
<option value="" v-if="OPTIONS.length === 0">I'm a placeholder</option>
</select>
</template>
- Initialize
Choices.js
instance. - Dynamically add options from
Choices.js
instance. Exploded.
What is expected?
No error, or a comprehensible error message emitted by Vue.
What is actually happening?
Uncaught (in promise) TypeError: Cannot read property 'insertBefore' of null
- Some other libraries which manipulate DOM, such as the famous
select2
jQuery plugin, have similar error. - I don't sure if this is a bug, or user indeed should not use
v-if
like this. If it is the later one, I also don't sure whether the error message emitted by Vue could be more comprehensible to user to know what exactly happened. (I spent 4 hours to find out where exactly this problem is.)