File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
test/unit/features/options Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,16 @@ export function normalizeChildren (
77 children : any ,
88 ns : string | void
99) : Array < VNode > | void {
10- // invoke children thunks.
11- // components always receive their children as thunks so that they
12- // can perform the actual render inside their own dependency collection cycle.
13- if ( typeof children === 'function' ) {
10+ // Invoke children thunks. Components always receive their children
11+ // as thunks so that they can perform the actual render inside their
12+ // own dependency collection cycle. Also, since JSX automatically
13+ // wraps component children in a thunk, we handle nested thunks to
14+ // prevent situations such as <MyComponent>{ children }</MyComponent>
15+ // from failing when it produces a double thunk.
16+ while ( typeof children === 'function' ) {
1417 children = children ( )
1518 }
19+
1620 if ( isPrimitive ( children ) ) {
1721 return [ createTextVNode ( children ) ]
1822 }
Original file line number Diff line number Diff line change @@ -36,4 +36,16 @@ describe('Options render', () => {
3636 new Vue ( ) . $mount ( )
3737 expect ( 'Failed to mount component: template or render function not defined.' ) . toHaveBeenWarned ( )
3838 } )
39+
40+ // Since JSX automatically thunkifies children, this will
41+ // prevent <MyComponent>{ children }</MyComponent> from
42+ // failing when it produces a double thunk.
43+ it ( 'should support nested thunk children' , ( ) => {
44+ const vm = new Vue ( {
45+ render : h => h ( 'div' ,
46+ ( ) => ( ) => ( ) => [ 'hello ' , h ( 'strong' , 'world' ) ]
47+ )
48+ } ) . $mount ( )
49+ expect ( vm . $el . innerHTML ) . toBe ( 'hello <strong>world</strong>' )
50+ } )
3951} )
You can’t perform that action at this time.
0 commit comments