@@ -6,14 +6,15 @@ import {
6
6
resolveComponentType ,
7
7
buildProps ,
8
8
ComponentNode ,
9
- PORTAL ,
10
- SUSPENSE ,
11
9
SlotFnBuilder ,
12
10
createFunctionExpression ,
13
11
createBlockStatement ,
14
12
buildSlots ,
15
13
FunctionExpression ,
16
- TemplateChildNode
14
+ TemplateChildNode ,
15
+ PORTAL ,
16
+ SUSPENSE ,
17
+ TRANSITION_GROUP
17
18
} from '@vue/compiler-dom'
18
19
import { SSR_RENDER_COMPONENT } from '../runtimeHelpers'
19
20
import {
@@ -34,6 +35,8 @@ interface WIPSlotEntry {
34
35
children : TemplateChildNode [ ]
35
36
}
36
37
38
+ const componentTypeMap = new WeakMap < ComponentNode , symbol > ( )
39
+
37
40
export const ssrTransformComponent : NodeTransform = ( node , context ) => {
38
41
if (
39
42
node . type !== NodeTypes . ELEMENT ||
@@ -43,18 +46,10 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
43
46
}
44
47
45
48
return function ssrPostTransformComponent ( ) {
46
- const component = resolveComponentType ( node , context )
47
-
49
+ const component = resolveComponentType ( node , context , true /* ssr */ )
48
50
if ( isSymbol ( component ) ) {
49
- // built-in compoonent
50
- if ( component === PORTAL ) {
51
- // TODO
52
- } else if ( component === SUSPENSE ) {
53
- // TODO fallthrough
54
- // TODO option to use fallback content and resolve on client
55
- } else {
56
- // TODO fallthrough for KeepAlive & Transition
57
- }
51
+ componentTypeMap . set ( node , component )
52
+ return // built-in component: fallthrough
58
53
}
59
54
60
55
// note we are not passing ssr: true here because for components, v-on
@@ -98,13 +93,28 @@ export function ssrProcessComponent(
98
93
node : ComponentNode ,
99
94
context : SSRTransformContext
100
95
) {
101
- // finish up slot function expressions from the 1st pass.
102
- const wipEntries = wipMap . get ( node ) || [ ]
103
- for ( let i = 0 ; i < wipEntries . length ; i ++ ) {
104
- const { fn, children } = wipEntries [ i ]
105
- const childContext = createChildContext ( context )
106
- processChildren ( children , childContext )
107
- fn . body = createBlockStatement ( childContext . body )
96
+ if ( ! node . ssrCodegenNode ) {
97
+ // this is a built-in component that fell-through.
98
+ // just render its children.
99
+ const component = componentTypeMap . get ( node ) !
100
+
101
+ if ( component === PORTAL ) {
102
+ // TODO
103
+ return
104
+ }
105
+
106
+ const needFragmentWrapper =
107
+ component === SUSPENSE || component === TRANSITION_GROUP
108
+ processChildren ( node . children , context , needFragmentWrapper )
109
+ } else {
110
+ // finish up slot function expressions from the 1st pass.
111
+ const wipEntries = wipMap . get ( node ) || [ ]
112
+ for ( let i = 0 ; i < wipEntries . length ; i ++ ) {
113
+ const { fn, children } = wipEntries [ i ]
114
+ const childContext = createChildContext ( context )
115
+ processChildren ( children , childContext )
116
+ fn . body = createBlockStatement ( childContext . body )
117
+ }
118
+ context . pushStatement ( node . ssrCodegenNode )
108
119
}
109
- context . pushStatement ( node . ssrCodegenNode ! )
110
120
}
0 commit comments