Skip to content

Commit

Permalink
fix(compiler): normalize potential functional component children in v…
Browse files Browse the repository at this point in the history
…-for (#8558)

fix #8468
  • Loading branch information
liximomo authored and yyx990803 committed Oct 24, 2018
1 parent 59d4351 commit d483a49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ export function genChildren (
el.tag !== 'template' &&
el.tag !== 'slot'
) {
return (altGenElement || genElement)(el, state)
// because el may be a functional component and return an Array instead of a single root.
// In this case, just a simple normalization is needed
const normalizationType = state.maybeComponent(el) ? `,1` : ``
return `${(altGenElement || genElement)(el, state)}${normalizationType}`
}
const normalizationType = checkSkip
? getNormalizationType(children, state.maybeComponent)
Expand Down
21 changes: 21 additions & 0 deletions test/unit/features/options/functional.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,25 @@ describe('Options functional', () => {
triggerEvent(parent.$el.querySelector('.clickable'), 'click')
waitForUpdate(assertMarkup).then(done)
})

// #8468
it('should normalize nested arrays when use functional components with v-for', () => {
const Foo = {
functional: true,
props: {
name: {}
},
render (h, context) {
return [h('span', 'hi'), h('span', context.props.name)]
}
}
const vm = new Vue({
template: `<div><foo v-for="name in names" :name="name" /></div>`,
data: {
names: ['foo', 'bar']
},
components: { Foo }
}).$mount()
expect(vm.$el.innerHTML).toBe('<span>hi</span><span>foo</span><span>hi</span><span>bar</span>')
})
})

1 comment on commit d483a49

@Herteby
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊👍

Please sign in to comment.