( instance: ComponentInternalInstance, children: VNodeNormalizedChildren, optimized: boolean, )
| 205 | } |
| 206 | |
| 207 | export const updateSlots = ( |
| 208 | instance: ComponentInternalInstance, |
| 209 | children: VNodeNormalizedChildren, |
| 210 | optimized: boolean, |
| 211 | ): void => { |
| 212 | const { vnode, slots } = instance |
| 213 | let needDeletionCheck = true |
| 214 | let deletionComparisonTarget = EMPTY_OBJ |
| 215 | if (vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) { |
| 216 | const type = (children as RawSlots)._ |
| 217 | if (type) { |
| 218 | // compiled slots. |
| 219 | if (__DEV__ && isHmrUpdating) { |
| 220 | // Parent was HMR updated so slot content may have changed. |
| 221 | // force update slots and mark instance for hmr as well |
| 222 | assignSlots(slots, children as Slots, optimized) |
| 223 | trigger(instance, TriggerOpTypes.SET, '$slots') |
| 224 | } else if (optimized && type === SlotFlags.STABLE) { |
| 225 | // compiled AND stable. |
| 226 | // no need to update, and skip stale slots removal. |
| 227 | needDeletionCheck = false |
| 228 | } else { |
| 229 | // compiled but dynamic (v-if/v-for on slots) - update slots, but skip |
| 230 | // normalization. |
| 231 | assignSlots(slots, children as Slots, optimized) |
| 232 | } |
| 233 | } else { |
| 234 | needDeletionCheck = !(children as RawSlots).$stable |
| 235 | normalizeObjectSlots(children as RawSlots, slots, instance) |
| 236 | } |
| 237 | deletionComparisonTarget = children as RawSlots |
| 238 | } else if (children) { |
| 239 | // non slot object children (direct value) passed to a component |
| 240 | normalizeVNodeSlots(instance, children) |
| 241 | deletionComparisonTarget = { default: 1 } |
| 242 | } |
| 243 | |
| 244 | // delete stale slots |
| 245 | if (needDeletionCheck) { |
| 246 | for (const key in slots) { |
| 247 | if (!isInternalKey(key) && deletionComparisonTarget[key] == null) { |
| 248 | delete slots[key] |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | } |
no test coverage detected