All slots re-renders if 1 slot re-render
Vue version
3.2.45
Link to minimal reproduction
Steps to reproduce
- Create a vue component with 2 or more slots.
- Use the component and set 1 slot that has a property that changes i.e. that forces the slot to re-render
- The other slots also re-renders.
What is expected?
Slots are not dependant on eachother. Slot only re-renders if props for that particular slot is changed.
What is actually happening?
All slots re-renders if 1 slot re-renders.
System Info
No response
Any additional comments?
Coming from react I think this behaviour is unexpected.
That's expected. When a component re-renders, all of the template is re-rendered into a new virtual DOM representation which will then be diffed. That includes all slots, as they are part of the component's template.
I agree with you if the parent that holds the template needs to re-render then yes, the template should re-render.
But if a component inside a slot needs to re-render, then I think it's counter intuitive that the parent component which holds the template re-render as well. In my example Comp is the parent component that holds the template.
I thought the slots would act like child-components. If a child-component props changes then I don't expect their "siblings" to re-render as well.
I thought the slots would act like child-components. If a child-component props changes then I don't expect their "siblings" to re-render as well.
That's a misconception. they are part of the component's template, they don't act as their own components. Any reactive data accessed in the slot's content will be collected as a dependency of component rendering the slots. If that reactive data changes, the component re-renders as a whole, re-rendering all its slots in the process.