2
2
type App ,
3
3
type ComponentInternalInstance ,
4
4
type ConcreteComponent ,
5
+ type HydrationRenderer ,
5
6
MoveType ,
6
7
type Plugin ,
7
8
type RendererInternals ,
@@ -11,6 +12,7 @@ import {
11
12
type VaporInteropInterface ,
12
13
createVNode ,
13
14
currentInstance ,
15
+ ensureHydrationRenderer ,
14
16
ensureRenderer ,
15
17
onScopeDispose ,
16
18
renderSlot ,
@@ -33,11 +35,12 @@ import type { RawSlots, VaporSlot } from './componentSlots'
33
35
import { renderEffect } from './renderEffect'
34
36
import { createTextNode } from './dom/node'
35
37
import { optimizePropertyLookup } from './dom/prop'
38
+ import { hydrateNode as vaporHydrateNode } from './dom/hydration'
36
39
37
40
// mounting vapor components and slots in vdom
38
41
const vaporInteropImpl : Omit <
39
42
VaporInteropInterface ,
40
- 'vdomMount' | 'vdomUnmount' | 'vdomSlot'
43
+ 'vdomMount' | 'vdomUnmount' | 'vdomSlot' | 'vdomHydrate'
41
44
> = {
42
45
mount ( vnode , container , anchor , parentComponent ) {
43
46
const selfAnchor = ( vnode . el = vnode . anchor = createTextNode ( ) )
@@ -113,6 +116,8 @@ const vaporInteropImpl: Omit<
113
116
insert ( vnode . vb || ( vnode . component as any ) , container , anchor )
114
117
insert ( vnode . anchor as any , container , anchor )
115
118
} ,
119
+
120
+ hydrate : vaporHydrateNode ,
116
121
}
117
122
118
123
const vaporSlotPropsProxyHandler : ProxyHandler <
@@ -147,7 +152,7 @@ function createVDOMComponent(
147
152
component : ConcreteComponent ,
148
153
rawProps ?: LooseRawProps | null ,
149
154
rawSlots ?: LooseRawSlots | null ,
150
- ) : VaporFragment {
155
+ ) : [ VaporFragment , VNode ] {
151
156
const frag = new VaporFragment ( [ ] )
152
157
const vnode = createVNode (
153
158
component ,
@@ -202,7 +207,7 @@ function createVDOMComponent(
202
207
203
208
frag . remove = unmount
204
209
205
- return frag
210
+ return [ frag , vnode ]
206
211
}
207
212
208
213
/**
@@ -279,11 +284,14 @@ function renderVDOMSlot(
279
284
}
280
285
281
286
export const vaporInteropPlugin : Plugin = app => {
282
- const internals = ensureRenderer ( ) . internals
287
+ const { internals, hydrateNode } = (
288
+ app . _ssr ? ensureHydrationRenderer ( ) : ensureRenderer ( )
289
+ ) as HydrationRenderer
283
290
app . _context . vapor = extend ( vaporInteropImpl , {
284
291
vdomMount : createVDOMComponent . bind ( null , internals ) ,
285
292
vdomUnmount : internals . umt ,
286
293
vdomSlot : renderVDOMSlot . bind ( null , internals ) ,
294
+ vdomHydrate : hydrateNode ,
287
295
} )
288
296
const mount = app . mount
289
297
app . mount = ( ( ...args ) => {
0 commit comments