App.vue(parent) variable change <component :is='Children' > ,Children.vue render twice
Version
3.1.5
[Reproduction link]
Steps to reproduce
- item in v-for "arr"
- App.vue(parent) Irrelevant variable change
- watch the devtools,
- click button
- <result1>:<component v-model='item.id'>,Children.vue render twice
- <result2>:<component v-model='arr[0].id'>,Children.vue oneice twice
What is expected?
render onice
What is actually happening?
App.vue(parent) variable change , Children.vue render twice
watch the devtools,
click button
<result1>:<component v-model='item.id'>,Children.vue render twice
<result2>:<component v-model='arr[0].id'>,Children.vue render oneice
I update the repro to make more sense.
the problem is: click button should not trigger Children
re-render.
This is expected behavior, because when you bind v-model
to item.id
, item
is a closure variable - so every render a new v-model
callback has to be generated (and cannot be cached due to correctness). This causes the child component to re-render.
See compiler output example - notice the first component's callback is not cached because it references item
which is a closure variable. The second component's callback can be cached because it doesn't reference item
.
Also this has nothing to do with <component :is>
.
In 3.2 you can optimize this case by adding v-memo="[item.id]"
.