Skip to content
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
12 changes: 8 additions & 4 deletions src/core/vdom/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ export function normalizeChildren (
children: any,
ns: string | void
): Array<VNode> | void {
// invoke children thunks.
// components always receive their children as thunks so that they
// can perform the actual render inside their own dependency collection cycle.
if (typeof children === 'function') {
// Invoke children thunks. Components always receive their children
// as thunks so that they can perform the actual render inside their
// own dependency collection cycle. Also, since JSX automatically
// wraps component children in a thunk, we handle nested thunks to
// prevent situations such as <MyComponent>{ children }</MyComponent>
// from failing when it produces a double thunk.
while (typeof children === 'function') {
children = children()
}

if (isPrimitive(children)) {
return [createTextVNode(children)]
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/features/options/render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ describe('Options render', () => {
new Vue().$mount()
expect('Failed to mount component: template or render function not defined.').toHaveBeenWarned()
})

// Since JSX automatically thunkifies children, this will
// prevent <MyComponent>{ children }</MyComponent> from
// failing when it produces a double thunk.
it('should support nested thunk children', () => {
const vm = new Vue({
render: h => h('div',
() => () => () => ['hello ', h('strong', 'world')]
)
}).$mount()
expect(vm.$el.innerHTML).toBe('hello <strong>world</strong>')
})
})