From: Evan You Date: Fri, 15 May 2020 20:11:53 +0000 (-0400) Subject: wip(runtime): test for static vnode handling X-Git-Tag: v3.0.0-beta.13~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1184118d23a93528984ebdcc9f5f6c722fb735ac;p=thirdparty%2Fvuejs%2Fcore.git wip(runtime): test for static vnode handling --- diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index a01a1c6633..cf4b21db51 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -485,26 +485,14 @@ function baseCreateRenderer( anchor: RendererNode | null, isSVG: boolean ) => { - if (n2.el && hostCloneNode !== undefined) { - // static node was already mounted (and reused), or adopted - // server-rendered node during hydration (in this case its children can be - // stripped by SSR optimizations). Clone the dom nodes instead. - let cur: RendererElement | null = n2.el - while (cur && cur !== n2.anchor) { - hostInsert(hostCloneNode(cur), container, anchor) - cur = hostNextSibling(cur) - } - hostInsert(hostCloneNode(n2.anchor!), container, anchor) - } else { - // static nodes are only present when used with compiler-dom/runtime-dom - // which guarantees presence of hostInsertStaticContent. - ;[n2.el, n2.anchor] = hostInsertStaticContent!( - n2.children as string, - container, - anchor, - isSVG - ) - } + // static nodes are only present when used with compiler-dom/runtime-dom + // which guarantees presence of hostInsertStaticContent. + ;[n2.el, n2.anchor] = hostInsertStaticContent!( + n2.children as string, + container, + anchor, + isSVG + ) } /** diff --git a/packages/runtime-dom/__tests__/rendererStaticNode.spec.ts b/packages/runtime-dom/__tests__/rendererStaticNode.spec.ts new file mode 100644 index 0000000000..c4519d81df --- /dev/null +++ b/packages/runtime-dom/__tests__/rendererStaticNode.spec.ts @@ -0,0 +1,50 @@ +import { createStaticVNode, h, render } from '../src' + +describe('static vnode handling', () => { + const content = `
hello

world

` + const content2 = `

foo

bar
baz` + + const s = createStaticVNode(content, 2) + const s2 = createStaticVNode(content2, 3) + + test('should mount from string', () => { + const root = document.createElement('div') + render(h('div', [s]), root) + expect(root.innerHTML).toBe(`
${content}
`) + }) + + test('should support reusing the same hoisted node', () => { + const root = document.createElement('div') + render(h('div', [s, s]), root) + expect(root.innerHTML).toBe(`
${content}${content}
`) + }) + + // the rest only happens during HMR but needs to be correctly supported + test('should update', () => { + const root = document.createElement('div') + render(h('div', [s]), root) + expect(root.innerHTML).toBe(`
${content}
`) + render(h('div', [s2]), root) + expect(root.innerHTML).toBe(`
${content2}
`) + }) + + test('should move', () => { + const root = document.createElement('div') + render(h('div', [h('b'), s, h('b')]), root) + expect(root.innerHTML).toBe(`
${content}
`) + render(h('div', [s, h('b'), h('b')]), root) + expect(root.innerHTML).toBe(`
${content}
`) + render(h('div', [h('b'), h('b'), s]), root) + expect(root.innerHTML).toBe(`
${content}
`) + }) + + test('should remove', () => { + const root = document.createElement('div') + render(h('div', [h('b'), s, h('b')]), root) + expect(root.innerHTML).toBe(`
${content}
`) + render(h('div', [h('b'), h('b')]), root) + expect(root.innerHTML).toBe(`
`) + render(h('div', [h('b'), h('b'), s]), root) + expect(root.innerHTML).toBe(`
${content}
`) + }) +})