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 (
7
7
children : any ,
8
8
ns : string | void
9
9
) : 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' ) {
14
17
children = children ( )
15
18
}
19
+
16
20
if ( isPrimitive ( children ) ) {
17
21
return [ createTextVNode ( children ) ]
18
22
}
Original file line number Diff line number Diff line change @@ -36,4 +36,16 @@ describe('Options render', () => {
36
36
new Vue ( ) . $mount ( )
37
37
expect ( 'Failed to mount component: template or render function not defined.' ) . toHaveBeenWarned ( )
38
38
} )
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
+ } )
39
51
} )
You can’t perform that action at this time.
0 commit comments