@@ -147,7 +147,7 @@ export const TeleportImpl = {
147147 }
148148 if ( ! disabled ) {
149149 mount ( target , targetAnchor )
150- updateCssVars ( n2 )
150+ updateCssVars ( n2 , false )
151151 }
152152 } else if ( __DEV__ && ! disabled ) {
153153 warn (
@@ -160,7 +160,7 @@ export const TeleportImpl = {
160160
161161 if ( disabled ) {
162162 mount ( container , mainAnchor )
163- updateCssVars ( n2 )
163+ updateCssVars ( n2 , true )
164164 }
165165
166166 if ( isTeleportDeferred ( n2 . props ) ) {
@@ -267,7 +267,7 @@ export const TeleportImpl = {
267267 )
268268 }
269269 }
270- updateCssVars ( n2 )
270+ updateCssVars ( n2 , disabled )
271271 }
272272 } ,
273273
@@ -389,12 +389,13 @@ function hydrateTeleport(
389389 querySelector ,
390390 ) )
391391 if ( target ) {
392+ const disabled = isTeleportDisabled ( vnode . props )
392393 // if multiple teleports rendered to the same target element, we need to
393394 // pick up from where the last teleport finished instead of the first node
394395 const targetNode =
395396 ( target as TeleportTargetElement ) . _lpa || target . firstChild
396397 if ( vnode . shapeFlag & ShapeFlags . ARRAY_CHILDREN ) {
397- if ( isTeleportDisabled ( vnode . props ) ) {
398+ if ( disabled ) {
398399 vnode . anchor = hydrateChildren (
399400 nextSibling ( node ) ,
400401 vnode ,
@@ -446,7 +447,7 @@ function hydrateTeleport(
446447 )
447448 }
448449 }
449- updateCssVars ( vnode )
450+ updateCssVars ( vnode , disabled )
450451 }
451452 return vnode . anchor && nextSibling ( vnode . anchor as Node )
452453}
@@ -462,13 +463,20 @@ export const Teleport = TeleportImpl as unknown as {
462463 }
463464}
464465
465- function updateCssVars ( vnode : VNode ) {
466+ function updateCssVars ( vnode : VNode , isDisabled : boolean ) {
466467 // presence of .ut method indicates owner component uses css vars.
467468 // code path here can assume browser environment.
468469 const ctx = vnode . ctx
469470 if ( ctx && ctx . ut ) {
470- let node = vnode . targetStart
471- while ( node && node !== vnode . targetAnchor ) {
471+ let node , anchor
472+ if ( isDisabled ) {
473+ node = vnode . el
474+ anchor = vnode . anchor
475+ } else {
476+ node = vnode . targetStart
477+ anchor = vnode . targetAnchor
478+ }
479+ while ( node && node !== anchor ) {
472480 if ( node . nodeType === 1 ) node . setAttribute ( 'data-v-owner' , ctx . uid )
473481 node = node . nextSibling
474482 }
0 commit comments