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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): when Transition reports a warning about 'can only be used on a single element or component', it ignores the comments node. (fix #5675) #5708

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 7 additions & 3 deletions packages/runtime-core/src/components/BaseTransition.ts
Expand Up @@ -20,6 +20,7 @@ import { ShapeFlags, PatchFlags } from '@vue/shared'
import { onBeforeUnmount, onMounted } from '../apiLifecycle'
import { RendererElement } from '../renderer'


export interface BaseTransitionProps<HostElement = RendererElement> {
mode?: 'in-out' | 'out-in' | 'default'
appear?: boolean
Expand Down Expand Up @@ -140,16 +141,19 @@ const BaseTransitionImpl: ComponentOptions = {
const state = useTransitionState()

let prevTransitionKey: any

const filterCommentChild = (children:Array<VNode>) =>{
return children.filter((child:VNode)=>{
return child.type !== Comment
})
}
return () => {
const children =
slots.default && getTransitionRawChildren(slots.default(), true)
if (!children || !children.length) {
return
}

// warn multiple elements
if (__DEV__ && children.length > 1) {
if (__DEV__ && filterCommentChild(children).length > 1) {
warn(
'<transition> can only be used on a single element or component. Use ' +
'<transition-group> for lists.'
Expand Down