File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,28 @@ describe('SSR hydration', () => {
9797 expect ( s . children ) . toBe ( staticContent )
9898 } )
9999
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+
100122 test ( 'element with text children' , async ( ) => {
101123 const msg = ref ( 'foo' )
102124 const { vnode, container } = mountWithHydration (
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ export function createHydrationFunctions(
150150 }
151151 break
152152 case Static :
153- if ( domType !== DOMNodeTypes . ELEMENT ) {
153+ if ( domType !== DOMNodeTypes . ELEMENT && domType !== DOMNodeTypes . TEXT ) {
154154 nextNode = onMismatch ( )
155155 } else {
156156 // determine anchor, adopt content
@@ -160,7 +160,10 @@ export function createHydrationFunctions(
160160 const needToAdoptContent = ! ( vnode . children as string ) . length
161161 for ( let i = 0 ; i < vnode . staticCount ! ; i ++ ) {
162162 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
164167 if ( i === vnode . staticCount ! - 1 ) {
165168 vnode . anchor = nextNode
166169 }
You can’t perform that action at this time.
0 commit comments