fix(compiler): force block for custom dirs and inline beforeUpdate hooks

to ensure they are called before children updates
This commit is contained in:
Evan You
2021-12-10 15:34:23 +08:00
parent 4b5d1ac894
commit 1c9a4810fc
8 changed files with 82 additions and 21 deletions

View File

@@ -67,13 +67,13 @@ exports[`compiler: transform text element with custom directives and only one te
return function render(_ctx, _cache) {
with (_ctx) {
const { toDisplayString: _toDisplayString, createTextVNode: _createTextVNode, resolveDirective: _resolveDirective, withDirectives: _withDirectives, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue
const { toDisplayString: _toDisplayString, createTextVNode: _createTextVNode, resolveDirective: _resolveDirective, openBlock: _openBlock, createElementBlock: _createElementBlock, withDirectives: _withDirectives } = _Vue
const _directive_foo = _resolveDirective(\\"foo\\")
return _withDirectives((_openBlock(), _createElementBlock(\\"p\\", null, [
_createTextVNode(_toDisplayString(foo), 1 /* TEXT */)
], 512 /* NEED_PATCH */)), [
])), [
[_directive_foo]
])
}

View File

@@ -1202,6 +1202,23 @@ describe('compiler: element transform', () => {
})
})
test('force block for runtime custom directive w/ children', () => {
const { node } = parseWithElementTransform(`<div v-foo>hello</div>`)
expect(node.isBlock).toBe(true)
})
test('force block for inline before-update handlers w/ children', () => {
expect(
parseWithElementTransform(`<div @vnode-before-update>hello</div>`).node
.isBlock
).toBe(true)
expect(
parseWithElementTransform(`<div @vnodeBeforeUpdate>hello</div>`).node
.isBlock
).toBe(true)
})
// #938
test('element with dynamic keys should be forced into blocks', () => {
const ast = parse(`<div><div :key="foo" /></div>`)