@@ -76,9 +76,15 @@ export function createHydrationFunctions(
76
76
parentSuspense : SuspenseBoundary | null ,
77
77
optimized = false
78
78
) : Node | null => {
79
+ const isFragmentStart = isComment ( node ) && node . data === '1'
80
+ if ( __DEV__ && isFragmentStart ) {
81
+ // in dev mode, replace comment anchors with invisible text nodes
82
+ // for easier debugging
83
+ node = replaceAnchor ( node , parentNode ( node ) ! )
84
+ }
85
+
79
86
const { type, shapeFlag } = vnode
80
87
const domType = node . nodeType
81
-
82
88
vnode . el = node
83
89
84
90
switch ( type ) {
@@ -108,7 +114,7 @@ export function createHydrationFunctions(
108
114
}
109
115
return nextSibling ( node )
110
116
case Fragment :
111
- if ( domType !== DOMNodeTypes . COMMENT ) {
117
+ if ( domType !== ( __DEV__ ? DOMNodeTypes . TEXT : DOMNodeTypes . COMMENT ) ) {
112
118
return handleMismtach ( node , vnode , parentComponent , parentSuspense )
113
119
}
114
120
return hydrateFragment (
@@ -152,7 +158,7 @@ export function createHydrationFunctions(
152
158
} else {
153
159
// no subTree means this is an async component
154
160
// try to locate the ending node
155
- return isComment ( node ) && node . data === '1'
161
+ return isFragmentStart
156
162
? locateClosingAsyncAnchor ( node )
157
163
: nextSibling ( node )
158
164
}
@@ -319,16 +325,19 @@ export function createHydrationFunctions(
319
325
parentSuspense : SuspenseBoundary | null ,
320
326
optimized : boolean
321
327
) => {
322
- return nextSibling (
323
- ( vnode . anchor = hydrateChildren (
324
- nextSibling ( node ) ! ,
325
- vnode ,
326
- parentNode ( node ) ! ,
327
- parentComponent ,
328
- parentSuspense ,
329
- optimized
330
- ) ! )
331
- )
328
+ const container = parentNode ( node ) !
329
+ let next = hydrateChildren (
330
+ nextSibling ( node ) ! ,
331
+ vnode ,
332
+ container ,
333
+ parentComponent ,
334
+ parentSuspense ,
335
+ optimized
336
+ ) !
337
+ if ( __DEV__ ) {
338
+ next = replaceAnchor ( next , container )
339
+ }
340
+ return nextSibling ( ( vnode . anchor = next ) )
332
341
}
333
342
334
343
const hydratePortal = (
@@ -377,7 +386,6 @@ export function createHydrationFunctions(
377
386
const next = nextSibling ( node )
378
387
const container = parentNode ( node ) !
379
388
container . removeChild ( node )
380
- // TODO Suspense
381
389
patch (
382
390
null ,
383
391
vnode ,
@@ -408,5 +416,12 @@ export function createHydrationFunctions(
408
416
return node
409
417
}
410
418
419
+ const replaceAnchor = ( node : Node , parent : Element ) : Node => {
420
+ const text = document . createTextNode ( '' )
421
+ parent . insertBefore ( text , node )
422
+ parent . removeChild ( node )
423
+ return text
424
+ }
425
+
411
426
return [ hydrate , hydrateNode ] as const
412
427
}
0 commit comments