File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,28 @@ describe('SSR hydration', () => {
97
97
expect ( s . children ) . toBe ( staticContent )
98
98
} )
99
99
100
+ // #6008
101
+ test ( 'static (with text node as starting node)' , ( ) => {
102
+ const html = ` A <span>foo</span> B`
103
+ const { vnode, container } = mountWithHydration ( html , ( ) =>
104
+ createStaticVNode ( ` A <span>foo</span> B` , 3 )
105
+ )
106
+ expect ( vnode . el ) . toBe ( container . firstChild )
107
+ expect ( vnode . anchor ) . toBe ( container . lastChild )
108
+ expect ( `Hydration node mismatch` ) . not . toHaveBeenWarned ( )
109
+ } )
110
+
111
+ test ( 'static with content adoption' , ( ) => {
112
+ const html = ` A <span>foo</span> B`
113
+ const { vnode, container } = mountWithHydration ( html , ( ) =>
114
+ createStaticVNode ( `` , 3 )
115
+ )
116
+ expect ( vnode . el ) . toBe ( container . firstChild )
117
+ expect ( vnode . anchor ) . toBe ( container . lastChild )
118
+ expect ( vnode . children ) . toBe ( html )
119
+ expect ( `Hydration node mismatch` ) . not . toHaveBeenWarned ( )
120
+ } )
121
+
100
122
test ( 'element with text children' , async ( ) => {
101
123
const msg = ref ( 'foo' )
102
124
const { vnode, container } = mountWithHydration (
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ export function createHydrationFunctions(
150
150
}
151
151
break
152
152
case Static :
153
- if ( domType !== DOMNodeTypes . ELEMENT ) {
153
+ if ( domType !== DOMNodeTypes . ELEMENT && domType !== DOMNodeTypes . TEXT ) {
154
154
nextNode = onMismatch ( )
155
155
} else {
156
156
// determine anchor, adopt content
@@ -160,7 +160,10 @@ export function createHydrationFunctions(
160
160
const needToAdoptContent = ! ( vnode . children as string ) . length
161
161
for ( let i = 0 ; i < vnode . staticCount ! ; i ++ ) {
162
162
if ( needToAdoptContent )
163
- vnode . children += ( nextNode as Element ) . outerHTML
163
+ vnode . children +=
164
+ nextNode . nodeType === DOMNodeTypes . ELEMENT
165
+ ? ( nextNode as Element ) . outerHTML
166
+ : ( nextNode as Text ) . data
164
167
if ( i === vnode . staticCount ! - 1 ) {
165
168
vnode . anchor = nextNode
166
169
}
You can’t perform that action at this time.
0 commit comments