From: Evan You Date: Thu, 14 Apr 2022 10:06:52 +0000 (+0800) Subject: fix(transition): handle transition for v-if branches with comment X-Git-Tag: v3.2.33~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62eba63172414ae0aa895d4b1927c7889c398f2f;p=thirdparty%2Fvuejs%2Fcore.git fix(transition): handle transition for v-if branches with comment fix #5675 --- diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index c8a9459437..64249f8c4e 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -148,12 +148,25 @@ const BaseTransitionImpl: ComponentOptions = { return } - // warn multiple elements - if (__DEV__ && children.length > 1) { - warn( - ' can only be used on a single element or component. Use ' + - ' for lists.' - ) + let child: VNode = children[0] + if (children.length > 1) { + let hasFound = false + // locate first non-comment child + for (const c of children) { + if (c.type !== Comment) { + if (__DEV__ && hasFound) { + // warn more than one non-comment child + warn( + ' can only be used on a single element or component. ' + + 'Use for lists.' + ) + break + } + child = c + hasFound = true + if (!__DEV__) break + } + } } // there's no need to track reactivity for these props so use the raw @@ -171,8 +184,6 @@ const BaseTransitionImpl: ComponentOptions = { warn(`invalid mode: ${mode}`) } - // at this point children has a guaranteed length of 1. - const child = children[0] if (state.isLeaving) { return emptyPlaceholder(child) } diff --git a/packages/vue/__tests__/Transition.spec.ts b/packages/vue/__tests__/Transition.spec.ts index 3720493951..9ec7e6ca6a 100644 --- a/packages/vue/__tests__/Transition.spec.ts +++ b/packages/vue/__tests__/Transition.spec.ts @@ -2039,7 +2039,7 @@ describe('e2e: Transition', () => { template: `
- +
content