Subscribe on changes!

TypeError: dynamic css on dynamically imported component

avatar
Sep 21st 2023

Vue version

3.3.4

Link to minimal reproduction

https://github.com/Disservin/vue-dynamic-import-css Vue Playground Link

Steps to reproduce

npm install
npm run dev

What is expected?

I'd expect no TypeError's and that the component is properly mounted and has my dynamic class.

What is actually happening?

Open your browser console and you should be greeted by a TypeError.

TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.

System Info

No response

Any additional comments?

If you comment out the following part in the Foo Component, you get no error.

.hover-link {
    padding: v-bind("bindings.padding") px;
}

or if you remove the class from the component :class="loading ? 'classA' : 'classB'"

    <component
        :is="getComponent()"
        :id="component.id"
        :settings="component.settings"
        :class="loading ? 'classA' : 'classB'"
    />
avatar
Sep 21st 2023

It seems to me that for some reason async components are missing the parentNode and thus the error?

avatar
Sep 21st 2023

When looking at the created instances, there are actually two, I guess that makes sense ?

{uid: 6, vnode: {…}, type: {…}, parent: {…}, appContext: {…}, …}
{uid: 4, vnode: {…}, type: {…}, parent: {…}, appContext: {…}, …}

From what I can tell they are for classB and classA, respectively, but uid: 4 has no subTree.el.parentNode while uid: 6 has it?

avatar
Sep 27th 2023

I think someone reported the same bug in Pinia but with a boiled down repro so I added it here simplified

avatar
Sep 27th 2023

Ah nice, seems to be related, thanks for the smaller reproduction! I initially encountered this also with my pinia store, but then I figured out that it isnt related to pinia.
Weirdly enough you can get rid of the error in my reproduction if you do these changes

-    <component
-        :is="getComponent()"
-        :id="component.id"
-        :settings="component.settings"
-        :class="loading ? 'classA' : 'classB'"
-    />
+    <MyComp
+        :id="component.id"
+        :settings="component.settings"
+        :class="loading ? 'classA' : 'classB'"
+    />

-const getComponent = () => {
-    return defineAsyncComponent(() => Promise.resolve(VFoo));
-};

+const MyComp = defineAsyncComponent(() => Promise.resolve(VFoo));
avatar
Dec 22nd 2023

Do we have any updates on this? I reported a bug (#9617) a while ago that was then mentioned as a possible duplicate of this.