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

prevent nested thunk children from failing #3367

Merged
merged 1 commit into from
Aug 1, 2016
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.
Jump to
Jump to file
Failed to load files.
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>')
})
})