File tree 2 files changed +20
-9
lines changed
runtime-core/src/components
2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -148,12 +148,25 @@ const BaseTransitionImpl: ComponentOptions = {
148
148
return
149
149
}
150
150
151
- // warn multiple elements
152
- if ( __DEV__ && children . length > 1 ) {
153
- warn (
154
- '<transition> can only be used on a single element or component. Use ' +
155
- '<transition-group> for lists.'
156
- )
151
+ let child : VNode = children [ 0 ]
152
+ if ( children . length > 1 ) {
153
+ let hasFound = false
154
+ // locate first non-comment child
155
+ for ( const c of children ) {
156
+ if ( c . type !== Comment ) {
157
+ if ( __DEV__ && hasFound ) {
158
+ // warn more than one non-comment child
159
+ warn (
160
+ '<transition> can only be used on a single element or component. ' +
161
+ 'Use <transition-group> for lists.'
162
+ )
163
+ break
164
+ }
165
+ child = c
166
+ hasFound = true
167
+ if ( ! __DEV__ ) break
168
+ }
169
+ }
157
170
}
158
171
159
172
// there's no need to track reactivity for these props so use the raw
@@ -171,8 +184,6 @@ const BaseTransitionImpl: ComponentOptions = {
171
184
warn ( `invalid <transition> mode: ${ mode } ` )
172
185
}
173
186
174
- // at this point children has a guaranteed length of 1.
175
- const child = children [ 0 ]
176
187
if ( state . isLeaving ) {
177
188
return emptyPlaceholder ( child )
178
189
}
Original file line number Diff line number Diff line change @@ -2039,7 +2039,7 @@ describe('e2e: Transition', () => {
2039
2039
template : `
2040
2040
<div id="container">
2041
2041
<transition>
2042
- <Comp class="test" v-if="toggle">
2042
+ <Comp class="test" v-if="toggle">
2043
2043
<div>content</div>
2044
2044
</Comp>
2045
2045
</transition>
You can’t perform that action at this time.
0 commit comments