-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: dynamic css on dynamically imported component #9264
Comments
It seems to me that for some reason async components are missing the parentNode and thus the error? |
When looking at the created instances, there are actually two, I guess that makes sense ?
From what I can tell they are for classB and classA, respectively, but |
I think someone reported the same bug in Pinia but with a boiled down repro so I added it here simplified |
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. - <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)); |
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. |
Note that with const getComponent = () => {
return defineAsyncComponent(() => Promise.resolve(VFoo));
}; and <component :is="getComponent()"> You are defining a new component on every update. To the parent component, it is rendering a different child component every time. So every time the parent component updates, That said the error is still something that is relevant. |
Ah thanks for pointing that out! I anyway now have something which looks like this (which i hope doesnt have this problem lol) const UiComponent = (() => {
return defineAsyncComponent(
() => import(`./VFoo.vue`),
);
})(); <ui-component>
</ui-component> |
Why not just const UiComponent = defineAsyncComponent(() => import(`./VFoo.vue`)) What's the point of wrapping it in another function? |
I had some additional logic in the first arrow function to build the import path, which I removed when posting here, but yea that is functionally the same anyway |
Vue version
3.3.4
Link to minimal reproduction
https://github.com/Disservin/vue-dynamic-import-css
Vue Playground Link
Steps to reproduce
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.
System Info
No response
Any additional comments?
If you comment out the following part in the Foo Component, you get no error.
or if you remove the class from the component
:class="loading ? 'classA' : 'classB'"
The text was updated successfully, but these errors were encountered: