From a646a834214f3343d82a52ddb847a9897e235f4a Mon Sep 17 00:00:00 2001 From: Vadim Kruglov Date: Tue, 16 Apr 2024 17:09:43 +0700 Subject: [PATCH] fix(runtime-core): Revert to using InternalObjectKey for normalized slots to prevent reassigning _ctx --- packages/runtime-core/src/componentSlots.ts | 3 +++ packages/runtime-core/src/vnode.ts | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index e0f051b3984..890751cfcea 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -1,5 +1,6 @@ import { type ComponentInternalInstance, currentInstance } from './component' import { + InternalObjectKey, type VNode, type VNodeChild, type VNodeNormalizedChildren, @@ -187,6 +188,8 @@ export const initSlots = ( normalizeVNodeSlots(instance, children) } } + + def(instance.slots, InternalObjectKey, 1) } export const updateSlots = ( diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 28b60be78f2..7c2469bc4e6 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -405,6 +405,8 @@ const createVNodeWithArgsTransform = ( ) } +export const InternalObjectKey = `__vInternal` + const normalizeKey = ({ key }: VNodeProps): VNode['key'] => key != null ? key : null @@ -791,7 +793,7 @@ export function normalizeChildren(vnode: VNode, children: unknown) { } else { type = ShapeFlags.SLOTS_CHILDREN const slotFlag = (children as RawSlots)._ - if (!slotFlag) { + if (!slotFlag && !(InternalObjectKey in children!)) { // if slots are not normalized, attach context instance // (compiled / normalized slots already have context) ;(children as RawSlots)._ctx = currentRenderingInstance