File tree 3 files changed +53
-7
lines changed
3 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -670,9 +670,13 @@ function finishComponentSetup(
670
670
671
671
// template / render function normalization
672
672
if ( __NODE_JS__ && isSSR ) {
673
- if ( Component . render ) {
674
- instance . render = Component . render as InternalRenderFunction
675
- }
673
+ // 1. the render function may already exist, returned by `setup`
674
+ // 2. otherwise try to use the `Component.render`
675
+ // 3. if the component doesn't have a render function,
676
+ // set `instance.render` to NOOP so that it can inherit the render function from mixins/extend
677
+ instance . render = ( instance . render ||
678
+ Component . render ||
679
+ NOOP ) as InternalRenderFunction
676
680
} else if ( ! instance . render ) {
677
681
// could be set from setup()
678
682
if ( compile && Component . template && ! Component . render ) {
@@ -711,7 +715,8 @@ function finishComponentSetup(
711
715
}
712
716
713
717
// warn missing template/render
714
- if ( __DEV__ && ! Component . render && instance . render === NOOP ) {
718
+ // the runtime compilation of template in SSR is done by server-render
719
+ if ( __DEV__ && ! Component . render && instance . render === NOOP && ! isSSR ) {
715
720
/* istanbul ignore if */
716
721
if ( ! compile && Component . template ) {
717
722
warn (
Original file line number Diff line number Diff line change @@ -99,6 +99,46 @@ function testRender(type: string, render: typeof renderToString) {
99
99
) . toBe ( `<div>hello</div>` )
100
100
} )
101
101
102
+ test ( 'components using defineComponent with extends option' , async ( ) => {
103
+ expect (
104
+ await render (
105
+ createApp (
106
+ defineComponent ( {
107
+ extends : {
108
+ data ( ) {
109
+ return { msg : 'hello' }
110
+ } ,
111
+ render ( this : any ) {
112
+ return h ( 'div' , this . msg )
113
+ }
114
+ }
115
+ } )
116
+ )
117
+ )
118
+ ) . toBe ( `<div>hello</div>` )
119
+ } )
120
+
121
+ test ( 'components using defineComponent with mixins option' , async ( ) => {
122
+ expect (
123
+ await render (
124
+ createApp (
125
+ defineComponent ( {
126
+ mixins : [
127
+ {
128
+ data ( ) {
129
+ return { msg : 'hello' }
130
+ } ,
131
+ render ( this : any ) {
132
+ return h ( 'div' , this . msg )
133
+ }
134
+ }
135
+ ]
136
+ } )
137
+ )
138
+ )
139
+ ) . toBe ( `<div>hello</div>` )
140
+ } )
141
+
102
142
test ( 'optimized components' , async ( ) => {
103
143
expect (
104
144
await render (
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ import {
22
22
isString ,
23
23
isVoidTag ,
24
24
ShapeFlags ,
25
- isArray
25
+ isArray ,
26
+ NOOP
26
27
} from '@vue/shared'
27
28
import { ssrRenderAttrs } from './helpers/ssrRenderAttrs'
28
29
import { ssrCompile } from './helpers/ssrCompile'
@@ -118,7 +119,7 @@ function renderComponentSubTree(
118
119
)
119
120
} else {
120
121
if (
121
- ! instance . render &&
122
+ ( ! instance . render || instance . render === NOOP ) &&
122
123
! instance . ssrRender &&
123
124
! comp . ssrRender &&
124
125
isString ( comp . template )
@@ -155,7 +156,7 @@ function renderComponentSubTree(
155
156
instance . ctx
156
157
)
157
158
setCurrentRenderingInstance ( null )
158
- } else if ( instance . render ) {
159
+ } else if ( instance . render && instance . render !== NOOP ) {
159
160
renderVNode (
160
161
push ,
161
162
( instance . subTree = renderComponentRoot ( instance ) ) ,
You can’t perform that action at this time.
0 commit comments