@@ -19,6 +19,7 @@ let warned = Object.create(null)
19
19
const warnOnce = msg => {
20
20
if ( ! warned [ msg ] ) {
21
21
warned [ msg ] = true
22
+ // eslint-disable-next-line no-console
22
23
console . warn ( `\n\u001b[31m${ msg } \u001b[39m\n` )
23
24
}
24
25
}
@@ -49,6 +50,27 @@ const normalizeRender = vm => {
49
50
}
50
51
}
51
52
53
+ function waitForSsrPrefetch ( vm , resolve , reject ) {
54
+ let handlers = vm . $options . ssrPrefetch
55
+ if ( isDef ( handlers ) ) {
56
+ if ( ! Array . isArray ( handlers ) ) handlers = [ handlers ]
57
+ try {
58
+ const promises = [ ]
59
+ for ( let i = 0 , j = handlers . length ; i < j ; i ++ ) {
60
+ const result = handlers [ i ] . call ( vm , vm )
61
+ if ( result && typeof result . then === 'function' ) {
62
+ promises . push ( result )
63
+ }
64
+ }
65
+ Promise . all ( promises ) . then ( resolve ) . catch ( reject )
66
+ return
67
+ } catch ( e ) {
68
+ reject ( e )
69
+ }
70
+ }
71
+ resolve ( )
72
+ }
73
+
52
74
function renderNode ( node , isRoot , context ) {
53
75
if ( node . isString ) {
54
76
renderStringNode ( node , context )
@@ -166,13 +188,20 @@ function renderComponentInner (node, isRoot, context) {
166
188
context . activeInstance
167
189
)
168
190
normalizeRender ( child )
169
- const childNode = child . _render ( )
170
- childNode . parent = node
171
- context . renderStates . push ( {
172
- type : 'Component' ,
173
- prevActive
174
- } )
175
- renderNode ( childNode , isRoot , context )
191
+
192
+ const resolve = ( ) => {
193
+ const childNode = child . _render ( )
194
+ childNode . parent = node
195
+ context . renderStates . push ( {
196
+ type : 'Component' ,
197
+ prevActive
198
+ } )
199
+ renderNode ( childNode , isRoot , context )
200
+ }
201
+
202
+ const reject = context . done
203
+
204
+ waitForSsrPrefetch ( child , resolve , reject )
176
205
}
177
206
178
207
function renderAsyncComponent ( node , isRoot , context ) {
@@ -394,6 +423,10 @@ export function createRenderFunction (
394
423
} )
395
424
installSSRHelpers ( component )
396
425
normalizeRender ( component )
397
- renderNode ( component . _render ( ) , true , context )
426
+
427
+ const resolve = ( ) => {
428
+ renderNode ( component . _render ( ) , true , context )
429
+ }
430
+ waitForSsrPrefetch ( component , resolve , done )
398
431
}
399
432
}
0 commit comments