Binding the 'v-for' element with 'ref' causes the movement animation to disappear when the list element is removed.
Vue version
3.2.47
Link to minimal reproduction
Steps to reproduce
Create loop elements and use the 'ref' binding to animate the 'transition-group' list, removing the first (or any of the last element) elements from the list
创建循环元素并使用ref
绑定,创建transition-group
列表动画,移除列表的第一个(或者除了末尾的任意一个)元素
What is expected?
The element moves up. 元素向上移动
What is actually happening?
You'll see elements overlap. 会看到元素发生重叠
System Info
No response
Any additional comments?
The latest and alpha versions have been tested in SFC Playground and both have this issue. 已在SFC Playground中测试了最新版本和alpha版本,均存在该问题。
I think this is a ref
bug. the following code may be used to solve this bug.
@LinusBorg
if (value || (!value && vnode.transition && !vnode.transition.persisted)) {
// #1789: for non-null values, set them after render
// null values means this is unmount and it should not overwrite another
// ref with the same key
;(doSet as SchedulerJob).id = -1
queuePostRenderEffect(doSet, parentSuspense)
} else {
doSet()
}
This is the source code.
https://github.com/vuejs/core/blob/main/packages/runtime-core/src/rendererTemplateRef.ts#L121-L129