Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): avoid traversing static children for vnodes w/ PatchFlags.BAIL #11115

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/runtime-core/__tests__/rendererFragment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
NodeOpTypes,
type TestElement,
TestNodeTypes,
type VNode,
createBlock,
createCommentVNode,
createTextVNode,
Expand Down Expand Up @@ -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
test('`template` keyed fragment w/ text', () => {
const root = nodeOps.createElement('div')
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,8 @@ export function traverseStaticChildren(n1: VNode, n2: VNode, shallow = false) {
c2 = ch2[i] = cloneIfMounted(ch2[i] as VNode)
c2.el = c1.el
}
if (!shallow) traverseStaticChildren(c1, c2)
if (!shallow && c2.patchFlag !== PatchFlags.BAIL)
traverseStaticChildren(c1, c2)
}
// #6852 also inherit for text nodes
if (c2.type === Text) {
Expand Down