Subscribe on changes!

Can't access children array from parent slot.default() if the child is a custom component.

avatar
Nov 16th 2023

Vue version

3.3.8

Link to minimal reproduction

https://play.vuejs.org/#eNq1VE2L2zAQ/StaXexAYh/2tnUC7bLQFtou3cJS8MXYE0dbWTL6SAPB/70jKXa8wUnawp6kmfdGejMazZ6+b9tka4He0UyXirWGaDC2XeWCNa1UhuyJgjXpyFrJhkRIjQbofsN4pUAcsCTtHe7E6N3AeyzQZwZWME84fegzM5uz547BPj4XpRTakEbXZOm0xtFH4FySZ6l4dRPNcpGlITVMCg0DTcsLA2gRkgUxfo/WcHN63lOx7WF7Ykyx0ZceOa/2kxmHuOxQIzSydNBL59RoTHbN6uRFS4FvtnfsnJayaRkH9a01DIuR0zviEYcVWIvfn73PKAvz3l9uoPw14X/RO+fL6aMCDWoLOR0wU6gaTIAfnr7CDvcD2MjKcmRfAL+Dltw6jYH2wYoKZY94Xu0n3xJM1D/0w86A0H1STqhjdp6fU2yB+wupH+XeJrc+LhcdVnHcQv/W+BPNxoFfazJ/3+lTHn/BJQlSfJFWGKjm7rY5sRqeuDT6jC7tseVAi2f+hwynxPGMLFehQiECODSowwX54KSCdWG58ZGBJDkkXNZxT8Vkuyu/atTm7tQVct0SejuAr6tx7oe/zVz6v2ccZ/WXQ4BkN4sF+SktKQucgNiNxGyYDsLaMBYXiyuzYqpi3R+fYuh3

Steps to reproduce

I created 3 different component

  • Parent: This contains a slot and this is where I want to get all children inside.
  • Child: Basic child component with text
  • ChildWithChildren: Compontent with some divs.

When I console.log the elements from the slot.default() it shows an array with 4 element which is good but when you start go down the tree you can see where we have custom component there the children is null, but if it's regular html element like <div></div> it contains children elements.

What is expected?

To be able to get children elements from custom component.

What is actually happening?

The children is null

System Info

No response

Any additional comments?

No response

avatar
Nov 16th 2023

Well yes, components manage their own virtual dom, so the Vnodes that you get from the slot will not contain the Vnodes located in a child component.

That's how components work a virtual dom.

avatar
Nov 16th 2023

That make sense. Thank you for the explanation!