Subscribe on changes!

v-memo doesn't work with v-for

avatar
Aug 4th 2021

Version

3.2.0-beta.7

Reproduction link

Vue SFC Playground

Steps to reproduce

click inc button

What is expected?

<Item /> should not re-render unless value of count is greater than 4, similar to div above

What is actually happening?

v-memo with v-for doesn't work at all and <Item /> re-renders each time count value is incremented.

avatar
Aug 4th 2021

What are you actually trying to achieve? Why would you use something that isn't used in the v-for in the v-memo. How are you checking that elements are updated in your current repro?

avatar
Aug 4th 2021

I don't use it in my project (yet) I was just testing this feature in the playground and noticed it doesn't work with v-for, that's it. Other example. Shouldn't it always render count: 0 within the list? basically act like v-once?

<div v-for="id in 3" :key="id" v-memo="[true]">
  count: {{ count }}
</div>
avatar
Aug 4th 2021

I don't think v-memo is supposed to work like v-once. Since you are passing :count="count", the component still needs to update. Take a look at this example without count, only the items changing are updating, while the rest (9998 elements) are not touched. I'm still confused though as using v-memo or not doesn't change the outcome...

avatar
Aug 4th 2021

your example is also broken

from the docs:

The directive expects a fixed-length array of dependency values to compare for the memoization. If every value in the array was the same as last render, then updates for the entire sub-tree will be skipped

in my example memo value doesn't change (v-memo="[true]") so why is text updated when the count value changes? :/

avatar
Aug 4th 2021

you added count back 😆

I'm also confused, this seems like a bug

avatar
Aug 4th 2021

oh good catch 😂

avatar
Aug 4th 2021