v-if works incorrectly when using with sparse array
Version
3.0.11
Reproduction link
Steps to reproduce
Clone this repo or open it on codesandbox
Run and open it with Chrome browser
Click the router link:
use-sparse-array-and-vshow
Open ELements devtool panel and inspect the expand ul tag recursively
When click on 'Remove first' button, you will see only removing element be re-rendered as expected.
But if you change tab to
use-sparse-array-and-vif
and click the button again, ALL elements are re-rendered.
What is expected?
Only the removing element be re-rendered.
What is actually happening?
All elements are re-rendered.
This behavior is works correctly in Vue 2: https://codesandbox.io/s/github/iendeavor/dont-use-index-as-template-key-but-how-about-sparse-array/tree/main/vue-2
your repro is very weired.its refresh automatically every few seconds without doing anything in codesandbox. 🤔
Not all elements are re-rendered, multiple warnings are because the deleted elements have the undefined
key at the time of patch
. because getTransitionRawChildren
does not filter out deleted elements correctly when using v-show
.
Is the docs wrong? https://v3.vuejs.org/guide/migration/key-attribute.html#with-template-v-for