-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Slots resolving issue on subsequent components #7710
Slots resolving issue on subsequent components #7710
Comments
When passing down children, you have to specify where to place them although I would agree it would make things easier if they were assigned automatically to their corresponding but think about it when writing a template. This is the way you would do it // ComponentA.vue
<CompB>
<slot name="foo" slot="foo"/>
</CompB> Note how you have to explicitly name the slot and say it is a slot of You need to do the same things with render functions, here is an example doing it in functional and non-functional components https://jsfiddle.net/posva/fseLahxu/ @yyx990803 I'm not sure if I'm giving the right solution. If it is, I think I should do a PR to document this, although I'm not sure what approach to take cc @chrisvfritz |
@posva I think the difference is templates don't have a concept of just |
Thank you @yyx990803 :) |
Named slots should be respecred when passing raw children down multiple layers of functional components. fix #7710
Heads up: we are likely going to revert this change in 2.6. This commit has led to a regression in #7958 and after revisiting the change, I believe it is technically incorrect to support it. Passing a raw For your use case (creating transparent wrappers that pass down named slots as-is), here's a work around: // a helper that explicitly passes down the same named slots that are passed in
function mapSlots (h, slots) {
return Object.keys(slots).map(name => {
return h('template', { slot: name }, slots[name])
})
}
const CompA = {
functional: true,
render (h, { slots }) {
return h(CompB, mapSlots(h, slots()))
}
} This is obviously a more verbose workaround, but it is necessary for now to ensure correct behavior in #7958, which is a more common use case. We should also consider an easier way to pass down named slots in render functions, pretty much like const CompA = {
functional: true,
render (h, { slots }) {
return h(CompB, { slots: slots() })
}
} |
Ok, thanks for the warning. |
Named slots should be respecred when passing raw children down multiple layers of functional components. fix vuejs#7710
Named slots should be respecred when passing raw children down multiple layers of functional components. fix vuejs#7710
Version
2.5.13
Reproduction link
https://codesandbox.io/s/316wjk4w41
Steps to reproduce
As stated by the docs slots() in fn components should be used only when the component knows about them, otherwise should pass along the children and the next component could deal with them.
What is expected?
I would expect that all children component would resolve slots correctly as long as children are passed along.
What is actually happening?
Only the initial component gets resolved the slots well, while any subsequent component that gets the children passed along doesn't.
The text was updated successfully, but these errors were encountered: