]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: fix tests
authorEvan You <yyx990803@gmail.com>
Fri, 15 May 2020 21:05:26 +0000 (17:05 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 15 May 2020 21:05:26 +0000 (17:05 -0400)
packages/runtime-core/src/hydration.ts
packages/server-renderer/__tests__/renderToString.spec.ts

index 5816b183c3dd96214c9814b3c837b308938c0d19..5d8fd41fb951f9948b63c26eefbf5754472fe33b 100644 (file)
@@ -118,16 +118,17 @@ export function createHydrationFunctions(
           return onMismatch()
         }
         // determine anchor, adopt content
-        let content = ''
         let cur = node
+        // if the static vnode has its content stripped during build,
+        // adopt it from the server-rendered HTML.
+        const needToAdoptContent = !(vnode.children as string).length
         for (let i = 0; i < vnode.staticCount; i++) {
-          content += (cur as Element).outerHTML
+          if (needToAdoptContent) vnode.children += (cur as Element).outerHTML
           if (i === vnode.staticCount - 1) {
             vnode.anchor = cur
           }
           cur = nextSibling(cur)!
         }
-        vnode.children = content
         return cur
       case Fragment:
         if (!isFragmentStart) {
index ed58e2a38df8e307d3b4fd69f0ae5efbe3e8b2cc..b034312c30b8f1162e4146b00ee7bb74cce19893 100644 (file)
@@ -536,7 +536,7 @@ describe('ssr: renderToString', () => {
 
     test('Static', async () => {
       const content = `<div id="ok">hello<span>world</span></div>`
-      expect(await renderToString(createStaticVNode(content))).toBe(content)
+      expect(await renderToString(createStaticVNode(content, 1))).toBe(content)
     })
   })