test(ssr): more hydration tests

This commit is contained in:
Evan You 2020-03-05 10:29:50 -06:00
parent fb4856b363
commit 08bba093af
2 changed files with 29 additions and 8 deletions

View File

@ -1,4 +1,12 @@
import { createSSRApp, h, ref, nextTick, VNode, Portal } from '@vue/runtime-dom' import {
createSSRApp,
h,
ref,
nextTick,
VNode,
Portal,
createStaticVNode
} from '@vue/runtime-dom'
function mountWithHydration(html: string, render: () => any) { function mountWithHydration(html: string, render: () => any) {
const container = document.createElement('div') const container = document.createElement('div')
@ -28,6 +36,21 @@ describe('SSR hydration', () => {
expect(container.textContent).toBe('bar') expect(container.textContent).toBe('bar')
}) })
test('comment', () => {
const { vnode, container } = mountWithHydration('<!---->', () => null)
expect(vnode.el).toBe(container.firstChild)
expect(vnode.el.nodeType).toBe(8) // comment
})
test('static', () => {
const html = '<div><span>hello</span></div>'
const { vnode, container } = mountWithHydration(html, () =>
createStaticVNode(html)
)
expect(vnode.el).toBe(container.firstChild)
expect(vnode.el.outerHTML).toBe(html)
})
test('element with text children', async () => { test('element with text children', async () => {
const msg = ref('foo') const msg = ref('foo')
const { vnode, container } = mountWithHydration( const { vnode, container } = mountWithHydration(
@ -148,10 +171,6 @@ describe('SSR hydration', () => {
) )
}) })
test('comment', () => {})
test('static', () => {})
// compile SSR + client render fn from the same template & hydrate // compile SSR + client render fn from the same template & hydrate
test('full compiler integration', () => {}) test('full compiler integration', () => {})

View File

@ -131,14 +131,16 @@ export function createHydrationFunctions({
parentComponent: ComponentInternalInstance | null, parentComponent: ComponentInternalInstance | null,
optimized: boolean optimized: boolean
) => { ) => {
optimized = optimized || vnode.dynamicChildren !== null
const { props, patchFlag, shapeFlag } = vnode const { props, patchFlag, shapeFlag } = vnode
// skip props & children if this is hoisted static nodes // skip props & children if this is hoisted static nodes
if (patchFlag !== PatchFlags.HOISTED) { if (patchFlag !== PatchFlags.HOISTED) {
// props // props
if (props !== null) { if (props !== null) {
if ( if (
patchFlag & PatchFlags.FULL_PROPS || !optimized ||
patchFlag & PatchFlags.HYDRATE_EVENTS (patchFlag & PatchFlags.FULL_PROPS ||
patchFlag & PatchFlags.HYDRATE_EVENTS)
) { ) {
for (const key in props) { for (const key in props) {
if (!isReservedProp(key) && isOn(key)) { if (!isReservedProp(key) && isOn(key)) {
@ -172,7 +174,7 @@ export function createHydrationFunctions({
vnode, vnode,
el, el,
parentComponent, parentComponent,
optimized || vnode.dynamicChildren !== null optimized
) )
while (next) { while (next) {
hasMismatch = true hasMismatch = true