Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BaseTransition): avoid flat children if fragment is stable and keyed #4743

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/runtime-core/src/components/BaseTransition.ts
Expand Up @@ -464,10 +464,14 @@ export function getTransitionRawChildren(
const child = children[i]
// handle fragment children case, e.g. v-for
if (child.type === Fragment) {
if (child.patchFlag & PatchFlags.KEYED_FRAGMENT) keyedFragmentCount++
ret = ret.concat(
getTransitionRawChildren(child.children as VNode[], keepComment)
)
if (child.patchFlag & PatchFlags.STABLE_FRAGMENT && child.key != null) {
ret.push(child)
} else {
if (child.patchFlag & PatchFlags.KEYED_FRAGMENT) keyedFragmentCount++
ret = ret.concat(
getTransitionRawChildren(child.children as VNode[], keepComment)
)
}
}
// comment placeholders should be skipped, e.g. v-if
else if (keepComment || child.type !== Comment) {
Expand Down
16 changes: 16 additions & 0 deletions packages/vue/__tests__/TransitionGroup.spec.ts
Expand Up @@ -508,4 +508,20 @@ describe('e2e: TransitionGroup', () => {

expect(`<TransitionGroup> children must be keyed`).toHaveBeenWarned()
})

test('should not warn v-for + template', () => {
createApp({
template: `
<transition-group name="test">
<template v-for="item in items" key="item">{{item}}</template>
</transition-group>
`,
setup: () => {
const items = ref(['a', 'b', 'c'])
return { items }
}
}).mount(document.createElement('div'))

expect(`<TransitionGroup> children must be keyed`).not.toHaveBeenWarned()
})
})