Skip to content

Commit

Permalink
fix v-for list auto-keying with nested <template> (fix vuejs#3913)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 12, 2016
1 parent ea39d9f commit 6ab10c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/compiler/optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ function isStatic (node: ASTNode): boolean {
!node.if && !node.for && // not v-if or v-for or v-else
!isBuiltInTag(node.tag) && // not a built-in
isPlatformReservedTag(node.tag) && // not a component
!isDirectChildOfTemplateFor(node) &&
Object.keys(node).every(isStaticKey)
))
}

function isDirectChildOfTemplateFor (node: ASTElement): boolean {
while (node.parent) {
node = node.parent
if (node.tag !== 'template') {
return false
}
if (node.for) {
return true
}
}
return false
}
6 changes: 3 additions & 3 deletions src/core/vdom/helpers/normalize-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import VNode from 'core/vdom/vnode'
export function normalizeChildren (
children: any,
ns: string | void,
nestedIndex: number | void
nestedIndex: string | void
): Array<VNode> | void {
if (isPrimitive(children)) {
return [createTextVNode(children)]
Expand All @@ -18,7 +18,7 @@ export function normalizeChildren (
const last = res[res.length - 1]
// nested
if (Array.isArray(c)) {
res.push.apply(res, normalizeChildren(c, ns, i))
res.push.apply(res, normalizeChildren(c, ns, `${nestedIndex || ''}_${i}`))
} else if (isPrimitive(c)) {
if (last && last.text) {
last.text += String(c)
Expand All @@ -36,7 +36,7 @@ export function normalizeChildren (
}
// default key for nested array children (likely generated by v-for)
if (c.tag && c.key == null && nestedIndex != null) {
c.key = `__vlist_${nestedIndex}_${i}__`
c.key = `__vlist${nestedIndex}_${i}__`
}
res.push(c)
}
Expand Down

0 comments on commit 6ab10c0

Please sign in to comment.