Skip to content

Commit de11f66

Browse files
committed
chore: update
1 parent 9443c1f commit de11f66

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

packages/runtime-core/src/component.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,9 @@ export interface ComponentInternalInstance {
582582
* For updating css vars on contained teleports
583583
* @internal
584584
*/
585-
ut?: (vars?: Record<string, string>) => void
586-
/**
587-
* `update nested teleport css vars`
588-
* @internal
589-
*/
590-
parentUt?: {
585+
ut?: {
591586
uid: number
592-
ut: (vars?: Record<string, string>) => void
587+
update: (vars?: Record<string, string>) => void
593588
}[]
594589
/**
595590
* dev only. For style v-bind hydration mismatch checks

packages/runtime-core/src/components/Teleport.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,23 +476,14 @@ function updateCssVars(vnode: VNode, isDisabled: boolean) {
476476
anchor = vnode.targetAnchor
477477
}
478478
if (ctx && ctx.ut) {
479-
let currentNode = node
480-
while (currentNode && currentNode !== anchor) {
481-
if (currentNode.nodeType === 1)
482-
currentNode.setAttribute('data-v-owner', ctx.uid)
483-
currentNode = currentNode.nextSibling
484-
}
485-
ctx.ut()
486-
}
487-
if (ctx && ctx.parentUt) {
488-
ctx.parentUt.forEach(i => {
479+
ctx.ut.forEach(i => {
489480
let currentNode = node
490481
while (currentNode && currentNode !== anchor) {
491482
if (currentNode.nodeType === 1)
492-
currentNode.setAttribute(`data-v-parent-${i.uid}-owner`, '')
483+
currentNode.setAttribute(`data-v-owner-${i.uid}`, '')
493484
currentNode = currentNode.nextSibling
494485
}
495-
i.ut()
486+
i.update()
496487
})
497488
}
498489
}

packages/runtime-core/src/vnode.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ function createBaseVNode(
491491
ctx: currentRenderingInstance,
492492
} as VNode
493493

494-
updateParentUt(vnode)
494+
updateUt(vnode)
495495

496496
if (needFullChildrenNormalization) {
497497
normalizeChildren(vnode, children)
@@ -539,22 +539,15 @@ function createBaseVNode(
539539
return vnode
540540
}
541541

542-
function updateParentUt(vnode: VNode) {
543-
if (vnode.ctx && vnode.ctx.parent && vnode.ctx.parent.parentUt) {
544-
vnode.ctx.parentUt = vnode.ctx.parent.parentUt.slice(0)
545-
}
546-
if (
547-
vnode.ctx &&
548-
currentRenderingInstance &&
549-
currentRenderingInstance.parent &&
550-
currentRenderingInstance.parent.ut
551-
) {
552-
const parentUid = currentRenderingInstance.parent.uid
553-
const parentUt = currentRenderingInstance.parent.ut
554-
if (!vnode.ctx.parentUt) {
555-
vnode.ctx.parentUt = [{ ut: parentUt, uid: parentUid }]
556-
} else if (!vnode.ctx.parentUt.find(i => parentUid === i.uid)) {
557-
vnode.ctx.parentUt.push({ ut: parentUt, uid: parentUid })
542+
function updateUt(vnode: VNode) {
543+
if (vnode.ctx && vnode.ctx.parent && vnode.ctx.parent.ut) {
544+
const parentUt = vnode.ctx.parent.ut.slice(0)
545+
if (vnode.shapeFlag & ShapeFlags.COMPONENT) {
546+
if (vnode.ctx.ut) {
547+
vnode.ctx.ut.unshift(...parentUt)
548+
} else vnode.ctx.ut = parentUt
549+
} else if (vnode.shapeFlag & ShapeFlags.TELEPORT) {
550+
if (!vnode.ctx.ut) vnode.ctx.ut = parentUt
558551
}
559552
}
560553
}

packages/runtime-dom/src/helpers/useCssVars.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
2828
}
2929
/* v8 ignore stop */
3030

31-
const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
32-
Array.from(
33-
document.querySelectorAll(`[data-v-owner="${instance.uid}"]`),
34-
).forEach(node => setVarsOnNode(node, vars))
35-
Array.from(
36-
document.querySelectorAll(`[data-v-parent-${instance.uid}-owner]`),
37-
).forEach(node => setVarsOnNode(node, vars))
38-
})
31+
const ut = {
32+
uid: instance.uid,
33+
update: (vars = getter(instance.proxy)) => {
34+
Array.from(
35+
document.querySelectorAll(`[data-v-owner-${instance.uid}]`),
36+
).forEach(node => setVarsOnNode(node, vars))
37+
},
38+
}
39+
instance.ut = [ut]
40+
const updateTeleports = () => {
41+
instance.ut!.forEach(i => i.update())
42+
}
3943

4044
if (__DEV__) {
4145
instance.getCssVars = () => getter(instance.proxy)
@@ -48,7 +52,7 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
4852
} else {
4953
setVarsOnVNode(instance.subTree, vars)
5054
}
51-
updateTeleports(vars)
55+
updateTeleports()
5256
}
5357

5458
onBeforeMount(() => {

0 commit comments

Comments
 (0)