Skip to content

Commit 5a77b2a

Browse files
committed
chore: track KeepAlive child as block inside v-for
1 parent 90c15ea commit 5a77b2a

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

packages/compiler-core/src/transforms/vFor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import {
4343
FRAGMENT,
4444
IS_MEMO_SAME,
45+
KEEP_ALIVE,
4546
OPEN_BLOCK,
4647
RENDER_LIST,
4748
} from '../runtimeHelpers'
@@ -208,7 +209,9 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(
208209
)
209210
}
210211
}
211-
childBlock.isBlock = !isStableFragment
212+
// track KeepAlive child as block
213+
childBlock.isBlock =
214+
childBlock.tag === KEEP_ALIVE || !isStableFragment
212215
if (childBlock.isBlock) {
213216
helper(OPEN_BLOCK)
214217
helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent))

packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,11 +1431,14 @@ describe('renderer: optimized mode', () => {
14311431
Fragment,
14321432
null,
14331433
renderList(1, () => {
1434-
return createVNode(
1435-
KeepAlive,
1436-
null,
1437-
[(openBlock(), createBlock(view.value))],
1438-
1024 /* DYNAMIC_SLOTS */,
1434+
return (
1435+
openBlock(),
1436+
createBlock(
1437+
KeepAlive,
1438+
{ include: [] },
1439+
[(openBlock(), createBlock(view.value))],
1440+
1024 /* DYNAMIC_SLOTS */,
1441+
)
14391442
)
14401443
}),
14411444
64 /* STABLE_FRAGMENT */,

packages/runtime-core/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ function baseCreateRenderer(
21102110
}
21112111

21122112
if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
2113-
;(vnode.component!.parent!.ctx as KeepAliveContext).deactivate(vnode)
2113+
;(parentComponent!.ctx as KeepAliveContext).deactivate(vnode)
21142114
return
21152115
}
21162116

0 commit comments

Comments
 (0)