Skip to content

Binding the 'v-for' element with 'ref' causes the movement animation to disappear when the list element is removed. #7754

Open
@flycran

Description

@flycran

Vue version

3.2.47

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9VE1v00AQ/SuDL0loYjdNJVBIUBEXbiAuHDAHx1knpvautbsOraJIKV9FFeKAQAVakEIpICGicqAqDaI/hjhp/wWzdpKmqcQl2Tf7Zt7O2/E2tWtBoDdCohW1krC5G0gQRIbBVZO6fsC4hCZw4kALHM58SCE1ZVKT2owKCb6oQVntp1M3iOcxuMO4V72QypjUIxJcWiUrSFgc8z0Xf5KEu/ksLGShcA+5Tkht6TIKVrWazkDTpBBT9YblhUQPQlFPx7Xm5pDdmkrgxGcNknYl8eM8UyZCY+WpKnHoppNwFdPFdUIrlyGXz2AxGXLs7Yy4CDzXRgXFzEI+0TcMuM58n1AJsu4K5FMCkqF1+FcnQBn3LQ+I4xBbjptXwreJI0YGYKWSkViOZiPA7cCzJEEEUKqEUmKDSzbKL5dNDa0xtXgL4JYXiphkJKwkQ3KLClfZkqtxFgZge5YQmFphK6YG1PIJAseqEkTSqiGouo1J0RICaOQcxnFDnRVNjI1AdnGZrI6iiPD0I6DamRQAaDZVsIUGJfhcE9PXNckzpYkY4woqcKYt1SWeLGnRmO0Rwxg8NQ6hkKueWhoXIa9DtLM3ePPi+Gh9cNAZvH42+LANFw2T6sqGnBLNjgFeJuE5C+dqKugRq0FGwWQuT09QBMvzYF6/LIBYglyJJyPWXTjV3Yqe7EYvnw8/96Lf7eG7x8ON/UF7beoMiaz6uGZEcZxiQRZYtitXizCPCiN9vCS/mCxV4+nCfLCSmTpAQYdhp9s/ej/RPen8Gm51jz9+G37pnbz9FK0f9g+fRgePoh/twc+18YX1e7v9P0eD7zuYHW3vHXc7w+4mZkQbXweb+1gGF8NXvcTIv+2HU32cdypgE58qgnmhHFmEUx9fkZbVkicm51uBfl8wio9QnInDFW/gbBWTWiqGT4/CplaXMhBFwwhpsFzTbeYbS7hn8JBK1ye5KvOXCvqCvngJB0fI6bhOhJ+rcPZAEI6KpoaeT4obGGzgXXCC3zon/L9iM9wzgjN750SVJvrQ0lr/AN24FR0=

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版本,均存在该问题。

Activity

AlexVagrant

AlexVagrant commented on Feb 20, 2023

@AlexVagrant
Contributor

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

edison1105

edison1105 commented on Feb 20, 2023

@edison1105
Member

@AlexVagrant
Good catch! PR welcome.

edison1105

edison1105 commented on Aug 21, 2024

@edison1105
Member

a workaround

const itemRefs = shallowRef() // use shallowRef instead of ref
Official-ObiTech

Official-ObiTech commented on Aug 29, 2024

@Official-ObiTech

// Validate and update positions after DOM update//
Object.entries(itemRefs.value).forEach(([r, i], index) => {
if (i && i.style) {
el.style.transform = translateY(${index * 20}px)
console.log(Updated position for item ${item}: ${el.style.transform})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @edison1105@AlexVagrant@flycran@Official-ObiTech

      Issue actions

        Binding the 'v-for' element with 'ref' causes the movement animation to disappear when the list element is removed. · Issue #7754 · vuejs/core