Skip to content

Commit

Permalink
key nested children by default (fix #3611)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 8, 2016
1 parent d2337df commit 63e4757
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/core/vdom/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import VNode from './vnode'

export function normalizeChildren (
children: any,
ns: string | void
ns: string | void,
nestedIndex: number | void
): Array<VNode> | void {
if (isPrimitive(children)) {
return [createTextVNode(children)]
Expand All @@ -17,7 +18,7 @@ export function normalizeChildren (
const last = res[res.length - 1]
// nested
if (Array.isArray(c)) {
res.push.apply(res, normalizeChildren(c, ns))
res.push.apply(res, normalizeChildren(c, ns, i))
} else if (isPrimitive(c)) {
if (last && last.text) {
last.text += String(c)
Expand All @@ -33,6 +34,10 @@ export function normalizeChildren (
if (ns) {
applyNS(c, ns)
}
// default key for nested array children (likely generated by v-for)
if (c.key == null && nestedIndex != null) {
c.key = `__vlist_${nestedIndex}_${i}__`
}
res.push(c)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/web/runtime/components/transition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
for (let i = 0; i < rawChildren.length; i++) {
const c = rawChildren[i]
if (c.tag) {
if (c.key != null) {
if (c.key != null && String(c.key).indexOf('__vlist') !== 0) {
children.push(c)
map[c.key] = c
;(c.data || (c.data = {})).transition = transitionData
Expand Down

0 comments on commit 63e4757

Please sign in to comment.