|
|
@@ -12,7 +12,6 @@ import {
|
|
|
ShapeFlags,
|
|
|
SlotFlags,
|
|
|
def,
|
|
|
- extend,
|
|
|
isArray,
|
|
|
isFunction,
|
|
|
} from '@vue/shared'
|
|
|
@@ -161,6 +160,22 @@ const normalizeVNodeSlots = (
|
|
|
instance.slots.default = () => normalized
|
|
|
}
|
|
|
|
|
|
+const assignSlots = (
|
|
|
+ slots: InternalSlots,
|
|
|
+ children: Slots,
|
|
|
+ optimized: boolean,
|
|
|
+) => {
|
|
|
+ for (const key in children) {
|
|
|
+ // #2893
|
|
|
+ // when rendering the optimized slots by manually written render function,
|
|
|
+ // do not copy the `slots._` compiler flag so that `renderSlot` creates
|
|
|
+ // slot Fragment with BAIL patchFlag to force full updates
|
|
|
+ if (optimized || key !== '_') {
|
|
|
+ slots[key] = children[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export const initSlots = (
|
|
|
instance: ComponentInternalInstance,
|
|
|
children: VNodeNormalizedChildren,
|
|
|
@@ -170,16 +185,10 @@ export const initSlots = (
|
|
|
if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
|
|
|
const type = (children as RawSlots)._
|
|
|
if (type) {
|
|
|
- extend(slots, children as InternalSlots)
|
|
|
+ assignSlots(slots, children as Slots, optimized)
|
|
|
// make compiler marker non-enumerable
|
|
|
if (optimized) {
|
|
|
def(slots, '_', type, true)
|
|
|
- } else {
|
|
|
- // #2893
|
|
|
- // when rendering the optimized slots by manually written render function,
|
|
|
- // we need to delete the `slots._` flag if necessary to make subsequent
|
|
|
- // updates reliable, i.e. let the `renderSlot` create the bailed Fragment
|
|
|
- delete slots._
|
|
|
}
|
|
|
} else {
|
|
|
normalizeObjectSlots(children as RawSlots, slots, instance)
|
|
|
@@ -204,7 +213,7 @@ export const updateSlots = (
|
|
|
if (__DEV__ && isHmrUpdating) {
|
|
|
// Parent was HMR updated so slot content may have changed.
|
|
|
// force update slots and mark instance for hmr as well
|
|
|
- extend(slots, children as Slots)
|
|
|
+ assignSlots(slots, children as Slots, optimized)
|
|
|
trigger(instance, TriggerOpTypes.SET, '$slots')
|
|
|
} else if (optimized && type === SlotFlags.STABLE) {
|
|
|
// compiled AND stable.
|
|
|
@@ -213,7 +222,7 @@ export const updateSlots = (
|
|
|
} else {
|
|
|
// compiled but dynamic (v-if/v-for on slots) - update slots, but skip
|
|
|
// normalization.
|
|
|
- extend(slots, children as Slots)
|
|
|
+ assignSlots(slots, children as Slots, optimized)
|
|
|
}
|
|
|
} else {
|
|
|
needDeletionCheck = !(children as RawSlots).$stable
|