mirror of https://github.com/vuejs/core.git
chore: add comments
This commit is contained in:
parent
87d1e5f028
commit
639fc0baf3
|
@ -219,6 +219,12 @@ function walk(
|
||||||
// #6978, #7138, #7114
|
// #6978, #7138, #7114
|
||||||
// a cached children array inside v-for can caused HMR errors since
|
// a cached children array inside v-for can caused HMR errors since
|
||||||
// it might be mutated when mounting the first item
|
// 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
|
exp.needArraySpread = true
|
||||||
return exp
|
return exp
|
||||||
}
|
}
|
||||||
|
|
|
@ -680,9 +680,7 @@ export function cloneVNode<T, U>(
|
||||||
scopeId: vnode.scopeId,
|
scopeId: vnode.scopeId,
|
||||||
slotScopeIds: vnode.slotScopeIds,
|
slotScopeIds: vnode.slotScopeIds,
|
||||||
children:
|
children:
|
||||||
// if vnode is cached, deep clone it's children to prevent cached children
|
__DEV__ && patchFlag === PatchFlags.CACHED && isArray(children)
|
||||||
// from retaining detached DOM nodes
|
|
||||||
patchFlag === PatchFlags.CACHED && isArray(children)
|
|
||||||
? (children as VNode[]).map(deepCloneVNode)
|
? (children as VNode[]).map(deepCloneVNode)
|
||||||
: children,
|
: children,
|
||||||
target: vnode.target,
|
target: vnode.target,
|
||||||
|
@ -740,7 +738,7 @@ export function cloneVNode<T, U>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* https://github.com/vitejs/vite/issues/2022
|
||||||
*/
|
*/
|
||||||
function deepCloneVNode(vnode: VNode): VNode {
|
function deepCloneVNode(vnode: VNode): VNode {
|
||||||
|
|
Loading…
Reference in New Issue