File tree 3 files changed +40
-12
lines changed
runtime-dom/__tests__/helpers
3 files changed +40
-12
lines changed Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ export const TeleportImpl = {
223
223
}
224
224
}
225
225
226
- updateCssVars ( parentComponent , n2 )
226
+ updateCssVars ( n2 )
227
227
} ,
228
228
229
229
remove (
@@ -385,7 +385,7 @@ function hydrateTeleport(
385
385
)
386
386
}
387
387
}
388
- updateCssVars ( parentComponent , vnode )
388
+ updateCssVars ( vnode )
389
389
}
390
390
return vnode . anchor && nextSibling ( vnode . anchor as Node )
391
391
}
@@ -396,19 +396,16 @@ export const Teleport = TeleportImpl as unknown as {
396
396
new ( ) : { $props : VNodeProps & TeleportProps }
397
397
}
398
398
399
- function updateCssVars (
400
- parentComponent : ComponentInternalInstance | null ,
401
- vnode : VNode
402
- ) {
399
+ function updateCssVars ( vnode : VNode ) {
403
400
// presence of .ut method indicates owner component uses css vars.
404
401
// code path here can assume browser environment.
405
- if ( parentComponent && parentComponent . ut ) {
402
+ const ctx = vnode . ctx
403
+ if ( ctx && ctx . ut ) {
406
404
let node = ( vnode . children as VNode [ ] ) [ 0 ] . el !
407
405
while ( node !== vnode . targetAnchor ) {
408
- if ( node . nodeType === 1 )
409
- node . setAttribute ( 'data-v-owner' , parentComponent . uid )
406
+ if ( node . nodeType === 1 ) node . setAttribute ( 'data-v-owner' , ctx . uid )
410
407
node = node . nextSibling
411
408
}
412
- parentComponent . ut ( )
409
+ ctx . ut ( )
413
410
}
414
411
}
Original file line number Diff line number Diff line change @@ -205,6 +205,11 @@ export interface VNode<
205
205
// application root node only
206
206
appContext : AppContext | null
207
207
208
+ /**
209
+ * @internal lexical scope owner instance
210
+ */
211
+ ctx : ComponentInternalInstance | null
212
+
208
213
/**
209
214
* @internal attached by v-memo
210
215
*/
@@ -439,7 +444,8 @@ function createBaseVNode(
439
444
patchFlag,
440
445
dynamicProps,
441
446
dynamicChildren : null ,
442
- appContext : null
447
+ appContext : null ,
448
+ ctx : currentRenderingInstance
443
449
} as VNode
444
450
445
451
if ( needFullChildrenNormalization ) {
@@ -661,7 +667,8 @@ export function cloneVNode<T, U>(
661
667
ssContent : vnode . ssContent && cloneVNode ( vnode . ssContent ) ,
662
668
ssFallback : vnode . ssFallback && cloneVNode ( vnode . ssFallback ) ,
663
669
el : vnode . el ,
664
- anchor : vnode . anchor
670
+ anchor : vnode . anchor ,
671
+ ctx : vnode . ctx
665
672
}
666
673
if ( __COMPAT__ ) {
667
674
defineLegacyVNodeProperties ( cloned as VNode )
Original file line number Diff line number Diff line change @@ -218,6 +218,30 @@ describe('useCssVars', () => {
218
218
}
219
219
} )
220
220
221
+ test ( 'with teleport in child slot' , async ( ) => {
222
+ document . body . innerHTML = ''
223
+ const state = reactive ( { color : 'red' } )
224
+ const root = document . createElement ( 'div' )
225
+ const target = document . body
226
+
227
+ const Child : FunctionalComponent = ( _ , { slots } ) => {
228
+ return h ( 'div' , slots . default && slots . default ( ) )
229
+ }
230
+
231
+ const App = {
232
+ setup ( ) {
233
+ useCssVars ( ( ) => state )
234
+ return ( ) => h ( Child , ( ) => [ h ( Teleport , { to : target } , [ h ( 'div' ) ] ) ] )
235
+ }
236
+ }
237
+
238
+ render ( h ( App ) , root )
239
+ await nextTick ( )
240
+ for ( const c of [ ] . slice . call ( target . children as any ) ) {
241
+ expect ( ( c as HTMLElement ) . style . getPropertyValue ( `--color` ) ) . toBe ( 'red' )
242
+ }
243
+ } )
244
+
221
245
test ( 'with teleport(change subTree)' , async ( ) => {
222
246
document . body . innerHTML = ''
223
247
const state = reactive ( { color : 'red' } )
You can’t perform that action at this time.
0 commit comments