wip(ssr): adjust event hydration flag

This commit is contained in:
Evan You
2020-02-13 18:28:40 -05:00
parent 6b505dcd23
commit 9aaef60ad2
22 changed files with 190 additions and 138 deletions

View File

@@ -8,6 +8,7 @@ import {
} from '@vue/runtime-core'
import { mergeProps, normalizeVNode } from '../src/vnode'
import { Data } from '../src/component'
import { PatchFlags } from '@vue/shared'
describe('vnode', () => {
test('create with just tag', () => {
@@ -238,22 +239,32 @@ describe('vnode', () => {
const vnode = (openBlock(),
createBlock('div', null, [
hoist,
(vnode1 = createVNode('div', null, 'text', 1 /* TEXT */))
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT))
]))
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
})
test('should not track vnodes with only HYDRATE_EVENTS flag', () => {
const hoist = createVNode('div')
const vnode = (openBlock(),
createBlock('div', null, [
hoist,
createVNode('div', null, 'text', PatchFlags.HYDRATE_EVENTS)
]))
expect(vnode.dynamicChildren).toStrictEqual([])
})
test('many times call openBlock', () => {
const hoist = createVNode('div')
let vnode1, vnode2, vnode3
const vnode = (openBlock(),
createBlock('div', null, [
hoist,
(vnode1 = createVNode('div', null, 'text', 1 /* TEXT */)),
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT)),
(vnode2 = (openBlock(),
createBlock('div', null, [
hoist,
(vnode3 = createVNode('div', null, 'text', 1 /* TEXT */))
(vnode3 = createVNode('div', null, 'text', PatchFlags.TEXT))
])))
]))
expect(vnode.dynamicChildren).toStrictEqual([vnode1, vnode2])

View File

@@ -58,8 +58,11 @@ export function renderComponentRoot(
}
try {
if (vnode.shapeFlag & ShapeFlags.STATEFUL_COMPONENT) {
// withProxy is a proxy with a diffrent `has` trap only for
// runtime-compiled render functions using `with` block.
const proxyToUse = withProxy || proxy
result = normalizeVNode(
instance.render!.call(withProxy || proxy, proxy, renderCache)
instance.render!.call(proxyToUse, proxyToUse, renderCache)
)
} else {
// functional

View File

@@ -279,10 +279,9 @@ export function createVNode(
shouldTrack > 0 &&
currentBlock !== null &&
// the EVENTS flag is only for hydration and if it is the only flag, the
// vnode should not be considered dynamic.
// vnode should not be considered dynamic due to handler caching.
patchFlag !== PatchFlags.HYDRATE_EVENTS &&
(patchFlag > 0 ||
patchFlag === PatchFlags.NEED_PATCH ||
shapeFlag & ShapeFlags.SUSPENSE ||
shapeFlag & ShapeFlags.STATEFUL_COMPONENT ||
shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT)