Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): normalize nested arrays in v-for(fix #8468) #8558

Merged
merged 4 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,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>')
})
})