]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: track KeepAlive child as block inside v-for edison/fix/12914 12915/head
authordaiwei <daiwei521@126.com>
Thu, 22 May 2025 03:17:17 +0000 (11:17 +0800)
committerdaiwei <daiwei521@126.com>
Thu, 22 May 2025 03:17:17 +0000 (11:17 +0800)
packages/compiler-core/src/transforms/vFor.ts
packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
packages/runtime-core/src/renderer.ts

index 0dca0ba9ab437216347a353dcabcec01d44fc07b..8aba1f2c1b2120595bee7b70ab0542b03b39b6e3 100644 (file)
@@ -42,6 +42,7 @@ import {
 import {
   FRAGMENT,
   IS_MEMO_SAME,
+  KEEP_ALIVE,
   OPEN_BLOCK,
   RENDER_LIST,
 } from '../runtimeHelpers'
@@ -208,7 +209,9 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(
               )
             }
           }
-          childBlock.isBlock = !isStableFragment
+          // track KeepAlive child as block
+          childBlock.isBlock =
+            childBlock.tag === KEEP_ALIVE || !isStableFragment
           if (childBlock.isBlock) {
             helper(OPEN_BLOCK)
             helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent))
index 7587ecfcbaa4cabe5b0da0f548d2104f48e3fd6a..f6fd16692c48aa55b95235f01f1cc498fbf7cf26 100644 (file)
@@ -1431,11 +1431,14 @@ describe('renderer: optimized mode', () => {
             Fragment,
             null,
             renderList(1, () => {
-              return createVNode(
-                KeepAlive,
-                null,
-                [(openBlock(), createBlock(view.value))],
-                1024 /* DYNAMIC_SLOTS */,
+              return (
+                openBlock(),
+                createBlock(
+                  KeepAlive,
+                  { include: [] },
+                  [(openBlock(), createBlock(view.value))],
+                  1024 /* DYNAMIC_SLOTS */,
+                )
               )
             }),
             64 /* STABLE_FRAGMENT */,
index 23c0f447d1e4296f8987694a56b2d783acba50d2..7b39aa917a25f7bb26ea98c349d61c4c4265aaac 100644 (file)
@@ -2110,7 +2110,7 @@ function baseCreateRenderer(
     }
 
     if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
-      ;(vnode.component!.parent!.ctx as KeepAliveContext).deactivate(vnode)
+      ;(parentComponent!.ctx as KeepAliveContext).deactivate(vnode)
       return
     }