Skip to content

fix(runtime-core): avoid flicker when setRef on TransitionGroup children #7768

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/runtime-core/src/rendererTemplateRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export function setRef(
warn('Invalid template ref type:', ref, `(${typeof ref})`)
}
}
if (value) {

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
Expand Down
51 changes: 51 additions & 0 deletions packages/vue/__tests__/e2e/TransitionGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,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 () => {
Expand Down