Explorar o código

chore: track KeepAlive child as block inside v-for

daiwei hai 1 ano
pai
achega
5a77b2a0aa

+ 4 - 1
packages/compiler-core/src/transforms/vFor.ts

@@ -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))

+ 8 - 5
packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts

@@ -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 */,

+ 1 - 1
packages/runtime-core/src/renderer.ts

@@ -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
     }