@@ -10,6 +10,7 @@ import {
1010 baseResolveTransitionHooks ,
1111 checkTransitionMode ,
1212 currentInstance ,
13+ getComponentName ,
1314 isTemplateNode ,
1415 leaveCbKey ,
1516 queuePostFlushCb ,
@@ -33,8 +34,10 @@ import {
3334 setCurrentHydrationNode ,
3435} from '../dom/hydration'
3536
37+ const displayName = 'VaporTransition'
38+
3639const decorate = ( t : typeof VaporTransition ) => {
37- t . displayName = 'VaporTransition'
40+ t . displayName = displayName
3841 t . props = TransitionPropsValidators
3942 t . __vapor = true
4043 return t
@@ -208,8 +211,18 @@ export function applyTransitionHooks(
208211 hooks : VaporTransitionHooks ,
209212 fallthroughAttrs : boolean = true ,
210213) : VaporTransitionHooks {
214+ // filter out comment nodes
215+ if ( isArray ( block ) ) {
216+ block = block . filter ( b => ! ( b instanceof Comment ) )
217+ if ( block . length === 1 ) {
218+ block = block [ 0 ]
219+ } else if ( block . length === 0 ) {
220+ return hooks
221+ }
222+ }
223+
211224 const isFrag = isFragment ( block )
212- const child = findTransitionBlock ( block )
225+ const child = findTransitionBlock ( block , isFrag )
213226 if ( ! child ) {
214227 // set transition hooks on fragment for reusing during it's updating
215228 if ( isFrag ) setTransitionHooksOnFragment ( block , hooks )
@@ -296,43 +309,46 @@ export function findTransitionBlock(
296309 return transitionBlockCache . get ( block )
297310 }
298311
299- let isFrag = false
300312 let child : TransitionBlock | undefined
301313 if ( block instanceof Node ) {
302314 // transition can only be applied on Element child
303315 if ( block instanceof Element ) child = block
304316 } else if ( isVaporComponent ( block ) ) {
305- child = findTransitionBlock ( block . block )
317+ // stop searching if encountering nested Transition component
318+ if ( getComponentName ( block . type ) === displayName ) return undefined
319+ child = findTransitionBlock ( block . block , inFragment )
306320 // use component id as key
307321 if ( child && child . $key === undefined ) child . $key = block . uid
308322 } else if ( isArray ( block ) ) {
309- child = block [ 0 ] as TransitionBlock
310323 let hasFound = false
311324 for ( const c of block ) {
312- const item = findTransitionBlock ( c )
313- if ( item instanceof Element ) {
314- if ( __DEV__ && hasFound ) {
315- // warn more than one non-comment child
316- warn (
317- '<transition> can only be used on a single element or component. ' +
318- 'Use <transition-group> for lists.' ,
319- )
320- break
321- }
322- child = item
323- hasFound = true
324- if ( ! __DEV__ ) break
325+ if ( c instanceof Comment ) continue
326+ // check if the child is a fragment to suppress warnings
327+ if ( isFragment ( c ) ) inFragment = true
328+ const item = findTransitionBlock ( c , inFragment )
329+ if ( __DEV__ && hasFound ) {
330+ // warn more than one non-comment child
331+ warn (
332+ '<transition> can only be used on a single element or component. ' +
333+ 'Use <transition-group> for lists.' ,
334+ )
335+ break
325336 }
337+ child = item
338+ hasFound = true
339+ if ( ! __DEV__ ) break
326340 }
327- } else if ( ( isFrag = isFragment ( block ) ) ) {
341+ } else if ( isFragment ( block ) ) {
342+ // mark as in fragment to suppress warnings
343+ inFragment = true
328344 if ( block . insert ) {
329345 child = block
330346 } else {
331347 child = findTransitionBlock ( block . nodes , true )
332348 }
333349 }
334350
335- if ( __DEV__ && ! child && ! inFragment && ! isFrag ) {
351+ if ( __DEV__ && ! child && ! inFragment ) {
336352 warn ( 'Transition component has no valid child element' )
337353 }
338354
@@ -344,7 +360,7 @@ export function setTransitionHooksOnFragment(
344360 hooks : VaporTransitionHooks ,
345361) : void {
346362 if ( isFragment ( block ) ) {
347- setTransitionHooks ( block , hooks )
363+ block . $transition = hooks
348364 } else if ( isArray ( block ) ) {
349365 for ( let i = 0 ; i < block . length ; i ++ ) {
350366 setTransitionHooksOnFragment ( block [ i ] , hooks )
0 commit comments