-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Vue warns incorrectly if component is surrounded by functional component #3257
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
Comments
Is this really a bug? I do not think so. As long as you execute the slot functions in setup, you will get this warning, which has nothing to do with whether you use functional components to wrap it. import { createApp, h, defineComponent } from 'vue'
const Comp = defineComponent({
setup(props, { slots }) {
// a warning raised, this is as expected
const s = slots.default && slots.default()
return () => s
}
})
createApp({
setup() {
return () => h(Comp, () => 'sss')
}
}).mount('#header')
|
@HcySunYang But then I should get the warning too when I execute the MyComponent directly in App.vue (instead of MyContainer), right? But then there is no warning. so something seems to be wrong there... A little bit of context of the bigger picture what I try to accomblish: I want to tell the parent component if any of the child components are considered "empty" (based on their data AND slot content). In vue2 those slots where just empty when no element was rendered (with functional components), but since vue3 I can't tell if the component has a |
Ok, I made a PR to make the warning consistent when calling the slot function outside the render function. However, more and more users request similar capabilities. They hope to call the slot function in the |
Version
3.0.5
Reproduction link
https://codesandbox.io/s/vue3-slot-invoked-outside-warning-demo-ezuud
Steps to reproduce
Please have a look at the minimal reproduction.
As soon as I create a component inside of a "functional component", it show's a warning.
What is expected?
It shouldn't warn.
What is actually happening?
[Vue warn]: Slot "default" invoked outside of the render function: this will not track dependencies used in the slot. Invoke the slot function inside the render function instead.
The warning is only shown if I create the
watch
in MyComponent.vue (or if I accessisMandatoryOrSlotVisible.value
directly.)If I use the same code without the surrounding MyContainer component, it work's without any warning. Since there is no invokation of the slot function in the surrounding MyContainer component, the warning is misleading.
The text was updated successfully, but these errors were encountered: