mirror of https://github.com/vuejs/core.git
fix(runtime-core): avoid traversing static children for vnodes w/ PatchFlags.BAIL (#11115)
close #10547
This commit is contained in:
parent
04729ba216
commit
b557d3fb8a
|
@ -3,6 +3,7 @@ import {
|
||||||
NodeOpTypes,
|
NodeOpTypes,
|
||||||
type TestElement,
|
type TestElement,
|
||||||
TestNodeTypes,
|
TestNodeTypes,
|
||||||
|
type VNode,
|
||||||
createBlock,
|
createBlock,
|
||||||
createCommentVNode,
|
createCommentVNode,
|
||||||
createTextVNode,
|
createTextVNode,
|
||||||
|
@ -316,6 +317,64 @@ describe('renderer: fragment', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #10547
|
||||||
|
test('`template` fragment w/ render function', () => {
|
||||||
|
const renderFn = (vnode: VNode) => {
|
||||||
|
return (
|
||||||
|
openBlock(),
|
||||||
|
createBlock(
|
||||||
|
Fragment,
|
||||||
|
null,
|
||||||
|
[createTextVNode('text'), (openBlock(), createBlock(vnode))],
|
||||||
|
PatchFlags.STABLE_FRAGMENT,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
const foo = h('div', ['foo'])
|
||||||
|
const bar = h('div', [h('div', 'bar')])
|
||||||
|
|
||||||
|
render(renderFn(foo), root)
|
||||||
|
expect(serializeInner(root)).toBe(`text<div>foo</div>`)
|
||||||
|
|
||||||
|
render(renderFn(bar), root)
|
||||||
|
expect(serializeInner(root)).toBe(`text<div><div>bar</div></div>`)
|
||||||
|
|
||||||
|
render(renderFn(foo), root)
|
||||||
|
expect(serializeInner(root)).toBe(`text<div>foo</div>`)
|
||||||
|
})
|
||||||
|
|
||||||
|
// #10547
|
||||||
|
test('`template` fragment w/ render function + keyed vnode', () => {
|
||||||
|
const renderFn = (vnode: VNode) => {
|
||||||
|
return (
|
||||||
|
openBlock(),
|
||||||
|
createBlock(
|
||||||
|
Fragment,
|
||||||
|
null,
|
||||||
|
[createTextVNode('text'), (openBlock(), createBlock(vnode))],
|
||||||
|
PatchFlags.STABLE_FRAGMENT,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
const foo = h('div', { key: 1 }, [h('div', 'foo')])
|
||||||
|
const bar = h('div', { key: 2 }, [h('div', 'bar'), h('div', 'bar')])
|
||||||
|
|
||||||
|
render(renderFn(foo), root)
|
||||||
|
expect(serializeInner(root)).toBe(`text<div><div>foo</div></div>`)
|
||||||
|
|
||||||
|
render(renderFn(bar), root)
|
||||||
|
expect(serializeInner(root)).toBe(
|
||||||
|
`text<div><div>bar</div><div>bar</div></div>`,
|
||||||
|
)
|
||||||
|
|
||||||
|
render(renderFn(foo), root)
|
||||||
|
expect(serializeInner(root)).toBe(`text<div><div>foo</div></div>`)
|
||||||
|
})
|
||||||
|
|
||||||
// #6852
|
// #6852
|
||||||
test('`template` keyed fragment w/ text', () => {
|
test('`template` keyed fragment w/ text', () => {
|
||||||
const root = nodeOps.createElement('div')
|
const root = nodeOps.createElement('div')
|
||||||
|
|
|
@ -2473,7 +2473,8 @@ export function traverseStaticChildren(n1: VNode, n2: VNode, shallow = false) {
|
||||||
c2 = ch2[i] = cloneIfMounted(ch2[i] as VNode)
|
c2 = ch2[i] = cloneIfMounted(ch2[i] as VNode)
|
||||||
c2.el = c1.el
|
c2.el = c1.el
|
||||||
}
|
}
|
||||||
if (!shallow) traverseStaticChildren(c1, c2)
|
if (!shallow && c2.patchFlag !== PatchFlags.BAIL)
|
||||||
|
traverseStaticChildren(c1, c2)
|
||||||
}
|
}
|
||||||
// #6852 also inherit for text nodes
|
// #6852 also inherit for text nodes
|
||||||
if (c2.type === Text) {
|
if (c2.type === Text) {
|
||||||
|
|
Loading…
Reference in New Issue