fix(runtime-core): handle fragment with null children (#10010)

close #10007
This commit is contained in:
Doctorwu 2024-01-08 18:48:47 +08:00 committed by GitHub
parent 3c3561e720
commit 3bf34b767e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -351,4 +351,16 @@ describe('renderer: fragment', () => {
render(renderFn(['two', 'one']), root) render(renderFn(['two', 'one']), root)
expect(serializeInner(root)).toBe(`text<div>two</div>text<div>one</div>`) expect(serializeInner(root)).toBe(`text<div>two</div>text<div>one</div>`)
}) })
// #10007
test('empty fragment', () => {
const root = nodeOps.createElement('div')
const renderFn = () => {
return openBlock(true), createBlock(Fragment, null)
}
render(renderFn(), root)
expect(serializeInner(root)).toBe('')
})
}) })

View File

@ -1086,7 +1086,11 @@ function baseCreateRenderer(
// since they are either generated by the compiler, or implicitly created // since they are either generated by the compiler, or implicitly created
// from arrays. // from arrays.
mountChildren( mountChildren(
n2.children as VNodeArrayChildren, // #10007
// such fragment like `<></>` will be compiled into
// a fragment which doesn't have a children.
// In this case fallback to an empty array
(n2.children || []) as VNodeArrayChildren,
container, container,
fragmentEndAnchor, fragmentEndAnchor,
parentComponent, parentComponent,