Unnecessary template renders when v-bind and additional object or array prop is used
Vue version
3.2.45
Link to minimal reproduction
Steps to reproduce
Hello, I need advice on this magic. I don't think it is expected behavior.
If template is updated (eg. title ref is updated), OtherChild
component is also unnecessarily re-rendered. Note, that title
is not used in the grouped
object, and the problem is connected with v-bind usage together with other object/array prop.
<template>
<TitleChild :title="title" />
<OtherChild v-bind="grouped" :take="['one', 'two']" />
</template>
If the second prop of OtherChild
is defined in the script, it works as it should. No unnecessary renders.
<template>
<TitleChild :title="title" />
<OtherChild v-bind="grouped" :take="takeList" />
</template>
<script setup>
const takeList = ['one', 'two'];
</script>
What is expected?
Should not re-render with v-bind and another prop in the template.
What is actually happening?
OtherChild
component is also unnecessarily re-rendered.
System Info
No response
Any additional comments?
No response
- The change to
title
makes the component re-render - During the re-render, a fresh inline array is being created in the template and passed to
OtherComponent
, which makesOtherComponent
re-render, because the attribute's content changed (it's a new array).
Expected Behavior.
Solution: extract the array into a variable in <script>