@@ -8,6 +8,7 @@ import { installRenderHelpers } from '../instance/render-helpers/index'
88
99import {
1010 isDef ,
11+ isTrue ,
1112 camelize ,
1213 emptyObject ,
1314 validateProp
@@ -28,14 +29,35 @@ function FunctionalRenderContext (
2829 this . listeners = data . on || emptyObject
2930 this . injections = resolveInject ( options . inject , parent )
3031 this . slots = ( ) => resolveSlots ( children , parent )
32+
33+ // ensure the createElement function in functional components
34+ // gets a unique context - this is necessary for correct named slot check
35+ const contextVm = Object . create ( parent )
36+ const isCompiled = isTrue ( options . _compiled )
37+ const needNormalization = ! isCompiled
38+
3139 // support for compiled functional template
32- if ( options . _compiled ) {
40+ if ( isCompiled ) {
41+ // exposing constructor and $options for renderStatic() because it needs
42+ // to cache the rendered trees on shared options
3343 this . constructor = Ctor
3444 this . $options = options
35- this . _c = parent . _c
45+ // pre-resolve slots for renderSlot()
3646 this . $slots = this . slots ( )
3747 this . $scopedSlots = data . scopedSlots || emptyObject
3848 }
49+
50+ if ( options . _scopeId ) {
51+ this . _c = ( a , b , c , d ) => {
52+ const vnode : ?VNode = createElement ( contextVm , a , b , c , d , needNormalization )
53+ if ( vnode ) {
54+ vnode . fnScopeId = options . _scopeId
55+ }
56+ return vnode
57+ }
58+ } else {
59+ this . _c = ( a , b , c , d ) => createElement ( contextVm , a , b , c , d , needNormalization )
60+ }
3961}
4062
4163installRenderHelpers ( FunctionalRenderContext . prototype )
@@ -58,25 +80,25 @@ export function createFunctionalComponent (
5880 if ( isDef ( data . attrs ) ) mergeProps ( props , data . attrs )
5981 if ( isDef ( data . props ) ) mergeProps ( props , data . props )
6082 }
61- // ensure the createElement function in functional components
62- // gets a unique context - this is necessary for correct named slot check
63- const _contextVm = Object . create ( contextVm )
64- const h = ( a , b , c , d ) => createElement ( _contextVm , a , b , c , d , true )
83+
6584 const renderContext = new FunctionalRenderContext (
6685 data ,
6786 props ,
6887 children ,
6988 contextVm ,
7089 Ctor
7190 )
72- const vnode = options . render . call ( null , h , renderContext )
91+
92+ const vnode = options . render . call ( null , renderContext . _c , renderContext )
93+
7394 if ( vnode instanceof VNode ) {
7495 vnode . functionalContext = contextVm
7596 vnode . functionalOptions = options
7697 if ( data . slot ) {
7798 ( vnode . data || ( vnode . data = { } ) ) . slot = data . slot
7899 }
79100 }
101+
80102 return vnode
81103}
82104
0 commit comments