Subscribe on changes!

All slots re-renders if 1 slot re-render

avatar
Mar 7th 2023

Vue version

3.2.45

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9U8FymzAQ/ZUdZTpuxzFy0/pCIXWbmXxAzrpgEAkJ0mok4UyG4d+zAuw4YIfT7r5F7+ntqmX/jIn2jWQxS1xuK+PBSd+YW6ErZdB6uENloLSoYBHxkIT2xRFuwcoSurEjQH+EzlE7Dzk22kMaGr6vf1AZQOhaethh8fYgdSHt3diyJjQgJaKXdo4lfBBHsijxUpk685IygCRo6iOKDwhcBY6xSvWnn8cY4D9BR4R/gibK0radVJbLrhu5+ImMGf1wkQsC7nvwrIRk13iPGrZ5XeUvqWC9iculYLf3dWVIINYyIz+Gvo//DMTOv9WSfmlzrNHGo//fbiBNyUX4C4urNX1luYCY4nKz2VDc0dHBQtSSugtp6LIZRSTiSHbwN3yzEZFJs9oFm0I6jmtiH7tmw0KtVGaiZ4eaNrLtV2YEnGAx9JVQo0ULuWBP3hsXc95o8/IY5aj4ljBuSUSl5KpAtf0V3US/N7yonD+tR9Kp1c7iq5OWGAW7PjmcU3Ev7cr2d6JhfUU26f1EOMFmpIGTrOrIgMPjOvMW+7W//AbI16LafyyDq9GDzlTYhrDAggE/jw6TO8ETkh1OmsyHJtS9A/sYXk8=

Steps to reproduce

  1. Create a vue component with 2 or more slots.
  2. Use the component and set 1 slot that has a property that changes i.e. that forces the slot to re-render
  3. The other slots also re-renders.

See link to playground

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.

avatar
Mar 7th 2023

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.

avatar
Mar 7th 2023

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.

avatar
Mar 7th 2023

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.

avatar
Mar 8th 2023

Ok thank you for the answer, seems like this issue is related to #6351