Skip to content

Commit 6ab10c0

Browse files
committed
fix v-for list auto-keying with nested <template> (fix #3913)
1 parent ea39d9f commit 6ab10c0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/compiler/optimizer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ function isStatic (node: ASTNode): boolean {
7575
!node.if && !node.for && // not v-if or v-for or v-else
7676
!isBuiltInTag(node.tag) && // not a built-in
7777
isPlatformReservedTag(node.tag) && // not a component
78+
!isDirectChildOfTemplateFor(node) &&
7879
Object.keys(node).every(isStaticKey)
7980
))
8081
}
82+
83+
function isDirectChildOfTemplateFor (node: ASTElement): boolean {
84+
while (node.parent) {
85+
node = node.parent
86+
if (node.tag !== 'template') {
87+
return false
88+
}
89+
if (node.for) {
90+
return true
91+
}
92+
}
93+
return false
94+
}

src/core/vdom/helpers/normalize-children.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import VNode from 'core/vdom/vnode'
66
export function normalizeChildren (
77
children: any,
88
ns: string | void,
9-
nestedIndex: number | void
9+
nestedIndex: string | void
1010
): Array<VNode> | void {
1111
if (isPrimitive(children)) {
1212
return [createTextVNode(children)]
@@ -18,7 +18,7 @@ export function normalizeChildren (
1818
const last = res[res.length - 1]
1919
// nested
2020
if (Array.isArray(c)) {
21-
res.push.apply(res, normalizeChildren(c, ns, i))
21+
res.push.apply(res, normalizeChildren(c, ns, `${nestedIndex || ''}_${i}`))
2222
} else if (isPrimitive(c)) {
2323
if (last && last.text) {
2424
last.text += String(c)
@@ -36,7 +36,7 @@ export function normalizeChildren (
3636
}
3737
// default key for nested array children (likely generated by v-for)
3838
if (c.tag && c.key == null && nestedIndex != null) {
39-
c.key = `__vlist_${nestedIndex}_${i}__`
39+
c.key = `__vlist${nestedIndex}_${i}__`
4040
}
4141
res.push(c)
4242
}

0 commit comments

Comments
 (0)