Skip to content

Commit

Permalink
fix(runtime-core): handle fragment with null children (vuejs#10010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu authored Jan 8, 2024
1 parent 3c3561e commit 3bf34b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/runtime-core/__tests__/rendererFragment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,16 @@ describe('renderer: fragment', () => {
render(renderFn(['two', 'one']), root)
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('')
})
})
6 changes: 5 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,11 @@ function baseCreateRenderer(
// since they are either generated by the compiler, or implicitly created
// from arrays.
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,
fragmentEndAnchor,
parentComponent,
Expand Down

0 comments on commit 3bf34b7

Please sign in to comment.