This commit is contained in:
AlexVagrant 2025-05-05 20:41:54 +00:00 committed by GitHub
commit ae1b3cb6f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 1 deletions

View File

@ -149,7 +149,8 @@ export function setRef(
warn('Invalid template ref type:', ref, `(${typeof ref})`)
}
}
if (value) {
if (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

View File

@ -297,6 +297,57 @@ describe('e2e: TransitionGroup', () => {
E2E_TIMEOUT,
)
test(
'ref',
async () => {
await page().evaluate(() => {
const { createApp, ref } = (window as any).Vue
createApp({
template: `
<div id="container">
<transition-group name="group">
<div v-for="item in items" :key="item" ref="itemRef" class="test">{{item}}</div>
</transition-group>
</div>
<button id="toggleBtn" @click="click">button</button>
`,
setup: () => {
const items = ref(['a', 'b', 'c'])
const click = () => (items.value = ['d', 'b', 'a'])
const itemRef = ref()
return { click, items, itemRef }
},
}).mount('#app')
})
expect(await html('#container')).toBe(
`<div class="test">a</div>` +
`<div class="test">b</div>` +
`<div class="test">c</div>`,
)
expect(await htmlWhenTransitionStart()).toBe(
`<div class="test group-enter-from group-enter-active">d</div>` +
`<div class="test">b</div>` +
`<div class="test group-move" style="">a</div>` +
`<div class="test group-leave-from group-leave-active group-move" style="">c</div>`,
)
await nextFrame()
expect(await html('#container')).toBe(
`<div class="test group-enter-active group-enter-to">d</div>` +
`<div class="test">b</div>` +
`<div class="test group-move" style="">a</div>` +
`<div class="test group-leave-active group-move group-leave-to" style="">c</div>`,
)
await transitionFinish(duration * 2)
expect(await html('#container')).toBe(
`<div class="test">d</div>` +
`<div class="test">b</div>` +
`<div class="test" style="">a</div>`,
)
},
E2E_TIMEOUT,
)
test(
'dynamic name',
async () => {