]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: add comments edison/fix/refix13211 13691/head
authordaiwei <daiwei521@126.com>
Thu, 24 Jul 2025 09:42:44 +0000 (17:42 +0800)
committerdaiwei <daiwei521@126.com>
Thu, 24 Jul 2025 09:48:37 +0000 (17:48 +0800)
packages/compiler-core/src/transforms/cacheStatic.ts
packages/runtime-core/src/vnode.ts

index fe995b97daf5a3d6c6098d385bffa63bbd594e8d..c4d29f71248b28f7e3eb6d196ca1bb80a5fae9da 100644 (file)
@@ -219,6 +219,12 @@ function walk(
     // #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
   }
index baa7b177465a4e61995a4e5dbca797ef93953585..cd1ef948d73aa8bacf0bfb44c93ebf7732ee7e49 100644 (file)
@@ -680,9 +680,7 @@ export function cloneVNode<T, U>(
     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,
@@ -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
  */
 function deepCloneVNode(vnode: VNode): VNode {