Binding a CSS variable in a component that uses a Ref on a loop of a custom component breaks Hot Module Reload
Vue version
3.3.8
Link to minimal reproduction
https://github.com/noahgregory-basis/nuxt-test
Steps to reproduce
- Run
npm run dev
to start the dev server. - Open browser to dev server and open the developer console.
- Comment out the
console.log
line inBar.vue
and save to trigger hot module reload. - Observe the error: Uncaught (in promise) TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
This appears to happen in the useCssVars
helper function. Specifically inside the onMounted
callback, at the line (as seen below in the bundle):
ob.observe(instance.subTree.el.parentNode, { childList: true });
What is expected?
No error occurs when hot-reloading.
What is actually happening?
Error occurs when hot-reloading.
System Info
No response
Any additional comments?
I have found that two circumstances need to exist for this error to appear:
- For some custom component:
a. The component is given a
v-for
prop to render it multiple times, b. The component is given aref
prop to put the array of components in, and c. The name passed intoref
is defined as a ref in<script setup>
block; and - A variable is defined in the
<script setup>
block and is used inv-bind
in the<style>
block.
Given where the error occurs, it seems item 2 is more of a culprit than item 1. However, item 1 still needs to exist, so it must be at least somewhat at fault. How, though, I have no idea.
Probably a duplicate of https://github.com/vuejs/core/issues/9264