// #6978, #7138, #7114
// a cached children array inside v-for can caused HMR errors since
// it might be mutated when mounting the first item
+ // #13221
+ // fix memory leak in cached array:
+ // cached vnodes get replaced by cloned ones during mountChildren,
+ // which bind DOM elements. These DOM references persist after unmount,
+ // preventing garbage collection. Array spread avoids mutating cached
+ // array, preventing memory leaks.
exp.needArraySpread = true
return exp
}
scopeId: vnode.scopeId,
slotScopeIds: vnode.slotScopeIds,
children:
- // if vnode is cached, deep clone it's children to prevent cached children
- // from retaining detached DOM nodes
- patchFlag === PatchFlags.CACHED && isArray(children)
+ __DEV__ && patchFlag === PatchFlags.CACHED && isArray(children)
? (children as VNode[]).map(deepCloneVNode)
: children,
target: vnode.target,
}
/**
- * for HMR of hoisted vnodes reused in v-for
+ * Dev only, for HMR of hoisted vnodes reused in v-for
* https://github.com/vitejs/vite/issues/2022
*/
function deepCloneVNode(vnode: VNode): VNode {