]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): further fix slots _ctx check
authorEvan You <yyx990803@gmail.com>
Thu, 18 Apr 2024 04:23:25 +0000 (12:23 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 18 Apr 2024 04:27:15 +0000 (12:27 +0800)
close #10724

packages/runtime-core/src/componentSlots.ts

index 66a09e5fa1a6765b734cbe39c6c34af7fead2af5..aeba4d5c6b0a0374978a90dd7fc89724cb48e3f5 100644 (file)
@@ -21,9 +21,7 @@ import { isKeepAlive } from './components/KeepAlive'
 import { type ContextualRenderFn, withCtx } from './componentRenderContext'
 import { isHmrUpdating } from './hmr'
 import { DeprecationTypes, isCompatEnabled } from './compat/compatConfig'
-import { toRaw } from '@vue/reactivity'
-import { trigger } from '@vue/reactivity'
-import { TriggerOpTypes } from '@vue/reactivity'
+import { TriggerOpTypes, trigger } from '@vue/reactivity'
 import { createInternalObject } from './internalObject'
 
 export type Slot<T extends any = any> = (
@@ -167,26 +165,18 @@ export const initSlots = (
   instance: ComponentInternalInstance,
   children: VNodeNormalizedChildren,
 ) => {
+  const slots = (instance.slots = createInternalObject())
   if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
     const type = (children as RawSlots)._
     if (type) {
-      // users can get the shallow readonly version of the slots object through `this.$slots`,
-      // we should avoid the proxy object polluting the slots of the internal instance
-      instance.slots = toRaw(children as InternalSlots)
+      extend(slots, children as InternalSlots)
       // make compiler marker non-enumerable
-      def(instance.slots, '_', type)
+      def(slots, '_', type)
     } else {
-      normalizeObjectSlots(
-        children as RawSlots,
-        (instance.slots = createInternalObject()),
-        instance,
-      )
-    }
-  } else {
-    instance.slots = createInternalObject()
-    if (children) {
-      normalizeVNodeSlots(instance, children)
+      normalizeObjectSlots(children as RawSlots, slots, instance)
     }
+  } else if (children) {
+    normalizeVNodeSlots(instance, children)
   }
 }