Skip to content

Commit 3bf34b7

Browse files
authoredJan 8, 2024
fix(runtime-core): handle fragment with null children (#10010)
close #10007
1 parent 3c3561e commit 3bf34b7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎packages/runtime-core/__tests__/rendererFragment.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,16 @@ describe('renderer: fragment', () => {
351351
render(renderFn(['two', 'one']), root)
352352
expect(serializeInner(root)).toBe(`text<div>two</div>text<div>one</div>`)
353353
})
354+
355+
// #10007
356+
test('empty fragment', () => {
357+
const root = nodeOps.createElement('div')
358+
359+
const renderFn = () => {
360+
return openBlock(true), createBlock(Fragment, null)
361+
}
362+
363+
render(renderFn(), root)
364+
expect(serializeInner(root)).toBe('')
365+
})
354366
})

‎packages/runtime-core/src/renderer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,11 @@ function baseCreateRenderer(
10861086
// since they are either generated by the compiler, or implicitly created
10871087
// from arrays.
10881088
mountChildren(
1089-
n2.children as VNodeArrayChildren,
1089+
// #10007
1090+
// such fragment like `<></>` will be compiled into
1091+
// a fragment which doesn't have a children.
1092+
// In this case fallback to an empty array
1093+
(n2.children || []) as VNodeArrayChildren,
10901094
container,
10911095
fragmentEndAnchor,
10921096
parentComponent,

0 commit comments

Comments
 (0)
Please sign in to comment.