Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-memo doesn't work with v-for #4246

Closed
sqal opened this issue Aug 4, 2021 · 8 comments · Fixed by #4272
Closed

v-memo doesn't work with v-for #4246

sqal opened this issue Aug 4, 2021 · 8 comments · Fixed by #4272
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working

Comments

@sqal
Copy link
Contributor

sqal commented Aug 4, 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.

@posva
Copy link
Member

posva commented Aug 4, 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?

@sqal
Copy link
Contributor Author

sqal commented Aug 4, 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>

@posva
Copy link
Member

posva commented Aug 4, 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...

@sqal
Copy link
Contributor Author

sqal commented Aug 4, 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? :/

@posva
Copy link
Member

posva commented Aug 4, 2021

you added count back 😆

I'm also confused, this seems like a bug

@posva posva added the 🐞 bug Something isn't working label Aug 4, 2021
@sqal
Copy link
Contributor Author

sqal commented Aug 4, 2021

oh good catch 😂

@lidlanca
Copy link
Contributor

lidlanca commented Aug 4, 2021

some what related issue #4253

@posva posva added the ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. label Aug 4, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants